Goals
- Simplest code possible to daemonize code, redirect output and manage the
pidfile.
Usage
require 'forker'
Forker.fork!(
:log => "/dev/null", :pid => "/var/run/#{File.basename($0)}.pid", :chdir => false, :umask => false )
Or for a simple start/stop script
require 'forker'
Forker::CLI.run(ARGV)
Example bin/worker script for Resque
$rails_rake_task = true
require File.expand_path("../config/environment", File.dirname(__FILE__))
require 'forker'
Forker::CLI.run(ARGV)
worker = nil
queues = (ENV['QUEUES'] || ENV['QUEUE'] || '*').to_s.split(',')
begin
worker = Resque::Worker.new(*queues)
worker.verbose = ENV['LOGGING'] || ENV['VERBOSE']
worker.very_verbose = ENV['VVERBOSE']
rescue Resque::NoQueueError
abort "set QUEUE env var, e.g. $ QUEUE=critical,high,low rake resque:work"
end
puts "*** Starting worker in #{ENV['RAILS_ENV']} environment: #{worker}"
worker.work(ENV['INTERVAL'] || 5)