Copyright (C) 2004-2018 Jürgen "eTM" Mangler email@example.com
Daemonite is freely distributable according to the terms of the GNU Lesser General Public License 3.0 (see the file 'COPYING').
This code is distributed without any warranty. See the file 'COPYING' for details.
Deamonite is just syntactic sugar around Process.daemon and argparse, which are part of ruby. And it gives you a simple loop. And it only works on *nix, because it runs 'ps ax' (that rhymes). I know, thats clumsy and I'm a lazy git. Please contribute a better solution if you have to.
After I reused similar code in about 20 projects I had make it into a gem. Sorry. Probably much better code out there does the same, but I am too lazy to search for it. Sorry.
Its fairly simple for now:
. do |opts| opts['bla'] run do |opts| p opts sleep 1 end end.loop!
Everything inside the #new block is executed once. Everything inside the #run block is executed periodically. So make sure to include sleep to not bog down your CPU. Or not - i.e. listen to network connections. #loop! finally invokes the contents of #run continuously.
In order to override or provide your own options:
Also be aware that a json configuration file $PROGRAM_NAME.sub /.rb$/, '.conf' is automatically read, if it exists.
Usage - Alternative
daemon = .(opts) daemon.run do |opts| p opts sleep 1 end daemon.loop!
- An example how to integrate with EventMachine (replace the #loop!).