Skip to content

Commit

Permalink
1,mv initrd script to 'root' dir,for no need to change the service sc…
Browse files Browse the repository at this point in the history
…ript when do update.

2,according to code/version.txt to start the specific xx_net
3,add 'status' command for service
  • Loading branch information
rowanpang committed Dec 30, 2016
1 parent a86299a commit 6ea7051
Showing 1 changed file with 30 additions and 6 deletions.
36 changes: 30 additions & 6 deletions code/default/xx_net.sh → xx_net.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,23 +26,45 @@ else
PYTHON="python"
fi

PACKAGE_PATH=$("${PYTHON}" -c "import os; print os.path.dirname(os.path.realpath('$0'))")
if [ -L $0 ];then
PACKAGE_PATH="$(dirname $(readlink -n $0))/"
else
PACKAGE_PATH="./"
fi
PACKAGE_VER_FILE="${PACKAGE_PATH}code/version.txt"
PACKAGE_VER="default"
if [ -f "${PACKAGE_VER_FILE}" ];then
PACKAGE_VER=$(cat $PACKAGE_VER_FILE)
fi
PACKAGE_START="${PACKAGE_PATH}code/${PACKAGE_VER}/launcher/start.py"

if ! [ -f $PACKAGE_START ];then
PACKAGE_START="${PACKAGE_PATH}code/default/launcher/start.py"
fi

start() {
echo -n "Starting ${PACKAGE_DESC}: "
if hash python2 2>/dev/null; then
#nohup "${PYTHON}" launcher/start.py 2>&1 | /usr/bin/logger -t ${PACKAGE_NAME} &
nohup "${PYTHON}" ${PACKAGE_PATH}/launcher/start.py >/dev/null 2>&1 &
nohup "${PYTHON}" ${PACKAGE_START} >/dev/null 2>&1 &
fi
echo "${PACKAGE_NAME}."
}

stop() {
echo -n "Stopping ${PACKAGE_DESC}: "
kill -9 `ps aux | grep "${PYTHON} ${PACKAGE_PATH}/launcher/start.py" | grep -v grep | awk '{print $2}'` || true
kill -9 `ps aux | grep "${PYTHON} ${PACKAGE_START}" | grep -v grep | awk '{print $2}'` || true
echo "${PACKAGE_NAME}."
}

status() {
pid="PID`ps aux | grep "${PYTHON} ${PACKAGE_START}" | grep -v grep | awk '{print $2}'`"
if [ $pid == "PID" ];then
echo "xx-net stoped"
else
echo "xx-net running,pid: ${pid##"PID"}"
fi
}

restart() {
stop
sleep 1
Expand All @@ -51,7 +73,7 @@ restart() {

usage() {
N=$(basename "$0")
echo "Usage: [sudo] $N {start|stop|restart}" >&2
echo "Usage: [sudo] $N {start|stop|restart|status}" >&2
exit 1
}

Expand All @@ -74,10 +96,12 @@ case "$1" in
restart | force-reload)
restart
;;
status)
status
;;
*)
usage
;;
esac

exit 0
}

0 comments on commit 6ea7051

Please sign in to comment.