-
Notifications
You must be signed in to change notification settings - Fork 27
/
HOWTO_daemons.txt
50 lines (34 loc) · 2.04 KB
/
HOWTO_daemons.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
There is small, simple framework inside NUcore for creating and controlling daemons that have the same environment as
the web application. This is useful for monitoring NUcore's database outside of the running web application while using
the application's classes. The daemons framework is based on the daemons gem (http://daemons.rubyforge.org/)
Creating daemons
----------------
All daemons belong in lib/daemons. In most cases all you need is:
require File.expand_path('base', File.dirname(__FILE__))
Daemons::Base.new('daemon_name').start do
# the work your daemon needs to do
end
The daemon_name argument can be anything. It's simply what you want to call your daemon. The filename of your source
should match what you give the constructor. By default a sane runtime is given to the daemon. If you want to tweak
the daemon's runtime see Daemons::Base#daemon_opts.
Controlling daemons
-------------------
There are rake tasks for controlling daemons:
* daemon:start[daemon_name]
* daemon:stop[daemon_name]
* daemon:debug[daemon_name]
In every case the daemon_name argument should match the filename of your daemon. For example, `rake daemon:start[mydaemon]`
would fire up the daemon at lib/daemons/mydaemon.rb. Note that the debug task will start the daemon in the foreground,
making it easier to diagnose problems by dumping output to the console.
Monitoring daemons
------------------
The default configuration for daemons includes a monitoring process that will restart failed daemons. In addition daemon
output is sent to log/<daemon_name>.output and log/<daemon_name>.log. Since a daemon is a stand-alone process you can
see it in your system's `ps` output by grepping for <daemon_name>.
Skip Monitoring
-------------------
If you wish to forego monitoring, for example if you are using a separate monitoring
system such as Eye, you can start up the daemon directly with the --no-monitor option:
ruby lib/daemons/recurring_tasks.rb start -- --no-monitor
(the additional -- is required)
ruby lib/daemons/recurring_tasks.rb stop