说明
之前一般我都是使用Tmux来启动Jenkins,自启啥的也比较麻烦,还是直接用systemd的方式来启动比较正规
开始
根目录位于/yunlingfly/jenkins/
首先编写service文件
>vim /usr/lib/systemd/system/jenkins.service
[Unit]
Description=jenkins project
After=network.target
[Service]
Type=simple
ExecStart=/yunlingfly/jenkins/startup.sh
ExecReload=
ExecStop=/yunlingfly/jenkins/shutdown.sh
PrivateTmp=true
重新加载
>systemctl daemon-reload
编写启动和关闭脚本
>vim startup.sh
#!/bin/sh
java -jar /yunlingfly/jenkins/jenkins.war --httpPort=38080
>chmod +777 startup.sh
>vim shutdown.sh
#/bin/sh
# 使用fuser关闭占用端口的程序
fuser -k 38080/tcp
>chmod +777 shutdown.sh
然后就可以快乐的使用
# 启动
systemctl start jenkins
# 关闭
systemctl stop jenkins
# 查看状态
systemctl status jenkins
# 自启
systemctl enable jenkins
# 关闭自启
systemctl disable jenkins