脚本
#!/bin/sh
SERVER_NAME=xxl-job.jar
SERVER_PATH=/usr/local/project/xxl-job/
LOG_PATH=/usr/local/logs/xxl-job/error.log
function status() {
pid=$(ps -ef | grep ${SERVER_NAME} | awk 'NR==1{print $2}');
if [[ -n "$pid" ]];
then
echo "the status of server:$SERVER_NAME is started!";
return 1;
else
echo "the status of server:$SERVER_NAME is stopped";
return 0;
fi;
}
function start(){
status;
if [ "$?" == 1 ];
then
echo "[server:$SERVER_NAME] is starting...";
else
nohup java -jar ${SERVER_PATH}${SERVER_NAME} >> ${LOG_PATH} 2>&1 &
echo "[server:$SERVER_NAME] is started success";
fi;
};
function stop(){
status;
if [ "$?" == 1 ];
then
pid=$(ps -ef | grep ${SERVER_NAME} | awk 'NR==1{print $2}');
echo "[server:$SERVER_NAME] is stopping...";
kill -9 ${pid}
echo "[server:$SERVER_NAME] is stopped";
fi;
};
action=$1
case $action in
start)
start;
;;
stop)
stop;
;;
restart)
stop;
sleep 1;
start;
;;
status)
status;
;;
*) echo "$0 {start|stop|restart|status}"
exit 4
;;
esac
版权声明:本文为weixin_44185837原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。