Class | DaemonController |
In: |
lib/daemon_controller/lock_file.rb
lib/daemon_controller/version.rb lib/daemon_controller.rb |
Parent: | Object |
Main daemon controller object. See the README for an introduction and tutorial.
MAJOR | = | 0 |
MINOR | = | 2 |
TINY | = | 5 |
VERSION_STRING | = | "#{MAJOR}.#{MINOR}.#{TINY}" |
ALLOWED_CONNECT_EXCEPTIONS | = | [Errno::ECONNREFUSED, Errno::ENETUNREACH, Errno::ETIMEDOUT, Errno::ECONNRESET, Errno::EINVAL, Errno::EADDRNOTAVAIL] |
SPAWNER_FILE | = | File.expand_path(File.join(File.dirname(__FILE__), "daemon_controller", "spawn.rb")) |
Create a new DaemonController object.
If the value is a Proc, and the before_start option is given too, then the start_command Proc is guaranteed to be called after the before_start Proc is called.
The value may be a command string. This command must exit with an exit code of 0 if the daemon can be successfully connected to, or exit with a non-0 exit code on failure.
The value may also be a Proc, which returns an expression that evaluates to true (indicating that the daemon can be connected to) or false (failure). If the Proc raises Errno::ECONNREFUSED, Errno::ENETUNREACH, Errno::ETIMEDOUT or Errno::ECONNRESET, Errno::EINVAL and Errno::EADDRNOTAVAIL then that also means that the daemon cannot be connected to. NOTE: if the ping command returns an object which responds to close, then that method will be called on the return value. This makes it possible to specify a ping command such as lambda { TCPSocket.new(‘localhost’, 1234) }, without having to worry about closing it afterwards. Any exceptions raised by close are ignored.
The default value is nil.
The default value is 15.
The default value is 15.
An alternative way to check whether the daemon has terminated with an error, is by checking whether its log file has been recently updated. If, after the daemon has started, the log file hasn‘t been updated for the amount of seconds given by the :log_file_activity_timeout option, then the daemon is assumed to have terminated with an error.
The default value is 7.
The default is false.
Connect to the daemon by running the given block, which contains the connection logic. If the daemon isn‘t already running, then it will be started.
The block must return nil or raise Errno::ECONNREFUSED, Errno::ENETUNREACH, Errno::ETIMEDOUT, Errno::ECONNRESET, Errno::EINVAL and Errno::EADDRNOTAVAIL to indicate that the daemon cannot be connected to. It must return non-nil if the daemon can be connected to. Upon successful connection, the return value of the block will be returned by connect.
Note that the block may be called multiple times.
Raises:
Returns the daemon‘s PID, as reported by its PID file. Returns the PID as an integer, or nil there is no valid PID in the PID file.
This method doesn‘t check whether the daemon‘s actually running. Use running? if you want to check whether it‘s actually running.
Raises SystemCallError or IOError if something went wrong during reading of the PID file.
Checks whether the daemon is still running. This is done by reading the PID file and then checking whether there is a process with that PID.
Raises SystemCallError or IOError if something went wrong during reading of the PID file.
Start the daemon and wait until it can be pinged.
Raises:
Stop the daemon and wait until it has exited.
Raises: