Last active
August 6, 2019 03:09
-
-
Save saosir/3bfa4386d64f7ca5eda78e8f56ac733a to your computer and use it in GitHub Desktop.
start/stop/restart/status shell script template for server operation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/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