#使用说明,用来提示输入参数 usage() { echo"Usage: sh server.sh [start|stop|restart|status]" exit 1 }
#检查程序是否在运行 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_log(){ is_exist if [ $? -eq 0 ]; then echo"${APP_NAME} 启动成功! pid=${pid}" else echo"${APP_NAME} 启动失败!请检查后重试" fi }
#启动方法 start(){ is_exist if [ $? -eq 0 ]; then echo"${APP_NAME} is already running. pid=${pid}" else nohup java -jar ${APP_PATH}/${APP_NAME} > /dev/null 2>&1 & #如果APP_NAME携带可变内容,请替换下方启动命令,符号 * 表示jar包名称中变化的部分 #nohup java -jar -Xmx512m -Xms512m ${APP_PATH}/${APP_NAME}*.jar >${APP_PATH}/web.log & start_log fi }
#停止方法 stop(){ is_exist if [ $? -eq "0" ]; then kill -9 $pid echo"${APP_NAME} 已关闭! pid=${pid}" else echo"${APP_NAME} is not running" fi #该脚本的特殊性:确保关闭所有openoffice进程 soffice_stop }
#输出运行状态 status(){ is_exist if [ $? -eq "0" ]; then echo"${APP_NAME} is running. Pid is ${pid}" else echo"${APP_NAME} is not running." fi }