2013-05-27 97 views
1

我有以下廚師例程來生成腳本以啓動/停止獨角獸守護程序。廚師例程中的權限錯誤

但是,當Capistrano執行此文件時,我總是會獲得Permission拒絕。我在做什麼錯誤的權限?

# recipes/default.rb 

template "/etc/init.d/unicorn_#{node['pod']['app_name']}" do 
    owner node['pod']['user'] 
    group node['pod']['user'] 
    mode 777 
    source "unicorn_init.erb" 
    variables(:app_name => node['pod']['app_name'], :user => node['pod']['user']) 
end 

# templates/default/unicorn_init.rb 

#!/bin/sh 
set -e 

# Feel free to change any of the following variables for your app: 
TIMEOUT=${TIMEOUT-60} 
APP_ROOT=/home/<%= @user %>/apps/<%= @app_name %>/current 
PID=/var/run/unicorn/unicorn_<%= @app_name %>.pid 
CMD="cd $APP_ROOT; bundle exec unicorn -D -c $APP_ROOT/config/unicorn.rb -E production" 
AS_USER=<%= @user %> 
set -u 

OLD_PIN="$PID.oldbin" 

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

oldsig() { 
    test -s $OLD_PIN && sudo -c "kill -$1 `cat $OLD_PIN`" - $AS_USER 
} 

run() { 
    if [ "$(id -un)" = "$AS_USER" ]; then 
    eval $1 
    else 
    su -c "$1" - $AS_USER 
    fi 
} 

case "$1" in 
start) 
    sig 0 && echo >&2 "Already running" && exit 0 
    run "$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" 
    run "$CMD" 
    ;; 
upgrade) 
    if sig USR2 && sleep 2 && sig 0 && oldsig QUIT 
    then 
    n=$TIMEOUT 
    while test -s $OLD_PIN && test $n -ge 0 
    do 
     printf '.' && sleep 1 && n=$(($n - 1)) 
    done 
    echo 

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

正如你所看到的,它不設置該文件的正確模式:

[2013-05-27T20:42:00+02:00] INFO: Processing template[/etc/init.d/unicorn_pod] action create (pod::default line 38) 
[2013-05-27T20:42:00+02:00] INFO: template[/etc/init.d/unicorn_pod] owner changed to 1001 
[2013-05-27T20:42:00+02:00] INFO: template[/etc/init.d/unicorn_pod] group changed to 110 
[2013-05-27T20:42:00+02:00] INFO: template[/etc/init.d/unicorn_pod] mode changed to 1411 

** [out :: localhost] -r----x--t 1 deployer deployer 1453 2013-05-27 17:48 unicorn_pod 

回答

1

docs。模式應該是八進制或字符串:

template "/etc/init.d/unicorn_#{node['pod']['app_name']}" do 
    [...] 
    mode 0777 #or mode "777" 
    [...] 
end