Skip to content

Instantly share code, notes, and snippets.

Created September 4, 2008 18:43
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save anonymous/8844 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 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment