lib/process/daemon.rb in process-daemon-0.3.0 vs lib/process/daemon.rb in process-daemon-0.5.0
- old
+ new
@@ -128,32 +128,48 @@
def shutdown
# Interrupt all children processes, preferably to stop them so that they are not left behind.
Process.kill(0, :INT)
end
- # Helper methods for static daemon instance
+ def run
+ startup
+
+ trap("INT") do
+ shutdown
+ end
+ end
+ # A shared instance of the daemon.
def self.instance
@instance ||= self.new
end
- # Main entry point for command line:
- def self.daemonize(argv = ARGV)
- Controller.daemonize(instance, argv)
+ # The process controller, responsible for managing the daemon process start, stop, restart, etc.
+ def self.controller(options = {})
+ @controller ||= Controller.new(instance, options)
end
- # Start the daemon instance:
+ # The main entry point for daemonized scripts.
+ def self.daemonize(*args)
+ # Wish Ruby 2.0 kwargs were backported to 1.9.3... oh well:
+ options = (args.last === Hash) ? args.pop : {}
+ argv = (args.last === Array) ? args.pop : ARGV
+
+ controller(options).daemonize(argv)
+ end
+
+ # Start the daemon instance.
def self.start
- Controller.start(instance)
+ controller.start
end
- # Stop the daemon instance:
+ # Stop the daemon instance.
def self.stop
- Controller.stop(instance)
+ controller.stop
end
- # Get the status of the daemon instance, `:stopped`, `:running` or `:unknown`.
+ # Check if the daemon is runnning or not.
def self.status
- ProcessFile.status(instance)
+ controller.status
end
end
end