Class | DaemonController |
In: |
lib/daemon_controller.rb
lib/daemon_controller/lock_file.rb lib/daemon_controller/version.rb |
Parent: | Object |
daemon_controller, library for robust daemon management Copyright (c) 2010, 2011, 2012 Phusion
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
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")) |
MAJOR | = | 1 |
MINOR | = | 0 |
TINY | = | 0 |
VERSION_STRING | = | "#{MAJOR}.#{MINOR}.#{TINY}" |
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 an Array which specifies the socket address of the daemon. It must be in one of the following forms:
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 Errno::ECONNRESET, Errno::EINVAL or 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 it. 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: