如何使用 upstart 启动 rake 任务

Nic*_*roi 7 upstart bundler

我正在尝试将 Resque worker 设置为 Upstart init 脚本,以供 Monit 在 Rails 应用程序中使用。我不是系统管理员,我尝试使用我们服务器上的其他 init 脚本中的示例编写此代码,这是我得到的:

start on startup
stop on shutdown

pre-start script
   cd /var/www/my-app/current
end script

script
   exec bundle exec rake environment resque:work RAILS_ENV=staging PIDFILE=/var/run/resque.pid QUEUE=sync >> /var/log/resque.log
end script
Run Code Online (Sandbox Code Playgroud)

但它不起作用,如果我尝试sudo start resque我得到:

resque start/running, process XXXX
Run Code Online (Sandbox Code Playgroud)

据我所知,什么都没有启动,没有找到 Resque 进程,也没有日志文件。我完全不知道如何让它工作。

更新:我找到了 syslog 文件,它说:

Nov  4 17:20:09 fantasysports init: resque main process (3057) terminated with status 2
Run Code Online (Sandbox Code Playgroud)

更新:我尝试使用 sudo 运行它(是的,这没有意义!)并删除了对日志文件的输出重定向,现在我得到了不同的状态代码:

Nov  4 17:29:44 fantasysports init: resque main process (3276) terminated with status 10
Run Code Online (Sandbox Code Playgroud)

更新:最终放弃了 init.d 的 Upstart,因为start-stop-daemon有更好的记录,它让我可以完全控制正在发生的事情。

Mik*_*ike 5

这是我的做法..这也加入了 rvm

start on startup
stop on starting rcS

chdir /data/pusher/current
env RAILS_ENV=production
script
  /usr/local/bin/rvm-shell '1.9.2@app' -c 'JOBS_PER_FORK=25 RAILS_ENV=production QUEUE=app_production bundle exec rake --trace resque:work >> /data/app/current/log/app-worker.production.log 2>&1'
end script
Run Code Online (Sandbox Code Playgroud)

编辑:这是我如何以不同的用户身份运行.. chdir 似乎没有受到尊重.. 所以它有点hacky

start on runlevel [2345]
stop on starting rcS

chdir /data/app/current
env RAILS_ENV=production
script
        sudo -u user -s -- "cd /data/app/current; export RAILS_ENV=production; /usr/local/bin/rvm-shell '1.9.2-p180@app' -c 'QUEUE=app_production bundle exec rake resque:work >> /data/app/current/log/app-worker.production.log 2>&1'"
end script
Run Code Online (Sandbox Code Playgroud)

您几乎需要更改到正确的目录并在 sudo 命令中设置 RAILS_ENV