我在我的紅寶石應用程序中做了幾項上帝照顧的工作。但是,服務器重新啓動作業時會停止。我想避免這個,所以我在我的服務器上創建了這個腳本。它看起來像這樣。Ubuntu服務器上的ROR,Redis,Resque,God&Cron - 啓動
my_app.sh
#!/bin/bash
# god tasks
#
case $1 in
start)
/usr/local/rvm/gems/ruby-1.9.3-p194/bin/god
/usr/local/rvm/gems/ruby-1.9.3-p194/bin/god start
/usr/local/rvm/gems/ruby-1.9.3-p194/bin/god load /usr/local/Linux/apache2/www/hej.se/ruby/config/resque.god
/usr/local/rvm/gems/ruby-1.9.3-p194/bin/god load /usr/local/Linux/apache2/www/hej.se/ruby/config/resque_schedule.god
;;
esac
exit 0
如果我手動登錄並寫
「/etc/init.d/my_app啓動」
它給了我
Sending 'start' command
No matching task or group
Sending 'load' command with action 'leave'
The following tasks were affected:
resque-0
resque-1
resque-2
resque-3
resque-4
Sending 'load' command with action 'leave'
The following tasks were affected:
resque_scheduler
一切正常,它做我想做的事,即工作。
我已經嘗試了幾種啓動Linux腳本的方法(Linux 10.4.4 LTS),rc.local,rc-default,現在我的最新嘗試是crontab。
腳本必須在我的用戶下運行,而不是root,(如果我在root下運行它,它不能找到ruby安裝)。
正因爲如此,我在我的用戶帳戶配置的crontab:
@reboot /etc/init.d/my_app start
可悲的是,這並不工作...我不我在做什麼錯。這應該可能沒有必要。我的意思是,在啓動ruby應用程序時,你不應該每次啓動時都能這樣做嗎?
我在這個服務器上使用乘客,我不知道這是否與它有關?
與我的SH所做的更改下面的解決方案:
my_app.sh
bash -c "source /usr/local/rvm/scripts/rvm && /usr/local/rvm/gems/ruby-1.9.3-p194/bin/god"
bash -c "source /usr/local/rvm/scripts/rvm && /usr/local/rvm/gems/ruby-1.9.3-p194/bin/god start"
bash -c "source /usr/local/rvm/scripts/rvm && /usr/local/rvm/gems/ruby-1.9.3-p194/bin/god load /usr/local/Linux/apache2/www/hej.se/ruby/config/resque.god"
bash -c "source /usr/local/rvm/scripts/rvm && /usr/local/rvm/gems/ruby-1.9.3-p194/bin/god load /usr/local/Linux/apache2/www/hej.se/ruby/config/resque_schedule.god"
如何讓腳本在啓動時運行?它試圖在啓動時運行它找不到紅寶石... 「/ usr/bin/env:ruby:沒有這樣的文件或目錄」 – Philip
我上面描述的命令會將它添加到啓動過程中。檢入/etc/rc*.d,這些都是自動運行的腳本(它們的'start'命令),該運行級別(0-6)。 – bricker
如果你的紅寶石找不到,那麼你只需要找出路徑。 RVM往往與這些東西混淆,我通常不會推薦它在生產服務器上,但由於您已經安裝了它,您只需要弄清楚如何配置它以正確查找ruby。 – bricker