使用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则标记为开机启动(*)
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 【译】Visual Studio 中新的强大生产力特性
· 【设计模式】告别冗长if-else语句:使用策略模式优化代码结构
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义