CenterOS7下springboot專案jar包自起配置
阿新 • • 發佈:2018-12-14
我本地有一個 data-service.jar
1. 編寫啟動指令碼 data-service-start
[[email protected] shell]# more data-service-start #!/bin/sh export JAVA_HOME=/usr/local/jdk1.8.0_131 export PATH=$JAVA_HOME/bin:$PATH java -jar /data/imgcloud/data-service.jar > /data/logs/data-service.log & echo $! > /var/run/data-service.pid
然後賦許可權 chmod 777 data-service-start
- 編寫停止指令碼
[[email protected] shell]# more data-service-stop
#!/bin/sh
PID=$(cat /var/run/data-service.pid)
kill -9 $PID
然後賦許可權 chmod 777 data-service-stop
- 在/usr/lib/systemd/system 下 編寫 data-service.service 指令碼
[[email protected] shell]# cd /usr/lib/systemd/system [
[email protected] system]# more data-service.service [Unit] Description=data-service for mongodb After=syslog.target network.target remote-fs.target nss-lookup.target [Service] Type=forking ExecStart=/data/shell/data-service-start ExecStop=/data/shell/data-service-stop PrivateTmp=true [Install] WantedBy=multi-user.target
- 相關命令
systemctl enable data-service 開機自啟動
systemctl stop data-service 停止
system start data-service 啟動