blob: a149f37bf9bf423500960a6a14639290cbd616d2 (
plain)
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
|
TOC:
01. HELLO WORLD
02. QUICK START GUIDE
03. CONFIGURATION
04. HIGH RESOLUTION SCHEDULING TIME
05. WRITING YOUR OWN MODULES
01. HELLO WORLD
PerlDaemon is a minimal daemon for Linux and other UNIX a like operating system
programmed in Perl. It can be extended to fit any task...
It supports:
* Automatic daemonizing
* Logging and logrotate support (SIGHUP)
* Clean shutdown support (SIGTERM)
* Pidfile support (incl. check on startup)
* Easy to configure
* Easy to extend (writing your own modules within PerlDaemonModules::)
The perldaemon website is located at http://perldaemon.buetow.org
02. QUICK START GUIDE:
# Starting
./bin/perldaemon start (or shortcut ./control start)
# Stopping
./bin/perldaemon stop (or shortcut ./control stop)
# Alternatively: Starting in foreground
./bin/perldaemon start daemon.daemonize=no (or shortcut ./control foreground)
To stop the daemon then just hit Ctrl+C. To see more available startup
options enter "./control" without any argument.
03. CONFIGURATION
Configurations can be set in ./conf/perldaemon.conf. If you want to change
a property only once it's possible to specify it on command line. All
available properties can be seen using ./control keys (caution: this list
in this document may be outdated, please run ./control keys by yourself too!)
pb@titania:~/svn/utils/perldaemon/trunk$ ./control keys
# Path to the logfile
daemon.logfile=./log/perldaemon.log
# The amount of seconds until the next event look takes place
daemon.interval=2
# Path to the modules dir
daemon.modules.dir=./lib/PerlDaemonModules
# Specifies either the daemon should run in daemon or foreground mode
daemon.daemonize=yes
# Path to the pidfile
daemon.pidfile=./run/perldaemon.pid
# Path to the alive file (is touched every interval seconds, usable to monitor)
daemon.alivefile=./run/perldaemon.alive
# Specifies the working directory
daemon.wd=./
So lets start the daemon using as its loop interval 10 seconds:
$ ./control keys | grep daemon.interval
daemon.interval=1
$ ./control keys daemon.interval=10 | grep daemon.interval
daemon.interval=10
$ ./control start daemon.interval=10; sleep 10; tail -n 2 log/perldaemon.log
Starting daemon now...
Mon Jun 13 11:29:27 2011 (PID 2838): Triggering PerlDaemonModules::ExampleModule
(last triggered before 10.002106s; carry: 7.002106s; wanted interval: 3s)
Mon Jun 13 11:29:27 2011 (PID 2838): ExampleModule Test 2
$ ./control stop
Stopping daemon now...
If you want to change that property forever either edit perldaemon.conf or do this:
$ ./control keys daemon.interval=10 > new.conf; mv new.conf conf/perldaemon.conf
04. HIGH RESOLUTION SCHEDULING TIME
PerlDaemon uses Time::HiRes to make sure that all the events run in correct
intervals. Each loop run a time carry value is recorded and added to the next
loop run in order to catch up lost time (in future there will be an option to
turn that off and on).
05. WRITING YOUR OWN MODULES:
cd ./lib/PerlDaemonModules/
cp ExampleModule.pm YourModule.pm
vi YourModule.pm
cd -
./bin/perldaemon restart (or shortcurt ./control restart)
Now watch ./log/perldaemon.log to see everything runs fine. It is a good
practise to test your modules in 'foreground mode' (see above how to do
that).
BTW: You can install as many modules in parallel as wished. But they are run
in sequential order (in future they can also run in parallel using several
threads or processes).
|