Skip to content

Instantly share code, notes, and snippets.

@epugh
Created September 6, 2008 16:36
Show Gist options
  • Save epugh/9172 to your computer and use it in GitHub Desktop.
Save epugh/9172 to your computer and use it in GitHub Desktop.
require 'singleton'
begin
require 'daemon_controller'
rescue LoadError
raise('FATAL: sudo gem install FooBarWidget-daemon_controller -s http://gems.github.com')
end
##
# sudo port install memcached
class DaemonBackgroundrb
include Singleton
BACKGROUNDRB_PORT = 11006
def initialize
@controller = DaemonController.new(
:identifier => 'BackgroundRB',
:before_start => method(:before_start),
:start_command => "./script/backgroundrb start -e #{RAILS_ENV}",
:ping_command => lambda { TCPSocket.new('localhost', BACKGROUNDRB_PORT) },
:pid_file => File.join(RAILS_ROOT, 'tmp', 'pids', 'backgroundrb_dc.pid'),
:log_file => nil,
:timeout => 120
)
end
def start
@controller.start
end
def stop
@controller.stop
end
def running?
@controller.running?
end
private
def before_start
puts "** daemon_controller starting backgroundrb..."
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment