httpd使用systemctl啟動超時解決過程

一窗明月半帘风發表於2024-03-06

現象:systemctl start httpd 啟動超時,提示資訊如下:

Job for httpd.service failed because the control process exited with error code. 
See "systemctl status httpd.service" and "journalctl -xe" for details.

systemctl status httpd資訊如下:

httpd.service: start operation timed out. Terminating.
httpd.service: Failed with result 'timeout'.

相關日誌中沒有報錯;如/var/log/httpd/error_log、/var/log/message

網上搜尋到的解決方法:

1. 加長服務啟動超時時間(未解決)

新增下述檔案:

# /usr/lib/systemd/system/httpd.service.d/timeout.conf
[Service]
TimeoutStartSec=600

# systemctl daemon-reload

# sysetmctl show httpd

# journalctl -u httpd

# systemctl restart httpd

參考連結:

https://askubuntu.com/questions/1309084/how-do-i-avoid-timeouts-and-get-apache2-to-start-at-system-startup#

2.修改service啟動命令(未解決)

# /usr/lib/systemd/system/httpd.service

ExecStart=/usr/sbin/httpd $OPTIONS -DFOREGROUND 
改為
ExecStart=/bin/bash -c "/usr/sbin/httpd $OPTIONS -DFOREGROUND"

3.修改service環境變數(未解決)

# /usr/lib/systemd/system/httpd.service

Environment=LANG=C
改為
Environment=APACHE_STARTED_BY_SYSTEMD=true

4.註釋service Type(解決)

# /usr/lib/systemd/system/httpd.service

將下述內容註釋
Type=notify

# systemctl dameon-reload

原因:notify需載入mod_systemd 模組

新建檔案用以載入所需模組
# vim /etc/httpd/conf.modules.d/systemc.conf
LoadModule systemd_module modules/mod_systemd.so

將service Type註釋取消
# systemctl daemon
-reload
# systemctl restart httpd

相關文章