2012-08-23 4 views
0

유니콘을 시작/중지/다시 시작하는 데 적합한 유니콘 셸 스크립트로 작업하고 있습니다. 내가 어떻게 실제로 작동하도록하는 데 약간의 어려움을 겪고 있는지.셸 스크립트 명령을 찾을 수 없음

이 문제에 대한 도움을 주시면 대단히 감사하겠습니다.

셸 스크립트 (sh unicorn_init.sh)를 실행하면 다음과 같은 결과가 표시됩니다.

kill: 72: No such process 

    unicorn_init.sh: 72: cd /data/appname/staging/releases/20120823055753; bundle exec unicorn_rails -D -c /data/appname/staging/releases/20120823055753/config/unicorn.rb -E staging: not found 

이 내 쉘 스크립트의 현재 버전 :

#!/bin/sh 
set -e 
# Example init script, this can be used with nginx, too, 
# since nginx and unicorn accept the same signals 

# Feel free to change any of the following variables for your app: 
TIMEOUT=${TIMEOUT-60} 
APP_ROOT=/data/appname/staging/releases/20120823055753 
SHARED_ROOT=/data/appname/staging/shared 
PID=$SHARED_ROOT/pids/unicorn-staging.pid 
CMD="cd $APP_ROOT; bundle exec unicorn_rails -D -c $APP_ROOT/config/unicorn.rb -E staging" 
action="$1" 
set -u 

old_pid="$PID.oldbin" 

cd $APP_ROOT || exit 1 

sig() { 
     test -s "$PID" && kill -$1 `cat $PID` 
} 

oldsig() { 
     test -s $old_pid && kill -$1 `cat $old_pid` 
} 

case $action in 
start) 
     sig 0 && echo >&2 "Already running" && exit 0 
     "$CMD" 
     ;; 
stop) 
     sig QUIT && exit 0 
     echo >&2 "Not running" 
     ;; 
force-stop) 
     sig TERM && exit 0 
     echo >&2 "Not running" 
     ;; 
restart|reload) 
     sig HUP && echo reloaded OK && exit 0 
     echo >&2 "Couldn't reload, starting '$CMD' instead" 
     "$CMD" 
     ;; 
upgrade) 
     if sig USR2 && sleep 2 && sig 0 && oldsig QUIT 
     then 
       n=$TIMEOUT 
       while test -s $old_pid && test $n -ge 0 
       do 
         printf '.' && sleep 1 && n=$(($n - 1)) 
       done 
       echo 

       if test $n -lt 0 && test -s $old_pid 
       then 
         echo >&2 "$old_pid still exists after $TIMEOUT seconds" 
         exit 1 
       fi 
       exit 0 
     fi 
     echo >&2 "Couldn't upgrade, starting '$CMD' instead" 
     "$CMD" 
     ;; 
reopen-logs) 
     sig USR1 
     ;; 
*) 
     echo >&2 "Usage: $0 <start|stop|restart|upgrade|force-stop|reopen-logs>" 
     exit 1 
     ;; 
esac 
+0

, 당신은'에 sig'를 수정해야 할 (1) 프로세스가 존재하지 않는 경우 kill''에서 오류 출력을 표시하지, (2)하지 주사위. 'set -e' 때문에 더 이상 실행되지 않는 프로세스를 종료하려고하면 스크립트가 종료됩니다. 고치는 것은 어렵지 않지만'set -e '에 대한 코딩은 좀 더 어렵습니다. – tripleee

+0

''$ CMD '''에서 따옴표를 제거하십시오. – cdarke

답변

2

따옴표 주위 $CMD 전체 변수 값이 공백을 포함하여 명령이라고 의미한다. 여기에 설명하기 위해 간단한 예입니다 : 순간적으로

/home/user1> CMD='echo hello' 
/home/user1> $CMD 
hello 
/home/user1> "$CMD" 
-bash: echo hello: command not found 
/home/user1> 
관련 문제