linux下的启停脚本
linux下的根据项目名称,进行进程的启停脚本
#!/bin/bash JAVA=/usr/bin/java APP_HOME=/opt/program/qa/wechat APP_NAME=programname.jar APP_PARAM="--spring.config.location=${APP_HOME}/application.properties --logging.path=${APP_HOME}" case $1 in start) PID=$(ps -ef | grep ${APP_NAME} | grep -v grep | awk '{print $2}') if [ -z "$PID" ] ;then echo "start ${APP_NAME}" nohup ${JAVA} -Dfile.encoding=utf-8 -jar ${APP_HOME}/${APP_NAME} ${APP_PARAM} > /dev/null 2>&1 & else echo "${APP_NAME} is running" fi ;; stop) PID=$(ps -ef | grep ${APP_NAME} | grep -v grep | awk '{print $2}') if [ -z "$PID" ] ;then echo "${APP_NAME} is not running" else echo "stop ${APP_NAME}" kill -9 $PID fi ;; restart) PID=$(ps -ef | grep ${APP_NAME} | grep -v grep | awk '{print $2}') if [ -z "$PID" ] ;then echo "start ${APP_NAME}" nohup ${JAVA} -Dfile.encoding=utf-8 -jar ${APP_HOME}/${APP_NAME} ${APP_PARAM} > /dev/null 2>&1 & else echo "stop ${APP_NAME}" kill -9 $PID echo "start ${APP_NAME}" nohup ${JAVA} -Dfile.encoding=utf-8 -jar ${APP_HOME}/${APP_NAME} ${APP_PARAM} > /dev/null 2>&1 & fi ;; logs) tail -f ${APP_HOME}/catalina.out ;; status) PID=$(ps -ef | grep ${APP_NAME} | grep -v grep | awk '{print $2}') if [ -z "$PID" ] ;then echo "${APP_NAME} is not running" else echo "${APP_NAME} is running, pid $PID" fi ;; esac
![](https://images.cnblogs.com/cnblogs_com/qianjinyan/910455/o_jasmine%20love.gif)