本文主要是介绍restart.sh,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
#!/bin/bash
APP_NAME=""
usage(){
echo “Usage: sh 执行脚本.sh [start|stop|restart|status]”
exit 1
}
#重启所有应用
restart_all(){
for var in almbi*.jar;do
echo "jar-name:: v a r " A P P N A M E = var" APP_NAME= var"APPNAME=var
restart
done
}
#检查程序是否在运行
is_exist(){
pid=ps -ef|grep $APP_NAME|grep -v grep|awk '{print $2}'
#如果不存在返回1,存在返回0
if [ -z “${pid}” ]; then
return 1
else
return 0
fi
}
#启动方法
start(){
is_exist
if [ ? − e q " 0 " ] ; t h e n e c h o " ? -eq "0" ]; then echo " ?−eq"0"];thenecho"{APP_NAME} is already running. pid=${pid} ."
else
nohup java -jar $APP_NAME > /home/almbi/nohup.out 2>&1 &
fi
}
#停止方法
stop(){
is_exist
if [ $? -eq “0” ]; then
kill -9 p i d e l s e e c h o " pid else echo " pidelseecho"{APP_NAME} is not running."
fi
}
#输出运行状态
status(){
is_exist
if [ ? − e q " 0 " ] ; t h e n e c h o " ? -eq "0" ]; then echo " ?−eq"0"];thenecho"{APP_NAME} is running. Pid is p i d " e l s e e c h o " {pid}" else echo " pid"elseecho"{APP_NAME} is NOT running."
fi
}
#重启
restart(){
stop
start
}
#根据输入参数,选择执行对应方法,不输入则执行使用说明
case “$1” in
“start”)
start
;;
“stop”)
stop
;;
“status”)
status
;;
“restart”)
restart
;;
“restart_all”)
restart_all
;;
*)
restart_all
;;
esac
这篇关于restart.sh的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!