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