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的脚本)
添加权限