Anonymous (owner)

Revisions

  • d8f0c1 Thu Sep 04 11:43:59 -0700 2008
  • 9f9381 Thu Sep 04 11:43:40 -0700 2008
gist: 8844 Download_button fork
public
Public Clone URL: git://gist.github.com/8844.git
Text
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
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