使用systemctl作为服务自启动管理
现象:
使用chkconfig作为系统拉起来之后启动RP服务的方式,大概在五分钟左右就不再重复启动
排查:
查看/var/log/message文件,分析启动阶段日志(该文件内容过多,包含了所有未定义输出的内容)
也可以通过journalctl -u RP命令,摘出关于RP的日志(也是根据message中来的)
查看到:
9月 11 10:34:48 master1 systemd[1]: Starting RP.service...
9月 11 10:39:49 master1 systemd[1]: RP.service: start operation timed out. Terminating.
9月 11 10:39:49 master1 systemd[1]: RP.service: Failed with result 'timeout'.
9月 11 10:39:49 master1 systemd[1]: RP.service: Unit process 13707 (sleep) remains running after >
9月 11 10:39:49 master1 systemd[1]: Failed to start RP.service.
该日志内容分析为:
systemd启动RP.service服务超时
解决:
使用systemctl作为服务启动管理(之前是使用chkconfig来的),并且设置重启策略。
- 在/etc/systemd/system创建RP.service文件。内容为
[Service]
TimeoutStartSec=30 //单次启动超过30秒,标记为失败
Restart=on-failure //异常失败后(返回值不为0)重启(kill -15算正常退出)
ExecStart=/etc/rc.d/init.d/RP //服务调用脚本
[Install]
WantedBy=multi-user.target //依赖项
-
使用systemctl enable RP.service命令,创建在系统启动时启动你的服务的链接(*)
-
使用systemctl status RP.service命令,查看服务的当前状态
-
使用systemctl is-enabled RP.service命令,返回enabled则标记为开机启动(*)

浙公网安备 33010602011771号