mirror of
https://github.com/thinkjs/thinkjs.git
synced 2026-01-25 14:42:47 +00:00
66 lines
815 B
Bash
66 lines
815 B
Bash
#!/bin/sh
|
|
DIR=`pwd`
|
|
NODE=`which node`
|
|
# get action
|
|
ACTION=$1
|
|
|
|
PID_FILE='./App/Runtime/Data/app.pid';
|
|
|
|
# help
|
|
usage() {
|
|
echo "Usage: ./ctrl.sh {start|stop|restart}"
|
|
exit 1;
|
|
}
|
|
|
|
get_pid() {
|
|
if [ -f $PID_FILE ]; then
|
|
echo `cat $PID_FILE`
|
|
fi
|
|
}
|
|
|
|
# start app
|
|
start() {
|
|
pid=`get_pid`
|
|
|
|
if [ ! -z $pid ]; then
|
|
echo 'server is already running'
|
|
else
|
|
nohup $NODE $DIR/www/index.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
|
|
rm -rf $PID_FILE;
|
|
echo "server stopped !"
|
|
fi
|
|
}
|
|
|
|
restart() {
|
|
stop
|
|
sleep 0.5
|
|
echo =====
|
|
start
|
|
}
|
|
|
|
case "$ACTION" in
|
|
start)
|
|
start
|
|
;;
|
|
stop)
|
|
stop
|
|
;;
|
|
restart)
|
|
restart
|
|
;;
|
|
*)
|
|
usage
|
|
;;
|
|
esac |