fa34f0
fa34f0
fa34f0
  "http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd" [
fa34f0
fa34f0
]>
fa34f0
fa34f0
 Copyright 2018 Red Hat, Inc.
fa34f0
fa34f0
 Licensed to the Apache Software Foundation (ASF) under one or more
fa34f0
 contributor license agreements.  See the NOTICE file distributed with
fa34f0
 this work for additional information regarding copyright ownership.
fa34f0
 The ASF licenses this file to You under the Apache License, Version 2.0
fa34f0
 (the "License"); you may not use this file except in compliance with
fa34f0
 the License.  You may obtain a copy of the License at
fa34f0
fa34f0
     http://www.apache.org/licenses/LICENSE-2.0
fa34f0
fa34f0
 Unless required by applicable law or agreed to in writing, software
fa34f0
 distributed under the License is distributed on an "AS IS" BASIS,
fa34f0
 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
fa34f0
 See the License for the specific language governing permissions and
fa34f0
 limitations under the License.
fa34f0
-->
fa34f0
fa34f0
<refentry>
fa34f0
  <refentryinfo>
fa34f0
    <title>httpd systemd units</title>
fa34f0
    <productname>httpd</productname>
fa34f0
    <author><contrib>Author</contrib><surname>Orton</surname><firstname>Joe</firstname><email>jorton@redhat.com</email></author>
fa34f0
  </refentryinfo>
fa34f0
fa34f0
  <refmeta>
fa34f0
    <refentrytitle>httpd.service</refentrytitle>
fa34f0
    <manvolnum>8</manvolnum>
fa34f0
  </refmeta>
fa34f0
  
fa34f0
  <refnamediv>
fa34f0
    <refname>httpd.service</refname>
fa34f0
    <refname>httpd@.service</refname>
fa34f0
    <refname>httpd.socket</refname>
fa34f0
    <refname>httpd-init.service</refname>
fa34f0
    <refpurpose>httpd unit files for systemd</refpurpose>
fa34f0
  </refnamediv>
fa34f0
fa34f0
  <refsynopsisdiv>
fa34f0
    <para>
fa34f0
      <filename>/usr/lib/systemd/system/httpd.service</filename>, 
fa34f0
      <filename>/usr/lib/systemd/system/httpd@.service</filename>,
fa34f0
      <filename>/usr/lib/systemd/system/httpd-init.service</filename>,
fa34f0
      <filename>/usr/lib/systemd/system/httpd.socket</filename>
fa34f0
    </para>
fa34f0
  </refsynopsisdiv>
fa34f0
  
fa34f0
  <refsect1>
fa34f0
    <title>Description</title>
fa34f0
fa34f0
    <para>This manual page describes the <command>systemd</command>
fa34f0
    unit files used to integrate the <command>httpd</command> daemon
fa34f0
    with <command>systemd</command>. Two main unit files are
fa34f0
    available: <command>httpd.service</command> allows the
fa34f0
    <command>httpd</command> daemon to be run as a system service, and
fa34f0
    <command>httpd.socket</command> allows httpd to be started via
fa34f0
    socket-based activation. Most systems will use
fa34f0
    <command>httpd.service</command>.</para>
fa34f0
fa34f0
    <para>The <command>apachectl</command> command has been modified
fa34f0
    to invoke <command>systemctl</command> for most uses, so for
fa34f0
    example, running <command>apachectl start</command> is equivalent
fa34f0
    to running <command>systemctl start httpd.service</command>.  This
fa34f0
    ensures that the running httpd daemon is tracked and managed by
fa34f0
    <command>systemd</command>.  In contrast, running
fa34f0
    <command>httpd</command> directly from a root shell will start the
fa34f0
    service outside of <command>systemd</command>; in this case,
fa34f0
    default security restrictions described below (including, but not
fa34f0
    limited to, SELinux) will not be enforced.</para>
fa34f0
fa34f0
    <refsect2>
fa34f0
      <title>Changing default behaviour</title>
fa34f0
fa34f0
      <para>To change the default behaviour of the httpd service, an
fa34f0
      <emphasis>over-ride</emphasis> file should be created, rather
fa34f0
      than changing
fa34f0
      <filename>/usr/lib/systemd/system/httpd.service</filename>
fa34f0
      directly, since such changes would be lost over package
fa34f0
      upgrades. Running <command>systemctl edit
fa34f0
      httpd.service</command> or <command>systemctl edit
fa34f0
      httpd.socket</command> as root will create a drop-in file (in
fa34f0
      the former case, in
fa34f0
      <filename>/etc/systemd/system/httpd.service.d</filename>) which
fa34f0
      over-rides the system defaults.</para>
fa34f0
fa34f0
      <para>For example, to set the <option>LD_LIBRARY_PATH</option>
fa34f0
      environment variable for the daemon, run <command>systemctl edit
fa34f0
      httpd.service</command> and enter:
fa34f0
fa34f0
      <programlisting>[Service]
fa34f0
Environment=LD_LIBRARY_PATH=/opt/vendor/lib</programlisting></para>
fa34f0
    </refsect2>
fa34f0
    
fa34f0
    <refsect2>
fa34f0
      <title>Starting the service at boot time</title>
fa34f0
fa34f0
      <para>The httpd.service and httpd.socket units are
fa34f0
      <emphasis>disabled</emphasis> by default. To start the httpd
fa34f0
      service at boot time, run: <command>systemctl enable
fa34f0
      httpd.service</command>. In the default configuration, the
fa34f0
      httpd daemon will accept connections on port 80 (and, if mod_ssl
fa34f0
      is installed, TLS connections on port 443) for any configured
fa34f0
      IPv4 or IPv6 address.</para>
fa34f0
fa34f0
      <para>If httpd is configured to depend on any specific IP
fa34f0
      address (for example, with a "Listen" directive) which may only
fa34f0
      become available during start-up, or if httpd depends on other
fa34f0
      services (such as a database daemon), the service
fa34f0
      <emphasis>must</emphasis> be configured to ensure correct
fa34f0
      start-up ordering.</para>
fa34f0
fa34f0
      <para>For example, to ensure httpd is only running after all
fa34f0
      configured network interfaces are configured, create a drop-in
fa34f0
      file (as described above) with the following section:
fa34f0
fa34f0
      <programlisting>[Unit]
fa34f0
After=network-online.target
fa34f0
Wants=network-online.target</programlisting>
fa34f0
fa34f0
      See 
fa34f0
      url="https://www.freedesktop.org/wiki/Software/systemd/NetworkTarget/"/>
fa34f0
      for more information on start-up ordering with systemd.</para>
fa34f0
fa34f0
    </refsect2>
fa34f0
fa34f0
    <refsect2>
fa34f0
      <title>SSL/TLS certificate generation</title>
fa34f0
fa34f0
      <para>The <command>httpd-init.service</command> unit is provided
fa34f0
      with the mod_ssl package. This oneshot unit automatically
fa34f0
      creates a TLS server certificate and key (using a generated
fa34f0
      self-signed CA certificate and key) for testing purposes before
fa34f0
      httpd is started. To inhibit certificate generation, use
fa34f0
      <command>systemctl mask httpd-init.service</command> after
fa34f0
      installing mod_ssl, and adjust the mod_ssl configuration to use
fa34f0
      an appropriate certificate and key.</para>
fa34f0
fa34f0
    </refsect2>
fa34f0
fa34f0
    <refsect2>
fa34f0
      <title>Reloading and stopping the service</title>
fa34f0
fa34f0
      <para>When running <command>systemctl reload
fa34f0
      httpd.service</command>, a <emphasis>graceful</emphasis>
fa34f0
      restart is used, which sends a signal to the httpd parent
fa34f0
      process to reload the configuration and re-open log files. Any
fa34f0
      children with open connections at the time of reload will
fa34f0
      terminate only once they have completed serving requests. This
fa34f0
      prevents users of the server seeing errors (or potentially
fa34f0
      losing data) due to the reload, but means some there is some
fa34f0
      delay before any configuration changes take effect for all
fa34f0
      users.</para>
fa34f0
fa34f0
      <para>Similarly, a <emphasis>graceful stop</emphasis> is used
fa34f0
      when <command>systemctl stop httpd.service</command> is run,
fa34f0
      which terminates the server only once active connections have
fa34f0
      been processed.</para>
fa34f0
fa34f0
      <para>To "ungracefully" stop the server without waiting for
fa34f0
      requests to complete, use <command>systemctl kill
fa34f0
      --kill-who=main httpd</command>; similarly to "ungracefully"
fa34f0
      reload the configuration, use <command>systemctl kill
fa34f0
      --kill-who=main --signal=HUP httpd</command>.</para>
fa34f0
    </refsect2>
fa34f0
fa34f0
    <refsect2>
fa34f0
      <title>Automated service restarts</title>
fa34f0
fa34f0
      <para>System packages (including the httpd package itself) may
fa34f0
      restart the httpd service automatically after packages are
fa34f0
      upgraded, installed, or removed. This is done using the
fa34f0
      <command>systemctl reload httpd.service</command>, which
fa34f0
      produces a <emphasis>graceful</emphasis> restart by default as
fa34f0
      described above.</para>
fa34f0
fa34f0
      <para>To suppress automatic reloads entirely, create the file
fa34f0
      <filename>/etc/sysconfig/httpd-disable-posttrans</filename>.</para>
fa34f0
    </refsect2>
fa34f0
fa34f0
    <refsect2>
fa34f0
      <title>Changing the default MPM (Multi-Processing Module)</title>
fa34f0
fa34f0
      <para>httpd offers a choice of multi-processing modules (MPMs),
fa34f0
      which can be configured in
fa34f0
      <filename>/etc/httpd/conf.modules.d/00-mpm.conf</filename>.
fa34f0
      See
fa34f0
      <citerefentry><refentrytitle>httpd.conf</refentrytitle><manvolnum>5</manvolnum></citerefentry>
fa34f0
      for more information on changing the MPM.</para>
fa34f0
    </refsect2>
fa34f0
fa34f0
    <refsect2>
fa34f0
      <title>systemd integration and mod_systemd</title>
fa34f0
fa34f0
      <para>The httpd service uses the <option>notify</option> systemd
fa34f0
      service type. The <literal>mod_systemd</literal> module must be
fa34f0
      loaded (as in the default configuration) for this to work
fa34f0
      correctly - the service will fail if this module is not
fa34f0
      loaded. <literal>mod_systemd</literal> also makes worker and
fa34f0
      request statistics available when running <command>systemctl status
fa34f0
      httpd</command>. See
fa34f0
      <citerefentry><refentrytitle>systemd.exec</refentrytitle><manvolnum>5</manvolnum></citerefentry>
fa34f0
      for more information on systemd service types.</para>
fa34f0
    </refsect2>
fa34f0
    
fa34f0
    <refsect2>
fa34f0
      <title>Security and SELinux</title>
fa34f0
fa34f0
      <para>The default SELinux policy restricts the httpd service in
fa34f0
      various ways. For example, the default policy limits the ports
fa34f0
      to which httpd can bind (using the <literal>Listen</literal>
fa34f0
      directive), which parts of the filesystem can be accessed, and
fa34f0
      whether outgoing TCP connections are possible. Many of these
fa34f0
      restrictions can be relaxed or adjusted by using
fa34f0
      <command>semanage</command> to change booleans or other
fa34f0
      types. See
fa34f0
      <citerefentry><refentrytitle>httpd_selinux</refentrytitle><manvolnum>8</manvolnum></citerefentry>
fa34f0
      for more information.</para>
fa34f0
fa34f0
      <para>The httpd service enables <emphasis>PrivateTmp</emphasis>
fa34f0
      by default. The <filename>/tmp</filename> and
fa34f0
      <filename>/var/tmp</filename> directories available within the
fa34f0
      httpd process (and CGI scripts, etc) are not shared by other
fa34f0
      processes. See
fa34f0
      <citerefentry><refentrytitle>systemd.exec</refentrytitle><manvolnum>5</manvolnum></citerefentry>
fa34f0
      for more information.</para>
fa34f0
fa34f0
    </refsect2>
fa34f0
fa34f0
    <refsect2>
fa34f0
      <title>Socket activation</title>
fa34f0
fa34f0
      <para>Socket activation (see
fa34f0
      <citerefentry><refentrytitle>systemd.socket</refentrytitle><manvolnum>5</manvolnum></citerefentry>
fa34f0
      for more information) can be used with <command>httpd</command>
fa34f0
      by enabling the <command>httpd.socket</command> unit.  The
fa34f0
      <command>httpd</command> listener configuration must exactly
fa34f0
      match the <literal>ListenStream</literal> options configured for
fa34f0
      the <command>httpd.socket</command> unit.  The default
fa34f0
      <command>httpd.socket</command> has a
fa34f0
      <literal>ListenStream=80</literal> and, if mod_ssl is installed,
fa34f0
      <literal>ListenStream=443</literal> by a drop-in file. If
fa34f0
      additional <literal>Listen</literal> directives are added to the
fa34f0
      httpd configuration, corresponding
fa34f0
      <literal>ListenStream</literal> options should be added via
fa34f0
      drop-in files, for example via <command>systemctl edit
fa34f0
      httpd.socket</command>.</para>
fa34f0
fa34f0
      <para>If using socket activation with httpd, only one listener
fa34f0
      on any given TCP port is supported; a configuration with both
fa34f0
      "<literal>Listen 127.0.0.1:80</literal>" and "<literal>Listen
fa34f0
      192.168.1.2:80</literal>" will not work.</para>
fa34f0
    </refsect2>
fa34f0
fa34f0
    <refsect2>
fa34f0
      <title>Instantiated services</title>
fa34f0
fa34f0
      <para>The <command>httpd@.service</command> unit is an
fa34f0
      instantiated template service. An instance of this unit will be
fa34f0
      started using the configuration file
fa34f0
      <filename>/etc/httpd/conf/INSTANCE.conf</filename>, where
fa34f0
      <emphasis>INSTANCE</emphasis> is replaced with the instance
fa34f0
      name.  For example, <command>systemctl start
fa34f0
      httpd@foobar.service</command> will start httpd using the
fa34f0
      configuration file
fa34f0
      <filename>/etc/httpd/conf/foobar.conf</filename>.  The
fa34f0
      <option>HTTPD_INSTANCE</option> environment variable is set to
fa34f0
      the instance name by the unit and is available for use within
fa34f0
      the configuration file.</para>
fa34f0
fa34f0
      <para>To allow multiple instances of httpd to run
fa34f0
      simultaneously, a number of configuration directives must be
fa34f0
      changed, such as <command>PidFile</command> and
fa34f0
      <command>DefaultRuntimeDir</command> to pick non-conflicting
fa34f0
      paths, and <command>Listen</command> to choose different ports.
fa34f0
      The example configuration file
fa34f0
      <filename>/usr/share/doc/httpd/instance.conf</filename>
fa34f0
      demonstrates how to make such changes using
fa34f0
      <option>HTTPD_INSTANCE</option> variable.</para>
fa34f0
fa34f0
      <para>It can be useful to configure instances of
fa34f0
      <command>httpd@.service</command> to reload when
fa34f0
      <command>httpd.service</command> is reloaded; for example,
fa34f0
      <command>logrotate</command> will reload only
fa34f0
      <command>httpd.service</command> when logs are rotated. If this
fa34f0
      behaviour is required, create a drop-in file for the instance as
fa34f0
      follows:
fa34f0
fa34f0
      <programlisting>[Unit]
fa34f0
ReloadPropagatedFrom=httpd.service</programlisting>
fa34f0
fa34f0
      As with normal units, drop-in files for instances can be created
fa34f0
      using <command>systemctl edit</command>, e.g. <command>systemctl edit
fa34f0
      httpd@foobar.service</command>.</para>
fa34f0
    </refsect2>
fa34f0
fa34f0
  </refsect1>
fa34f0
fa34f0
  <refsect1>
fa34f0
    <title>Files</title>
fa34f0
fa34f0
    <para><filename>/usr/lib/systemd/system/httpd.service</filename>,
fa34f0
    <filename>/usr/lib/systemd/system/httpd.socket</filename>,
fa34f0
    <filename>/usr/lib/systemd/system/httpd@.service</filename>,
fa34f0
    <filename>/etc/systemd/systemd/httpd.service.d</filename></para>
fa34f0
  </refsect1>
fa34f0
  
fa34f0
  <refsect1>
fa34f0
    <title>See also</title>
fa34f0
fa34f0
    <para>
fa34f0
    <citerefentry><refentrytitle>httpd</refentrytitle><manvolnum>8</manvolnum></citerefentry>, 
fa34f0
    <citerefentry><refentrytitle>httpd.conf</refentrytitle><manvolnum>5</manvolnum></citerefentry>,
fa34f0
    <citerefentry><refentrytitle>systemd</refentrytitle><manvolnum>1</manvolnum></citerefentry>, 
fa34f0
    <citerefentry><refentrytitle>systemctl</refentrytitle><manvolnum>1</manvolnum></citerefentry>, 
fa34f0
    <citerefentry><refentrytitle>systemd.service</refentrytitle><manvolnum>5</manvolnum></citerefentry>,
fa34f0
    <citerefentry><refentrytitle>systemd.exec</refentrytitle><manvolnum>5</manvolnum></citerefentry>,
fa34f0
    <citerefentry><refentrytitle>systemd.socket</refentrytitle><manvolnum>5</manvolnum></citerefentry>,
fa34f0
    <citerefentry><refentrytitle>httpd_selinux</refentrytitle><manvolnum>8</manvolnum></citerefentry>,
fa34f0
    <citerefentry><refentrytitle>semanage</refentrytitle><manvolnum>8</manvolnum></citerefentry>
fa34f0
    </para>
fa34f0
  </refsect1>
fa34f0
fa34f0
</refentry>
fa34f0
fa34f0
fa34f0
-->