使用systemctl作为服务自启动管理

现象:

使用chkconfig作为系统拉起来之后启动RP服务的方式,大概在五分钟左右就不再重复启动

排查:

查看/var/log/message文件,分析启动阶段日志(该文件内容过多,包含了所有未定义输出的内容)

也可以通过journalctl -u RP命令,摘出关于RP的日志(也是根据message中来的)

查看到:

911 10:34:48 master1 systemd[1]: Starting RP.service...
911 10:39:49 master1 systemd[1]: RP.service: start operation timed out. Terminating.
911 10:39:49 master1 systemd[1]: RP.service: Failed with result 'timeout'.
911 10:39:49 master1 systemd[1]: RP.service: Unit process 13707 (sleep) remains running after >
911 10:39:49 master1 systemd[1]: Failed to start RP.service.

该日志内容分析为:

systemd启动RP.service服务超时

解决:

使用systemctl作为服务启动管理(之前是使用chkconfig来的),并且设置重启策略。

  1. 在/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 //依赖项
  1. 使用systemctl enable RP.service命令,创建在系统启动时启动你的服务的链接(*)

  2. 使用systemctl status RP.service命令,查看服务的当前状态

  3. 使用systemctl is-enabled RP.service命令,返回enabled则标记为开机启动(*)

posted @   Dyaqi  阅读(14)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 【译】Visual Studio 中新的强大生产力特性
· 【设计模式】告别冗长if-else语句:使用策略模式优化代码结构
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
点击右上角即可分享
微信分享提示