Created
February 8, 2020 04:06
-
-
Save wulucxy/3738b875a1f5d612737bcfcd207c1bf8 to your computer and use it in GitHub Desktop.
#shell
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 | |
DIR=`pwd` | |
NODE=`which node` | |
# get action | |
ACTION=$1 | |
# help | |
usage() { | |
echo "Usage: ./appctl.sh {start|stop|restart}" | |
exit 1; | |
} | |
get_pid() { | |
if [ -f ./run/app.pid ]; then | |
echo `cat ./run/app.pid` | |
fi | |
} | |
# start app | |
start() { | |
pid=`get_pid` | |
if [ ! -z $pid ]; then | |
echo 'server is already running' | |
else | |
$NODE $DIR/app.js 2>&1 & | |
echo 'server is running' | |
fi | |
} | |
# stop app | |
stop() { | |
pid=`get_pid` | |
if [ -z $pid ]; then | |
echo 'server not running' | |
else | |
echo "server is stopping ..." | |
kill -15 $pid | |
echo "server stopped !" | |
fi | |
} | |
restart() { | |
stop | |
sleep 0.5 | |
echo ===== | |
start | |
} | |
case "$ACTION" in | |
start) | |
start | |
;; | |
stop) | |
stop | |
;; | |
restart) | |
restart | |
;; | |
*) | |
usage | |
;; | |
esac | |
// 使用 | |
``` | |
./appctl.sh start // 启动 | |
./appctl.sh stop // 关闭 | |
./appctl.sh restart // 重启 | |
``` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment