1.新建/etc/init.d/myService.sh shell文件
#!/bin/sh
# chkconfig: 2345 85 15
#description:auto_run
#程序名 RUN_NAME="bi-operation-support-web-advertisement-1.0.jar" #jar 位置 JAVA_OPTS=/etc/systemd/system/bi-operation-support-web-advertisement-1.0.jar #開始方法 start() { nohup java -jar $JAVA_OPTS & echo "$RUN_NAME started success." } #結束方法 stop() { echo "stopping $RUN_NAME ..." kill -9 `ps -ef|grep $JAVA_OPTS|grep -v grep|grep -v stop|awk '{print $2}'` } case "$1" in start) start ;; stop) stop ;; restart) stop start ;; *) echo "Userage: $0 {start|stop|restart}" exit 1 esac
2.給sh文件和jar可執行權限
chmod +x /etc/init.d/myService.sh chmod +x /etc/init.d/bi-operation-support-web-advertisement-1.0.jar
2. 添加chkconfig
chkconfig --add myService.sh (首先,添加為系統服務,注意add前面有兩個橫杠) chkconfig myService.sh on (開機自啟動) chkconfig --list (列表顯示) service myService.sh start(啟動服務,就是執行my的腳本)
添加權限