Git Product home page Git Product logo

fallen's Introduction

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:

  • daemonize!: detaches the process and keep running it on background;
  • chdir!: changes the current working directory of the process (useful for log and pid files);
  • pid_file: allows to indicate a file path where the daemon PID will be stored; could be either an absolute path or a relative path to the current working directory (see chdir!);
  • stdout, stderr & stdin: redirects the process STDOUT, STDERR and STDIN to either an absolute or relative file path; note that when a process is daemonized by default all these streams are redirected to /dev/null.

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.

fallen's People

Contributors

elcuervo avatar fsaravia avatar imton avatar inkel avatar kandalf avatar phortx avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.