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