Skip to content

Instantly share code, notes, and snippets.

@duchenpaul
Created February 23, 2018 09:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save duchenpaul/375ff8e269df5499086e2fcaeaf1bc06 to your computer and use it in GitHub Desktop.
Save duchenpaul/375ff8e269df5499086e2fcaeaf1bc06 to your computer and use it in GitHub Desktop.
Simple script to control service
#!/bin/bash
TARGET_SERVICE=server_status_web
service_start_cmd='/home/pi/run/server_statisic/FlaskApp/server_status_web.py'
usage(){
echo -e "Usage: bash $0 [ start | stop | restart ] "
exit 1
}
start_service(){
`${service_start_cmd} &`
}
kill_service(){
sudo kill -9 $(ps ax | grep ${TARGET_SERVICE} | fgrep -v grep | awk '{ print $1 }')
}
service_status(){
ps axf | grep ${TARGET_SERVICE} | fgrep -v grep
}
if [ $# -ne 1 ]; then
usage
fi
case $1 in
start )
echo "Start ${TARGET_SERVICE} ..."
start_service
service_status
;;
stop )
echo "Stop ${TARGET_SERVICE} ..."
kill_service
;;
restart )
echo "Restart"
kill_service
start_service
service_status
;;
status )
service_status
;;
* )
usage
;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment