Blame SOURCES/httpd.service.xml

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