jar包启动脚本
vim /usr/local/bin/start.sh
#!/bin/bash
export JAVA_HOME="/usr/local/jdk"
export PATH=$JAVA_HOME/bin:$PATH
ServiceName=$1
CMD_PATH="/opt/blog"
cd $CMD_PATH/
chmod 755 ${CMD_PATH}/${ServiceName}.jar
nohup java -jar -Xms512m -Xmx1024m ${CMD_PATH}/${ServiceName}.jar &
echo $! > $CMD_PATH/${ServiceName}.pid
jar包停止脚本
vim /usr/local/bin/stop.sh
#!/bin/bash
ServiceName=$1
CMD_PATH="/opt/blog"
PID=$(cat $CMD_PATH/${ServiceName}.pid)
kill -9 $PID
cd $CMD_PATH
rm -f nohup.out
systemd管理
vim /usr/lib/systemd/system/blog-admin.service
[Unit]
Description=sms service daemon
After=syslog.target network.target
[Service]
Type=forking
Environment=JAVA_HOME="/usr/local/jdk"
ExecStart=/usr/local/bin/start.sh blog-admin
ExecStop=/usr/local/bin/stop.sh blog-admin
#ExecReload=/usr/local/bin/restart.sh "sms-service"
PrivateTmp=true
User=root
Group=root
[Install]
WantedBy=multi-user.target
重载systemd
systemctl daemon-reload
管理命令
systemctl start blog-admin.service
systemctl stop blog-admin.service
systemctl status blog-admin.service