Home

Awesome

Fallen

A simpler daemon library for Ruby processes.

Usage

require "fallen"

module Azazel
  extend Fallen
  
  def self.run
    while running?
      puts "Time is on my side... Yes it is..."
      sleep 666
    end
  end
end

Azazel.start!

This will print Time is on my side... Yes it is.. every 666 seconds on STDOUT. You can stop the daemon by pressing CTRL+c.

Control your daemon

Fallen accepts the following methods:

For example, the previous example could have the following lines before Azazel.start! to store the PID and log to a file:

Azazel.pid_file "/var/run/azazel.pid"
Azazel.stdout "/var/log/azazel.log"
Azazel.daemonize!
Azazel.start!

CLI support

Fallen supports command line parameters, by default using the clap gem. In order to enable command line support you need to do the following:

require "fallen"
require "fallen/cli"

module Azazel
  extend Fallen
  extend Fallen::CLI
  
  # ...
  
  def usage
    puts "..." # Your usage message
    # Default Fallen usage options
    puts fallen_usage
  end
end

case Clap.run(ARGV, Azazel.cli).first
when "start"
  Azazel.start!
when "stop"
  Azazel.stop!
else
  Azazel.usage
end

Azazel.usage will print the following:

Fallen introduced command line arguments:

  -D    Daemonize this process
  -C    Change directory.
  -P    Path to PID file. Only used in daemonized process.
  -out  Path to redirect STDOUT.
  -err  Path to redirect STDERR.
  -in   Path to redirect STDIN.

License

See the UNLICENSE file included with this gem distribution.