我有以下脚本用于在 ruby on rails 中启动延迟的工作人员
require 'rubygems'
require 'daemon_spawn'
$: << '.'
RAILS_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
class DelayedJobWorker < DaemonSpawn::Base
def start(args)
ENV['RAILS_ENV'] ||= args.first || 'development'
Dir.chdir RAILS_ROOT
require File.join('config', 'environment')
Delayed::Worker.new.start
end
def stop
system("kill `cat #{RAILS_ROOT}/tmp/pids/delayed_job.pid`")
end
end
DelayedJobWorker.spawn!(:log_file => File.join(RAILS_ROOT, "log", "delayed_job.log"),
:pid_file => File.join(RAILS_ROOT, 'tmp', 'pids', 'delayed_job.pid'),
:sync_log => true,
:working_dir => RAILS_ROOT)
它以这个命令开始
user@mysystem:path/to/my/application$ ruby script/delayed_job start production
DelayedJobWorker started.
我正在尝试使用 crontab 在启动时自动执行此操作
为此我制作了此脚本
#!/bin/bash
cd path/to/my/application
ruby script/delayed_job start production
这是我的 crontab
# m h dom mon dow command
SHELL=/bin/bash
@reboot /path/to/my/script/delayed_job_at_startup.sh
当我重新启动系统时,脚本没有成功,我从 crontab 收到此消息
X-Cron-Env: <SHELL=/bin/bash>
X-Cron-Env: <HOME=/home/finalsayan>
X-Cron-Env: <PATH=/usr/bin:/bin>
X-Cron-Env: <LOGNAME=finalsayan>
/usr/local/rvm/rubies/ruby-1.9.3-p194/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require': cannot load such file -- daemon_spawn (LoadError)
from /usr/local/rvm/rubies/ruby-1.9.3-p194/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
from script/delayed_job:24:in `<main>'
感谢您的帮助