2013-08-03 29 views
2

我使用的是提供的init.d腳本(init.d script from the sidekiq github repo),但是我在安裝了系統RVM的Ubuntu系統上。使用RVM管理使用init.d腳本的sidekiq

我似乎無法弄清楚如何進入我的應用程序目錄,併發出命令,而不會有一些抱怨日誌中沒有實際開始。

問題:當我使用RVM時,sidekiq的啓動命令應該如何在我的init.d腳本中看起來像?我的用戶名爲ubuntu。目前我有這在我的init.d腳本:

START_CMD="$BUNDLE exec $SIDEKIQ" 
# where bundle is /usr/local/rvm/gems/ruby-1.9.3-p385/bin/bundle 
# and sidekiq is sidekiq 
# I've also tried with the following args: -e $APP_ENV -P $PID_FILE -C $APP_CONFIG/sidekiq.yml -d -L $LOG_FILE" 
RETVAL=0 


start() { 

    status 
    if [ $? -eq 1 ]; then 

[ `id -u` == '0' ] || (echo "$SIDEKIQ runs as root only .."; exit 5) 
[ -d $APP_DIR ] || (echo "$APP_DIR not found!.. Exiting"; exit 6) 
cd $APP_DIR 
echo "Starting $SIDEKIQ message processor .. " 
echo "in dir `pwd`" 
su - ubuntu -c "$START_CMD >> $LOG_FILE 2>&1 &" 
RETVAL=$? 
#Sleeping for 8 seconds for process to be precisely visible in process table - See status() 
sleep 8 
[ $RETVAL -eq 0 ] && touch $LOCK_FILE 
return $RETVAL 
    else 
    echo "$SIDEKIQ message processor is already running .. " 
    fi 


} 

我sidekiq.log給了我這個錯誤:Could not locate Gemfile。但是,根據執行此命令時的echo pwd,我打印了工作目錄,並且我絕對是在我應用程序的當前目錄中。

當我拿出蘇 - [這裏指揮] Ubuntu的-c,我得到這個錯誤:

/usr/bin/env: ruby_noexec_wrapper: No such file or directory 

我的解決方法就是手動啓動的過程。當我手動cd到我的應用程序目錄,併發出以下命令:

bundle exec sidekiq -d -L log/sidekiq.log -P tmp/pids/sidekiq.pid

事情按計劃進行,然後

sudo /etc/init.d/sidekiq status

告訴我的事情是啓動和運行。

此外,sudo /etc/init.d/sidekiq停止和狀態按預期工作。

回答

2

的包裝紙:

rvm wrapper ruby-1.9.3-p385 --no-links bundle # OR: 
rvm wrapper ruby-1.9.3-p385 --no-links --all 

您可以使用別名來使其更容易:

rvm alias create my_app 1.9.3-p385 

BUNDLER=/usr/local/rvm/wrappers/ruby-1.9.3-p385/bundle 

的情況下,打捆包裝不可用產生的呢然後像這樣使用它:

BUNDLER=/usr/local/rvm/wrappers/my_app/bundle 

這樣你就不必更改腳本時應用紅寶石變化 - 只需更新別名,對於這個在RVM-Capistrano酒店=一個很好的說明/集成>https://github.com/wayneeseguin/rvm-capistrano/#create-application-alias-and-wrappers

+0

在/usr/local/rvm/wrappers/ruby-1.9.3-p385目錄中,沒有捆綁命令。 '哪個bundle給了我/usr/local/rvm/gems/ruby-1.9.3-p385/bin/bundle。另外,我是否需要su - ubuntu -c [命令]代碼? – Danny

+0

還添加了指令,如果不可用,則生成包裝 – mpapis