Module Daemon
In: lib/serverside/cluster.rb
lib/serverside/daemon.rb

The Daemon module takes care of starting and stopping daemons.

Methods

alive?   control   start   stop  

Classes and Modules

Module Daemon::PidFile
Class Daemon::Base
Class Daemon::Cluster

Constants

WorkingDirectory = FileUtils.pwd

Public Class methods

[Source]

    # File lib/serverside/daemon.rb, line 76
76:   def self.alive?(daemon)
77:     pid = PidFile.recall(daemon) rescue nil
78:     pid ? Process.exists?(pid) : false
79:   end

Controls a daemon according to the supplied command or command-line parameter. If an invalid command is specified, an error is raised.

[Source]

    # File lib/serverside/daemon.rb, line 35
35:   def self.control(daemon, cmd = nil)
36:     case (cmd || (!ARGV.empty? && ARGV[0]) || :nil).to_sym
37:     when :start
38:       start(daemon)
39:     when :stop
40:       stop(daemon)
41:     when :restart
42:       begin
43:         stop(daemon)
44:         sleep 2
45:       rescue
46:       end
47:       start(daemon)
48:     else
49:       raise 'Invalid command. Please specify start, stop or restart.'
50:     end
51:   end

Starts the daemon by forking and bcoming session leader.

[Source]

    # File lib/serverside/daemon.rb, line 54
54:   def self.start(daemon)
55:     fork do
56:       Process.setsid
57:       exit if fork
58:       PidFile.store(daemon, Process.pid)
59:       Dir.chdir WorkingDirectory
60:       File.umask 0000
61:       STDIN.reopen "/dev/null"
62:       STDOUT.reopen "/dev/null", "a"
63:       STDERR.reopen STDOUT
64:       trap("TERM") {daemon.stop; exit}
65:       daemon.start
66:     end
67:   end

Stops the daemon by sending it a TERM signal.

[Source]

    # File lib/serverside/daemon.rb, line 70
70:   def self.stop(daemon)
71:     pid = PidFile.recall(daemon)
72:     pid && Process.kill("TERM", pid) rescue nil
73:     PidFile.remove(daemon)
74:   end

[Validate]