is_exist(){ if [ $(ps -ef | grep -c ${process}) -gt 1 ] then return 1 else return 0 fi }
is_running(){ is_exist if [ $? == 1 ] then echo -e "\033[32mdino uWSGI service is running!\033[0m"; return 1 else echo -e "\033[33mdino uWSGI service is not running!\033[0m" return 0 fi }
kill_all(){ echo -e "shutting down dino uWSGI service ...... \c" pids=$(ps x | grep ${process} | grep -v grep | awk '{print $1}') for pid in$pids do `kill -9 $pid` done sleep 1 is_exist if [ $? == 0 ] then echo -e "\033[32m[OK]\033[0m"; return 1 else echo -e "\033[31m[Fail]\033[0m" return 0 fi }
start_service(){ run_start_cmd echo -e "Starting dino uWSGI service ...... \c"; sleep 1 is_exist if [ $? == 1 ] then echo -e "\033[32m[OK]\033[0m"; return 1 else echo -e "\033[31m[Fail]\033[0m" return 0 fi }
cmd=$1
# start if [ $cmd = start ] then is_running; if [ $? == 0 ] then start_service fi
# status elif [ $cmd = status ];then is_running
# stop elif [ $cmd = stop ];then kill_all
# restart elif [ $cmd = restart ];then is_running if [ $? == 1 ] then kill_all if [ $? == 1 ] then start_service fi else start_service fi