事象
VMのCentOS7を電源オフで落とした後、起動すると apache が起動失敗する。
[root@localhost ~]# systemctl restart httpd24-httpd
Job for httpd24-httpd.service failed. See "systemctl status httpd24-httpd.service" and "journalctl -xe" for details.
statusを確認するとhttpd (pid 1033) already running
と出力されている。
[root@localhost ~]# systemctl status httpd24-httpd.service
● httpd24-httpd.service - The Apache HTTP Server
Loaded: loaded (/usr/lib/systemd/system/httpd24-httpd.service; enabled; vendor preset: disabled)
Active: failed (Result: protocol) since 木 2021-06-24 11:25:56 JST; 21min ago
Process: 1687 ExecStart=/opt/rh/httpd24/root/usr/sbin/httpd-scl-wrapper $OPTIONS -DFOREGROUND (code=exited, status=0/SUCCESS)
Main PID: 1687 (code=exited, status=0/SUCCESS)
Status: "Reading configuration..."
6月 24 11:25:55 localhost.localdomain systemd[1]: Starting The Apache HTTP Server...
6月 24 11:25:56 localhost.localdomain httpd-scl-wrapper[1687]: AH00558: httpd: Could not reliably determine the server's...sage
6月 24 11:25:56 localhost.localdomain httpd-scl-wrapper[1687]: httpd (pid 1033) already running
6月 24 11:25:56 localhost.localdomain systemd[1]: Failed to start The Apache HTTP Server.
6月 24 11:25:56 localhost.localdomain systemd[1]: Unit httpd24-httpd.service entered failed state.
6月 24 11:25:56 localhost.localdomain systemd[1]: httpd24-httpd.service failed.
原因
前回終了時のhttpdのPIDファイルが残っている。
対応
PIDファイルを削除。
[root@localhost ~]# find / -name httpd.pid
/opt/rh/httpd24/root/var/run/httpd/httpd.pid
[root@localhost ~]# mv /opt/rh/httpd24/root/var/run/httpd/httpd.pid /opt/rh/httpd24/root/var/run/httpd/httpd.pid.bk
[root@localhost ~]# systemctl restart httpd24-httpd
[root@localhost ~]# rm /opt/rh/httpd24/root/var/run/httpd/httpd.pid.bk
参考URL
https://piyolian.blogspot.com/2012/06/apache-httpd-pid-already-running.html
https://unix.stackexchange.com/questions/548776/how-to-avoid-systemd-pid-conflict-after-crash