Giter VIP home page Giter VIP logo

demon's Introduction

NAME

demon.rb - the ruby daemon library you've been waiting for

SYNOPSIS

a small, flexible, powerful ruby daemon library

DESCRIPTION

demon.rb aims to make it simple to construct extremely well behaved daemon programs in no time.

it supports both a DSL and object oriented interface to sound unix daemon code. unlike some daemon libraries, it makes zero assumptions about how you want to organize your code - although some sane defaults exist to help you along if you don't what to think about this at all.

INSTALL

gem 'demon'

USAGE

simple usage is simple...

#! /usr/bin/env ruby

# file: a.rb

Demon do
  loop do
    stuff_as_a_daemon
  end
end
  ./a.rb help 
---
start: start in daemon mode
run: run in the foreground, but otherwise like a daemon
stop: stop any currently running daemon
restart: restart any currently running daemon, or start a new one
pid: print the pid of the running daemon, iff any
ping: ensure a daemon is running, start one iff not
signal: hit the daemon, if any, with SIGUSR2
tail: tail -F all auxillary files (lock files, logs, etc)
fuser: report the fuser of any auxillary files (lock files, logs, etc)
log: display the location of the log file
root: display the location of the root daemon dir (lock files, logs, etc)
modes: print all modes, even those without "help"
help: this message

a few things to notice about the above daemon:

  • daemons are expected to run for a long time. demon.rb will run the supplied block over and over (aka. it is an implied loop)
  • if the supplied block blows up the error will be logged, and the block retried. we assume you mean to keep your daemon up.
  • the actual script being run must be know to demon.rb. you can let it know by passing a block, or supplying the location of the script as the first arugment
Demon __FILE__ do
  # stuff
end

of course, you can have much more find grained control over your daemons

  class MyProgram 
    def run
      loop do
        teh_awesome
      end
    end

    def daemonize!
      program = self

      demon.start{ program.run }
    end

    def pid 
      demon.run(:pid)
    end

    def demon
      @demon ||= Demon.new(__FILE__, :root => '~/.my_progarm/')
    end
  end

demon's People

Contributors

ahoward avatar

Stargazers

Angus H. avatar

Watchers

Erik Berlin avatar  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.