I will show you how to start * Apache * with * httpd.conf * in * systemd * of * CentOS7 * or * CentOS8 *.
It is assumed that the configuration file myhttpd.conf
that you want to use when starting * Apache * exists under the / etc / httpd / conf
directory.
Modify the * Apache * * systemd * unit definition file /usr/lib/systemd/system/httpd.service
.
The httpd.service
before modification is as follows.
/usr/lib/systemd/system/httpd.service (before modification)
[Unit]
Description=The Apache HTTP Server
After=network.target remote-fs.target nss-lookup.target
Documentation=man:httpd(8)
Documentation=man:apachectl(8)
[Service]
Type=notify
EnvironmentFile=/etc/sysconfig/httpd
ExecStart=/usr/sbin/httpd $OPTIONS -DFOREGROUND
ExecReload=/usr/sbin/httpd $OPTIONS -k graceful
ExecStop=/bin/kill -WINCH ${MAINPID}
# We want systemd to give httpd some time to finish gracefully, but still want
# it to kill httpd after TimeoutStopSec if something went wrong during the
# graceful stop. Normally, Systemd sends SIGTERM signal right after the
# ExecStop, which would kill httpd. We are sending useless SIGCONT here to give
# httpd time to finish.
KillSignal=SIGCONT
PrivateTmp=true
[Install]
WantedBy=multi-user.target
/usr/lib/systemd/system/httpd.service (after modification)
[Unit]
Description=The Apache HTTP Server
After=network.target remote-fs.target nss-lookup.target
Documentation=man:httpd(8)
Documentation=man:apachectl(8)
[Service]
Type=notify
EnvironmentFile=/etc/sysconfig/httpd
ExecStart=/usr/sbin/httpd -f /etc/httpd/conf/myhttpd.conf $OPTIONS -DFOREGROUND
ExecReload=/usr/sbin/httpd -f /etc/httpd/conf/myhttpd.conf $OPTIONS -k graceful
ExecStop=/bin/kill -WINCH ${MAINPID}
# We want systemd to give httpd some time to finish gracefully, but still want
# it to kill httpd after TimeoutStopSec if something went wrong during the
# graceful stop. Normally, Systemd sends SIGTERM signal right after the
# ExecStop, which would kill httpd. We are sending useless SIGCONT here to give
# httpd time to finish.
KillSignal=SIGCONT
PrivateTmp=true
[Install]
WantedBy=multi-user.target
/usr/lib/systemd/system/httpd.service (difference)
-ExecStart=/usr/sbin/httpd $OPTIONS -DFOREGROUND
-ExecReload=/usr/sbin/httpd $OPTIONS -k graceful
+ExecStart=/usr/sbin/httpd -f /etc/httpd/conf/myhttpd.conf $OPTIONS -DFOREGROUND
+ExecReload=/usr/sbin/httpd -f /etc/httpd/conf/myhttpd.conf $OPTIONS -k graceful
Start * Apache * with the unit definition file (httpd.service
) modified by the following command.
systemctl start httpd
Execution result
[root@CENTOS7 ~]# systemctl start httpd
[root@CENTOS7 ~]#
Check the * Apache (httpd) * process with the following command and make sure it is started in /etc/httpd/conf/myhttpd.conf
.
ps -ef | grep httpd
Execution result
[root@CENTOS7 ~]# ps -ef | grep httpd
root 1332 1 0 22:20 ? 00:00:00 /usr/sbin/httpd -f /etc/httpd/conf/myhttpd.conf -DFOREGROUND
apache 1333 1332 0 22:20 ? 00:00:00 /usr/sbin/httpd -f /etc/httpd/conf/myhttpd.conf -DFOREGROUND
apache 1334 1332 0 22:20 ? 00:00:00 /usr/sbin/httpd -f /etc/httpd/conf/myhttpd.conf -DFOREGROUND
apache 1335 1332 0 22:20 ? 00:00:00 /usr/sbin/httpd -f /etc/httpd/conf/myhttpd.conf -DFOREGROUND
apache 1336 1332 0 22:20 ? 00:00:00 /usr/sbin/httpd -f /etc/httpd/conf/myhttpd.conf -DFOREGROUND
apache 1337 1332 0 22:20 ? 00:00:00 /usr/sbin/httpd -f /etc/httpd/conf/myhttpd.conf -DFOREGROUND
root 1341 1295 0 22:21 pts/0 00:00:00 grep --color=auto httpd
[root@CENTOS7 ~]#
This time, I added -f /etc/httpd/conf/myhttpd.conf
directly to ʻExecStart and ʻExecReload
of /usr/lib/systemd/system/httpd.service
, but make it a variable. You can also.
Refer to the following for how to use variables in the unit definition file.
How to use variables in systemd Unit definition file
that's all
Recommended Posts