Linux:systemd配置jar启动服务

/lib/systemd/system目录下创建一个脚本文件testjar.service

vim /lib/systemd/system/testjar.service

#表示基础信息
[Unit]
#描述
Description=testjar Service
#在哪个服务之后启动
After=syslog.target network.target remote-fs.target nss-lookup.target

#表示服务信息
[Service]
PIDFile=/var/run/testjar.pid
User=workspace
Group=workspace
WorkingDirectory=/home/workspace/testjar
ExecStart=/usr/local/java/jdk1.8.0_221/bin/java -jar /home/workspace/testjar/testjar.jar
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true

#安装相关信息
[Install]
WantedBy=multi-user.target

创建软链接

软链接是为系统初始化时自动启动服务

ln -s /lib/systemd/system/testjar.service /etc/systemd/system/multi-user.target.wants/testjar.service

刷新配置

systemctl daemon-reload

启动、重启、停止

启动

systemctl start testjar

重启redis

systemctl restart testjar

停止

systemctl stop testjar

开机自启动
服务加入开机启动

systemctl enable testjar

禁止开机启动

systemctl disable testjar
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章