我试图设置Resque worker作为Monit在Rails应用程序中使用的Upstart初始化脚本。 我不是一个系统pipe理员,我试图用我们服务器上其他初始化脚本的例子来写这个,下面是我得到的:
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
但它不起作用,如果我尝试sudo start resque我得到:
resque start/running, process XXXX
据我所知,没有任何事情正在开始,没有findResque进程,也没有日志文件。 我很迷茫,如何让它工作。
更新 :我find了系统日志文件,它说:
Nov 4 17:20:09 fantasysports init: resque main process (3057) terminated with status 2
更新 :我试图使用sudo(是的,这是没有道理的!)运行它,并删除输出redirect到日志文件,现在我得到一个不同的状态代码:
Nov 4 17:29:44 fantasysports init: resque main process (3276) terminated with status 10
更新 :由于start-stop-daemon有更好的文档logging,所以它完全控制了正在发生的事情。
这是我如何做到这一点。这也增加了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
编辑:这里是我如何做它作为一个不同的用户运行.. chdir似乎并没有荣幸..所以这是一种哈克
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
您几乎需要切换到正确的目录,并在sudo命令中设置RAILS_ENV
你可能想看看福尔曼: http://ddollar.github.com/foreman/有能力出口到新贵,并build议在许多职位,包括这一个pipe理resque工人: http:// michaelvanrooijen .COM /用品/ 2011/06/08-pipe理和监控-您-ruby应用与-领class-和-新贵/
在“集成”一节中,RVM手册推荐“ 使用基于init.d或upstart启动的基于RVM和Ruby的服务 ”的方式是使用RVM别名和包装器。
我有一个情况,我必须监视bluepill过程。 这个进程是一个守护进程,所以分叉2次。 从rvm-shell命令开始,添加了第三个fork …导致Upstart无法跟踪进程PID ( 它只能跟踪第二个进程的最大进程 – 当给出expect daemon节点时 )。
我通过以下方式解决了这个问题:
首先,我为我的环境创build了一个RVM别名:
rvm alias create my_app ruby-2.0.0-p247@my_app
然后我用我的工作如下的新贵configuration:
`#/etc/init/bluepill_my-app.conf
description "my_app Bluepill" start on runlevel [2] stop on runlevel [016] setuid my-app setgid my-app expect daemon respawn env USER=my-app env HOME=/var/www/my-app/ env RAILS_ENV=my-app env BLUEPILL_BASE_DIR=/tmp/bluepill_my-app chdir /var/www/my-app/current/ exec /var/www/my-app/.rvm/wrappers/my-app/bundle exec bluepill --no-privileged load /var/www/my-app/current/config/deploy/monitoring/my-app.pill >> /tmp/upstart.log 2>&1
`
Bundler需要安装在RVM别名指向的给定gemset中。
调用bundler包装器脚本不会像rvm-shell命令那样产生任何分支。
另一种方法是在使用的gemset中安装bluepill gem,为它创build一个包装脚本并直接使用它,而不需要bundle exec – 就像RVM手册所build议的 – 但是通过bunlder使用它可以让bluepill .pill文件使用任何图书馆使用我的应用程序(如setingslogic等)。
这有一个小题目,但我认为这是一个很好的例子,如何做得更好。 我希望这有帮助。