seedwork 启动脚本

#!/bin/bash


#需要配置的参数

gearmand=172.17.0.23:4730

job_limit=100

log_level=all


worker_ROOT=${PWD}

NAME=${PWD##*/}

BASEDIR=$worker_ROOT/script

DAEMON=$worker_ROOT/$NAME

DESC="daemon $NAME"

PID="$DAEMON".pid

# 按天分割: %Y%m%d, 按小时分割: %Y%m%d%H,更多可参考: http://cronolog.org/usage.html

LOG="$DAEMON"_%Y%m%d.log

# cronolog 软件的路径

Cron=cronolog


set -e


process () {

    if [ -f $PID ]; then

        pid=$(cat $PID)

        if [ -z $(ps -ef |grep "$pid" |grep -v "grep") ]; then

            rm $PID

        else

            echo "$NAME process is running, use: 'sh $0 restart' instead"

            exit 1

        fi

    fi

}


# Check if DAEMON binary exist

test -f $DAEMON || { echo >&2 "$DAEMON doesn't exists. Exit. exec go build to create it."; exit 1; }


case "$1" in

  start)

  process

        nohup $DAEMON -log-level=$log_level -gearmand=$gearmand -basedir=$BASEDIR -pid=$PID -job-limit=$job_limit 2>&1 |$Cron $LOG &

        ;;

  stop)

        kill -2 `cat $PID`

        ;;

  restart)

        sh $0 stop

  sleep 2

        sh $0 start

        ;;

  *)

        N=$NAME

        echo "Usage: sh $N {start|stop|restart}" >&2

        exit 1

        ;;

esac


exit 0


你可能感兴趣的:(linux,shell)