systemctl管理服务启动、停止、开机启动
- 在/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
- 启动、重启、停止
启动redis
systemctl start testjar
重启redis
systemctl restart testjar
停止redis
systemctl stop testjar
- 开机自启动
redis服务加入开机启动
systemctl enable testjar
禁止开机启动
systemctl disable testjar
来源:https://blog.csdn.net/u010277446/article/details/102775190