大网数据广告活动
服务器运维问答

How to use automatic Restart with Jenkins on Systemd

· 52CE 我爱测

I have Jenkins running on a CentOS7 and it kind of crashes from time to time and I'd like to restart it automatically when this happens. Googleing a bit I've found that on Systemd you can use Restart=on-failure but the problem is…

问题原文

原帖链接 · daniels · CC BY-SA 3.0

I have Jenkins running on a CentOS7 and it kind of crashes from time to time and I'd like to restart it automatically when this happens. Googleing a bit I've found that on Systemd you can use Restart=on-failure but the problem is that from what I see Jenkins does not use a service file.

If I do systemctl status jenkins.service I get:

● jenkins.service - LSB: Jenkins Continuous Integration Server
   Loaded: loaded (/etc/rc.d/init.d/jenkins)
   Active: active (running) since Mon 2016-02-29 17:30:08 UTC; 11min ago

So looks like it's still using init.d? Any idea how I can use this Restart=on-failure in this case?

已采纳解答

原帖链接 · thrig · CC BY-SA 3.0

As a total horrible kluge you could point systemd at the jenkins init script, as that script has a whole bunch of annoying "where's Java" and other code to figure out how to get jenkins up and running.

# cat /etc/systemd/system/jenkins.service
[Unit]
Description=Jenkins Server Daemon
Wants=network-online.target
After=network-online.target

[Service]
ExecStart=/etc/init.d/jenkins start
Restart=always
RestartSec=3
Type=forking

[Install]
WantedBy=multi-user.target
# systemctl enable jenkins.service

and then the service starts at reboot, is not listed by chkconfig --list, and restarts even if you kill -9 $thepid though ideally long-term a better option would be for the jenkins folk to include direct support for systemd in their RPM...

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2016-02-29)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。