记一次httpd使用systemctl启动超时解决过程

现象: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;且当使用systemctl 启动或重启时,ctrl+c 中断命令,然后使用systemctl status httpd 或ps查看进程时,httpd进程正常运行。

解决方法:

1. 加长服务启动超时时间(未解决)

# vim /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

参考链接:

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

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

 参考链接:

https://www.mankier.com/8/httpd.service#Description-Automated_service_restarts

资料截图:

 

posted @ 2024-03-06 08:29  一窗明月半帘风  阅读(398)  评论(0编辑  收藏  举报