ruby-on-rails - Ubuntu 服务器上的 ROR、Redis、Resque、God 和 Cron - 启动

标签 ruby-on-rails redis crontab boot god

我在我的 ruby​​ 应用程序中做了几项上帝会照顾的工作。但是,当服务器重新启动时,作业停止。我想避免这种情况,所以我在我的服务器上制作了这个脚本。看起来像这样。

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 start"

它给了我

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 10.4.4 LTS)、rc.local、rc-default,现在我最近的尝试是 crontab。

脚本必须在我的用户下运行,而不是 root,(如果我在 root 下运行它找不到 ruby​​ 安装)。

因此,我在我的用户帐户下配置了 crontab:

@reboot /etc/init.d/my_app start

遗憾的是这不起作用...我不知道我做错了什么。这可能不是必需的。我的意思是,您不应该在启动 ruby​​ 应用程序时自动执行此操作吗?

我在这个服务器上用的是passenger,不知道跟这个有关系吗?

下面是我对 sh 所做的更改的解决方案:

我的应用.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"

最佳答案

忘记 cronjob。

Centos/Fedora:

sudo chmod a+x /etc/init.d/my_app
sudo chkconfig --add my_app
sudo chkconfig my_app on

Ubuntu/Debian:

sudo update-rc.d my_app defaults

这两个都将脚本符号链接(symbolic link)到 /etc/rc1.d/etc/rc2.d 等,并使脚本可以在启动时运行对于那些运行级别。

关于ruby-on-rails - Ubuntu 服务器上的 ROR、Redis、Resque、God 和 Cron - 启动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12669396/

相关文章:

perl - 如何编写 Perl 脚本以使用 curl 处理 URL?

ruby-on-rails - "The token is invalid"尝试使用 ActiveMerchant 设置 Paypal 定期付款

ruby-on-rails - Ruby BigDecimal 乘法

redis - 运行时警告 :You're running the worker with superuser privileges:this is absolutely not recommended

python - Redis使用python获取数据

node.js - 从特定时间开始每小时的 cron 表达式

ruby-on-rails - 如何在 Rails 上实现 cookieless flash 消息?

ruby-on-rails - 另一个Django v Rails问题-哪个更适合复杂的Web应用程序?

docker - RedisInsight Docker 显示 : site cannot be reached in browser

crontab - mysqldump & gzip 命令使用 crontab 正确创建 MySQL 数据库的压缩文件