service文件的一些参数不多讲, 此处我们只关心, 快速注册, 让jar包可以运行.

第一步:

在目录/etc/systemd/system文件夹下新建service文件, 比如redisdelkey.service.

第二步:

vim打开, 然后写点东西:

1
2
3
4
5
6
7
8
9
10
11
[Unit]
Description=admin service
[Service]
WorkingDirectory=/root/
PrivateTmp=true
Restart=always
Type=simple
ExecStart=/usr/bin/java -jar >log.out &
ExecStop=/usr/bin/kill -15 $MAINPID
[Install]
WantedBy=multi-suer.target

保存退出:wq!

第三步:

启动命令: systemctl start redisdelkey

finally:

systemctl常见命令:

systemctl is-enabled servicename.service #查询服务是否开机启动

systemctl enable *.service #开机运行服务

systemctl disable *.service #取消开机运行

systemctl start *.service #启动服务

systemctl stop *.service #停止服务

systemctl restart *.service #重启服务

systemctl reload *.service #重新加载服务配置文件

systemctl status *.service #查询服务运行状态

systemctl --failed #显示启动失败的服务