5 # The God::Server oversees the DRb server which dishes out info on this God daemon.
9 # The location of the socket for a given port
10 # +port+ is the port number
12 # Returns String (file location)
13 def self.socket_file(port)
14 "/tmp/god.#{port}.sock"
17 # The address of the socket for a given port
18 # +port+ is the port number
20 # Returns String (drb address)
22 "drbunix://#{self.socket_file(port)}"
25 # The location of the socket for this Server
27 # Returns String (file location)
29 self.class.socket_file(@port)
32 # The address of the socket for this Server
34 # Returns String (drb address)
36 self.class.socket(@port)
39 # Create a new Server and star the DRb server
40 # +port+ is the port on which to start the DRb service (default nil)
41 def initialize(port = nil)
51 # Forward API calls to God
53 # Returns whatever the forwarded call returns
54 def method_missing(*args, &block)
55 God.send(*args, &block)
58 # Stop the DRb server and delete the socket file
63 FileUtils.rm_f(self.socket_file)
68 # Start the DRb server. Abort if there is already a running god instance
74 @drb ||= DRb.start_service(self.socket, self)
75 applog(nil, :info, "Started on #{DRb.uri}")
76 rescue Errno::EADDRINUSE
77 applog(nil, :info, "Socket already in use")
79 server = DRbObject.new(nil, self.socket)
85 abort "Socket #{self.socket} already in use by another instance of god"
86 rescue StandardError, Timeout::Error
87 applog(nil, :info, "Socket is stale, reopening")
88 File.delete(self.socket_file) rescue nil
89 @drb ||= DRb.start_service(self.socket, self)
90 applog(nil, :info, "Started on #{DRb.uri}")