Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
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 DaemonMemcache
include Singleton
MEMCACHE_PORT = 11211
def initialize
@controller = DaemonController.new(
:identifier => 'Memcached distributed memory object caching system',
:before_start => method(:before_start),
:start_command => "memcached -d -m 64 -p #{MEMCACHE_PORT} -P" + File.join(RAILS_ROOT, 'tmp', 'pids', 'memcached.pid'),
:ping_command => lambda { TCPSocket.new('localhost', MEMCACHE_PORT) },
:pid_file => File.join(RAILS_ROOT, 'tmp', 'pids', 'memcached.pid'),
:log_file => nil,
:timeout => 10
)
end
def start
@controller.start
end
def stop
@controller.stop
end
def running?
@controller.running?
end
private
def before_start
puts "** daemon_controller starting memcached..."
end
end
### Trackback: http://geminstallthat.wordpress.com/2008/09/04/daemon_controller-memcached-configuration/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment