2012-05-04 20 views
0

我在Ubuntu 12.04服務器上安裝了帶有獨角獸的nginx。一切正常,網站,分貝,獨角獸......好。所以我試圖確保在重新啓動後,nginx和獨角獸啓動。我爲我的獨角獸進程設置了update-rc.d,但是它在重新啓動後無法啓動/工作。我懷疑它是與Ubuntu的使用「服務」,而不是「/etc/init.d/unicorn_init」Ubuntu 12.04:'unicorn_init.sh start'起作用,但'service unicorn_init start'不是

換句話說:

如果我執行:

$ /etc/init.d/unicorn_init start 

獨角獸啓動就好,沒有錯誤。

如果我執行:

$ service unicorn_init start 

失敗和獨角獸不啓動。

我認爲它與路徑有關。香港專業教育學院添加環境路徑PATH,GEM_PATH,& GEM_HOME,但我仍然收到了同樣的結果

1,如果我跑/usr/local/rvm/gems/ruby-1.9.3-p194/bin/unicorn,我出現錯誤:

usr/local/rvm/rubies/ruby-1.9.3-p194/lib/ruby/site_ruby/1.9.1/rubygems/dependency.rb:247:in `to_specs': Could not find unicorn (>= 0) amongst[bigdecimal-1.1.0, io-console-0.3, json-1.5.4, minitest-2.5.1, rake-0.9.2.2, rdoc-3.9.4] (Gem::LoadError) 
    from /usr/local/rvm/rubies/ruby-1.9.3-p194/lib/ruby/site_ruby/1.9.1/rubygems/dependency.rb:256:in `to_spec' 
    from /usr/local/rvm/rubies/ruby-1.9.3-p194/lib/ruby/site_ruby/1.9.1/rubygems.rb:1231:in `gem' 
    from /usr/local/rvm/gems/ruby-1.9.3-p194/bin/unicorn:18:in `<main>' 

2,如果我跑在/ var /導軌/ web應用/斌/麒麟,我得到的錯誤:

/usr/local/rvm/rubies/ruby-1.9.3-p194/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require': cannot load such file -- bundler/setup (LoadError) 
    from /usr/local/rvm/rubies/ruby-1.9.3-p194/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require' 
    from /var/rails/web-app/bin/unicorn:14:in `<main>' 

任何幫助將不勝感激!由於

回答

3

你應該使用一個麒麟包裝腳本,將包括所有所需的環境變量:

rvm wrapper 1.9.3 ruby-1.9.3 unicorn 

這將產生在init腳本ruby-1.9.3_unicorn使用這個而不是隻獨角獸。

你可以找到包裝更詳細地:

rvm wrapper 

如果在工作時通過捆綁完成(如capitrano),然後生成bundle的包裝:

rvm wrapper 1.9.3 ruby-1.9.3 bundle 

,並使用全該命令顯示的包裝路徑:

which ruby-1.9.3_bundle 
+0

YES!謝謝。我這樣做,將加載路徑更改爲 /usr/local/rvm/bin/ruby-1.9。3_unicorn 和 $ service unicorn_init start 成功運行。試圖重啓,獨角獸成功啓動。謝謝一堆! –

0

你告訴r埃裏克,我自己做,並在開發模式下運行很好。 這個例子不能正常使用,它仍然很粗糙。

config/unicorn_init文件:

TIMEOUT=${TIMEOUT-60} 
PID=$APP_ROOT/tmp/pids/unicorn.pid 
CMD="PATH=$_PATH GEM_HOME=$_GEM_HOME GEM_PATH=$_GEM_PATH $APP_ROOT/.bundle/bin/unicorn -D -c $APP_ROOT/config/unicorn.rb" 

set -e 
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 
    su -c "$CMD" - $APP_USER 
    ;; 
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" 
    su -c "$CMD" - $APP_USER 
    ;; 
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" 
    su -c "$CMD" - $APP_USER 
    ;; 
reopen-logs) 
    sig USR1 
    ;; 
*) 
    echo >&2 "Usage: $0 <start|stop|restart|upgrade|force-stop|reopen-logs>" 
    exit 1 
    ;; 
esac 
echo "#\!/bin/bash\n_PATH=$PATH\n_GEM_HOME=$GEM_HOME\n_GEM_PATH=$GEM_PATH\nAPP_ROOT=$(pwd)\nAPP_USER=$USER\n$(cat config/unicorn_init)" > config/unicorn_init.sh 
chmod +x config/unicorn_init.sh 
相關問題