Skip to content

Instantly share code, notes, and snippets.

@hoshinotsuyoshi
Created February 10, 2013 07:44
Show Gist options
  • Save hoshinotsuyoshi/4748819 to your computer and use it in GitHub Desktop.
Save hoshinotsuyoshi/4748819 to your computer and use it in GitHub Desktop.
worker-daemonize
#!/usr/bin/env ruby
#
# usage:
# ruby worker-daemonize start
#
require 'daemon_spawn'
require File.expand_path('../job',__FILE__)
WorkingDir = File.expand_path('../wd',__FILE__)
class ResqueWorkerDaemon < DaemonSpawn::Base
def start(args)
@worker = Resque::Worker.new('default')
@worker.verbose = true
@worker.work
end
def stop
@worker.try(:shutdown)
end
end
ResqueWorkerDaemon.spawn!({
:working_dir => WorkingDir,
:pid_file => File.join(WorkingDir, 'tmp', 'pids', 'echo_server.pid'),
:log_file => File.join(WorkingDir, 'log', 'echo_server.log'),
:sync_log => true,
:singleton => true
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment