服务启动脚本

#!/bin/bash

APP_NAME="get_logs"

checkpid() {
pid=`ps -ef | grep $APP_NAME | grep -v grep | awk '{print $2}'`
#return $pid
}

start() {
checkpid
if [ ! -z "$pid" ]; then
echo -e "${APP_NAME} is already running. pid=${pid} \033[31m[Failed]\033[0m"
exit 1
else
echo -n "Starting ${APP_NAME} ..."
/opt/scripts/bin/get_logs.sh &
echo -e "\033[32m[Ok]\033[0m"
fi

}

stop() {
checkpid
if [ ! -z "$pid" ]; then
echo -n "$APP_NAME will be stop ..."
kill -9 $pid
sleep 1
checkpid
if [ -z "$pid" ]; then
echo -e "\033[32m[OK]\033[0m"
else
echo -e "\033[31m[Failed]\033[0m"
exit 2
fi
else
echo "${APP_NAME} is not running"
fi
}

restart() {
stop
sleep 1
start
}

case "$1" in
'start')
start
;;
'stop')
stop
;;
'restart')
restart
;;
*)
echo "Usage: $0 {start|stop|restart}"
exit 1
esac

exit 0

posted @ 2019-12-23 16:53  30岁再次出发  阅读(243)  评论(0编辑  收藏  举报