Skip to content

Instantly share code, notes, and snippets.

@saosir
Last active August 6, 2019 03:09
Show Gist options
  • Select an option

  • Save saosir/3bfa4386d64f7ca5eda78e8f56ac733a to your computer and use it in GitHub Desktop.

Select an option

Save saosir/3bfa4386d64f7ca5eda78e8f56ac733a to your computer and use it in GitHub Desktop.
start/stop/restart/status shell script template for server operation
#!/bin/sh
BASE_HOME=$(dirname $(readlink -f "$0"))
PID=${BASE_HOME}/.pid
status(){
echo "==========status======="
status=`ps -p $$`
}
start() {
echo "==========start==========="
}
stop() {
echo "===========stop============"
pid=$$
kill_cmd="pstree -p $pid | awk -F \"[()]\" '{for(i=0;i<=NF;i++)if(\$i~/[0-9]+/)print \$i}' |"'grep -v -E "\[|\(|\)|\]"|xargs kill -9'
eval ${kill_cmd}
}
restart() {
stop;
echo "sleeping.........";
sleep 3;
start;
}
case "$1" in
'start')
start
;;
'stop')
stop
;;
'status')
status
;;
'restart')
restart
;;
*)
echo "usage: $0 {start|stop|restart|status}"
exit 1
;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment