Last active
October 19, 2016 07:10
-
-
Save jxinging/d969779a9f5b3a9d680e to your computer and use it in GitHub Desktop.
后台启动进程,如果已经在运行则退出
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ## 后台启动进程,如果已经在运行则退出 | |
| # $1 ,command | |
| # $2 ,lock file | |
| start_daemon(){ | |
| [ $# -lt 2 ] && return 2 | |
| local CMD=$1; local LOCK_FILE=$2 | |
| [ -s "$LOCK_FILE" ] && { PID=`cat $LOCK_FILE` ;ps axo pid,cmd | egrep $PID | egrep -q $0 && { | |
| echo Runing...,PID:$PID ;return 1;} || { echo Stoped,remove lock file :$LOCK_FILE ;} | |
| } | |
| { eval $CMD ; /bin/rm -f $LOCK_FILE ;} & | |
| PID=$!;echo Start,PID:$PID ;echo $PID > $LOCK_FILE | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment