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