sh boot status
#!/bin/bashAPP_NAME=elasticcd `dirname $0`# 使用说明,用来提示输入参数usage() {echo "Usage: sh boot [APP_NAME] [start|stop|restart|status]"exit 1}# 检查程序是否在运行is_exist(){# 获取PIDPID=$(ps -ef |grep ${APP_NAME} |grep -v grep |awk '{print $2}')# -z "${pid}"判断pid是否存在,如果不存在返回1,存在返回0if [ -z "${PID}" ]; then# 如果进程不存在返回1return 1els# 进程存在返回0return 0fi}# 定义启动程序函数start(){is_existif [ $? -eq "0" ]; thenecho "${APP_NAME} is already running, PID=${PID}"elsesh bin/elasticsearch -dis_existecho "${APP_NAME} start success, PID=${PID}"fi}# 停止进程函数stop(){is_existif [ $? -eq "0" ]; thenkill -9 ${PID}# 检测是否停止COUNT=1while [ $COUNT -eq 1 ]doecho -e ".\c"sleep 1is_existif [ -z "${PID}" ]; thenCOUNT=0echo "${APP_NAME} process stop"fidoneelseecho "There is not the process of ${APP_NAME}"fi}# 重启进程函数restart(){stopstart}# 查看进程状态status(){is_existif [ $? -eq "0" ]; thenecho "${APP_NAME} is running, PID=${PID}"elseecho "There is not the process of ${APP_NAME}"fi}case $1 in"start")start;;"stop")stop;;"restart")restart;;"status")status;;*)usage;;esacexit 0
