码迷,mamicode.com
首页 > 其他好文 > 详细

seedwork 启动脚本

时间:2015-02-04 16:50:56      阅读:139      评论:0      收藏:0      [点我收藏+]

标签:shell linux

#!/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


本文出自 “寒江独钓” 博客,请务必保留此出处http://iter2012.blog.51cto.com/6873825/1611504

seedwork 启动脚本

标签:shell linux

原文地址:http://iter2012.blog.51cto.com/6873825/1611504

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!