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