一.脚本做成服务
1.把启动脚本复制到 /etc/init.d目录中
2.脚本内容 xxxx代表jar包名称
#!/usr/bin/env bash
# chkconfig: 2345 20 80
#description: start and stop server
PRO_HOME=/usr/test/demo
JAVA_HOME=/usr/java/jdk1.8.0_92
SVR_NAME=test
case $1 in
start)
echo "starting $PRO_HOME/$SVR_NAME ..."
$JAVA_HOME/bin/java -Dfile.encoding=UTF-8 -jar $PRO_HOME/$SVR_NAME/xxxx.$SVR_NAME*.jar --spring.config.location=$PRO_HOME/$SVR_NAME/application.yml > $PRO_HOME/$SVR_NAME/logs.out&
;;
stop)
echo "stopping $PRO_HOME/$SVR_NAME ..."
ps -ef|grep xxxx.$SVR_NAME* |grep -v grep |awk '{print $2}' | sed -e "s/^/kill -9 /g" | sh -
;;
restart)
"$0" stop
sleep 3
"$0" start
;;
status)
ps -ef|grep xxxx.$SVR_NAME*
;;
logs)
tail -f $PRO_HOME/$SVR_NAME/logs.out
;;
*)
echo "Example: server-$SVR_NAME [start|stop|restart|status|logs]" ;;
esac
3.添加服务
[root@root init.d]# chkconfig --add test
4.查看所有服务列表
[root@root localhost]# chkconfig
二.xxxx.jar包做成启动命令
#!/usr/bin/env bash
case $1 in
start)
java -Dfile.encoding=UTF-8 -jar xxxx.jar --spring.config.location=application.yml > logs.out &
;;
stop)
ps -ef|grep xxxx* |grep -v grep |awk '{print $2}' | sed -e "s/^/kill -9 /g" | sh -
;;
restart)
"$0" stop
sleep 3
"$0" start
;;
status) ps -ef|grep xxxx*
;;
*)
echo "Example: service.sh [start|stop|restart|status]" ;;
esac
启动命令
sh xxxx(文件名) start