Centos7 springboot jar服务开机自动启动

1、新建开机自启动service脚本(service文件名可以自定义,.service后缀不能变)

vim /usr/lib/systemd/system/cuckoo.service

[Unit]
Description=cuckoo-service
After=syslog.target network.target remote-fs.target nss-lookup.target

[Service]
Type=forking
ExecStart=/data/app/start.sh
ExecReload=/data/app/restart.sh
ExecStop=/data/app/stop.sh
PrivateTmp=true

[Install]
WantedBy=multi-user.target

2、新建启动脚本 start.sh (注意路径)

vim start.sh
#!/bin/bash
APP_NAME=cuckoo-admin.jar
nohup /data/software/jdk8/bin/java -Dspring.profiles.active=prod -jar /data/app/$APP_NAME >/data/app/admin.log 2>&1 &
echo "$APP_NAME is running"

3、新建重启动脚本 restart.sh

vim restart.sh
#!/bin/bash
APP_NAME=cuckoo-admin.jar
pid=`ps -ef | grep $APP_NAME | grep -v grep | awk '{print $2}'`
  
if [ -z "${pid}" ]; then
   echo "$APP_NAME is not running"
else
    echo "kill thread...$pid"
    kill -9 $pid
fi

nohup /data/software/jdk8/bin/java -Dspring.profiles.active=prod -jar $APP_NAME >/data/app/admin.log 2>&1 &
echo "$APP_NAME is running"

4、新建停止脚本 stop.sh

vim stop.sh
#!/bin/bash
APP_NAME=cuckoo-admin.jar
pid=`ps -ef | grep $APP_NAME | grep -v grep | awk '{print $2}'`
  
if [ -z "${pid}" ]; then
   echo "$APP_NAME is not running"
else
    echo "kill thread...$pid"
    kill -9 $pid
fi

5、增加脚本执行权限

chmod +x start.sh
chmod +x restart.sh
chmod +x stop.sh

6、设置service脚本开机自启动

systemctl status cuckoo
#开机自启动
systemctl enable cuckoo
#取消开机自启动
systemctl disable cuckoo

7、启动、重启、停止服务

systemctl start cuckoo
systemctl restart cuckoo
systemctl stop cuckoo
  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值