#!/bin/bash
### BEGIN INIT INFO
# Provides:          taskbuilder.org
# Required-Start:    $local_fs $network
# Required-Stop:     $local_fs
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: wsocket service
# Description:       tasgineServer
### END INIT INFO 
#
# chkconfig: 2345 99 08
# description: tasgineServer

DEAMON=/home/taskmsg/tasgine/
Name=tasgineServer
PID=tasgineServer.pid
ServerName=start

cd $DEAMON
case "$1" in
    start)
		echo "tasgine正在启动服务......"
				sleep 5
        ./tasgine $ServerName &
				pidVal=`ps -ef|grep -i tasgine' '"${ServerName}"|grep -v "grep"|awk '{print $2}'`
				echo pid:${pidVal[@]}
				echo ${pidVal[@]} > $PID
		echo "tasgine启动成功"
        ;;
    stop)
		echo "tasgine正在停止服务......"
				kVal=`cat $PID`
				echo pid:${kVal[@]}
        kill -9 ${kVal[@]}
		echo "tasgine已停止"
        ;;
    reload|restart)
		echo "tasgine正在停止服务......"
				kVal=`cat $PID`
				echo pid:${kVal[@]}
        kill -9 ${kVal[@]}
		echo "tasgine已停止"
				sleep 2
		echo "tasgine正在启动服务......"
        ./tasgine $ServerName &
				pidVal=`ps -ef|grep -i tasgine' '"${ServerName}"|grep -v "grep"|awk '{print $2}'`
				echo pid:${pidVal[@]}
				echo ${pidVal[@]} > $PID
		echo "tasgine启动成功"
        ;;
    list)
        pidVal=`ps -ef|grep -i tasgine' '"${ServerName}"|grep -v "grep"|awk '{print $2}'`
				echo "tasgine服务pid："${pidVal[@]}""
        ;;
	update)
        ./tasgine npm/bin/npm-cli.js update tfp
        ;;
    *)
        echo "使用方法: "${Name}" {start|stop|restart|reload|list|update}"
        exit 1
        ;;
esac