summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CHANGELOG8
-rw-r--r--README83
-rw-r--r--VERSION2
-rw-r--r--WHISHLIST2
-rwxr-xr-xbin/perldaemon10
-rw-r--r--conf/perldaemon.conf33
-rw-r--r--lib/PerlDaemon/PerlDaemon.pl30
7 files changed, 151 insertions, 17 deletions
diff --git a/CHANGELOG b/CHANGELOG
index 87ee912..3904e2a 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -1,6 +1,14 @@
+Mo 13. Jun 11:41:41 CEST 2011
+* Released PerlDaemon v1.2
+
+Mo 13. Jun 11:40:49 CEST 2011
+* Added documentation (README file)
+* Added './control keys' which shows all the available properties
+
Mo 6. Jun 09:03:57 CEST 2011
* Added './control foreground' startup option
* Added correct time carrying
+* Renamed TODO into WHISHLIST
Do 2. Jun 11:09:25 CEST 2011
* Added module load error handling
diff --git a/README b/README
index d63652c..1315c4d 100644
--- a/README
+++ b/README
@@ -1,4 +1,11 @@
-HELLO WORLD
+TOC:
+01. HELLO WORLD
+02. QUICK START GUIDE
+03. CONFIGURATION
+04. HIGH RESOLUTION SCHEDULING TIME
+05. WRITING YOUR OWN MODULES
+
+01 - HELLO WORLD
RunModuleemon is a minimal linux/unix daemon programmed in Perl.
It can be extended to fit any task...
@@ -13,19 +20,87 @@ It supports:
The perldaemon website is located at http://perldaemon.buetow.org
-QUICK START GUIDE:
+02. QUICK START GUIDE:
# Starting
./bin/perldaemon start (or shortcut ./control start)
+
# Stopping
./bin/perldaemon stop (or shortcut ./control stop)
-# Writing your own modules:
+# 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 your own 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.loopinterval=1
+
+# 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
+
+# Each module should run every runinterval seconds
+daemon.modules.runinterval=3
+
+# Path to the alive file (is touched every loopinterval 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.loopinterval
+daemon.loopinterval=1
+$ ./control keys daemon.loopinterval=10 | grep daemon.loopinterval
+daemon.loopinterval=10
+$ ./control start daemon.loopinterval=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
+Starting daemon now...
+$ ./control stop
+Stopping daemon now...
+
+If you want to change that property forever either edit perldaemon.conf or do this:
+$ ./control keys daemon.loopinterval=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)
-Btw: You can install as many modules in parallel as whished.
+Btw: You can install as many modules in parallel as whished. But they are run
+in sequential order (in future they can also run in parallel using several
+threads or processes).
+
diff --git a/VERSION b/VERSION
index 222615e..78f011a 100644
--- a/VERSION
+++ b/VERSION
@@ -1 +1 @@
-PerlDaemon v1.1
+PerlDaemon v1.2
diff --git a/WHISHLIST b/WHISHLIST
index 3d9a157..f628b43 100644
--- a/WHISHLIST
+++ b/WHISHLIST
@@ -1,2 +1,2 @@
-* Add documentation
+* Add parallel module execution support
* Add special SIGNAL handling (e.g. trigger modules)
diff --git a/bin/perldaemon b/bin/perldaemon
index feaa68a..11c1a7e 100755
--- a/bin/perldaemon
+++ b/bin/perldaemon
@@ -35,6 +35,10 @@ logrotate () {
kill -HUP $(cat ./run/perldaemon.pid)
}
+keys () {
+ perl -I$LIBDIR $LIBDIR/PerlDaemon/PerlDaemon.pl config=./conf/perldaemon.conf keys=1 $@
+}
+
case $ARG in
start)
shift
@@ -59,8 +63,12 @@ case $ARG in
start daemon.daemonize=no $@
;;
+ keys)
+ keys $@
+ ;;
+
*)
- echo "Usage: $0 <start|stop|restart|logrotate|foreground>"
+ echo "Usage: $0 <start|stop|restart|logrotate|foreground|keys> [key1=val1 [[key2=val2] ...]]"
exit 1
;;
esac
diff --git a/conf/perldaemon.conf b/conf/perldaemon.conf
index aa5464f..9a6f6b4 100644
--- a/conf/perldaemon.conf
+++ b/conf/perldaemon.conf
@@ -1,9 +1,24 @@
-# Minimal Perl Daemon Sample Configuration
-daemon.wd = ./
-daemon.loopinterval = 1
-daemon.alivefile = ./run/perldaemon.alive
-daemon.pidfile = ./run/perldaemon.pid
-daemon.logfile = ./log/perldaemon.log
-daemon.modules.dir = ./lib/PerlDaemonModules
-daemon.modules.runinterval = 3
-daemon.daemonize = yes
+# Path to the logfile
+daemon.logfile=./log/perldaemon.log
+
+# The amount of seconds until the next event look takes place
+daemon.loopinterval=1
+
+# 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
+
+# Each module should run every runinterval seconds
+daemon.modules.runinterval=3
+
+# Path to the alive file (is touched every loopinterval seconds, usable to monitor)
+daemon.alivefile=./run/perldaemon.alive
+
+# Specifies the working directory
+daemon.wd=./
+
diff --git a/lib/PerlDaemon/PerlDaemon.pl b/lib/PerlDaemon/PerlDaemon.pl
index bb1d7c8..1c3d331 100644
--- a/lib/PerlDaemon/PerlDaemon.pl
+++ b/lib/PerlDaemon/PerlDaemon.pl
@@ -1,4 +1,5 @@
#!/usr/bin/perl
+
# PerlDaemon (c) 2010, 2011, Dipl.-Inform. (FH) Paul Buetow (http://perldaemon.buetow.org)
use strict;
@@ -64,12 +65,18 @@ sub writepid ($) {
sub readconf ($%) {
my ($confile, %opts) = @_;
+ my $desc;
open my $fh, $confile or
die "Can't read config file $confile (specify using config=filepath)\n";
+
my %conf;
-
while (<$fh>) {
+ if (/^#(.*)/) {
+ $desc = $1;
+ next;
+ }
+
next if /^[\t\w]+#/;
s/#.*//;
@@ -77,6 +84,11 @@ sub readconf ($%) {
next unless defined $val;
$conf{$key} = $val;
+
+ if (defined $desc) {
+ $conf{"$key.desc"} = $desc;
+ $desc = undef;
+ }
}
close $fh;
@@ -164,6 +176,16 @@ sub daemonloop ($) {
}
}
+sub showkeys ($) {
+ my $conf = shift;
+ for my $key (grep !/(^keys$)|(^config$)|(\.desc$)/, keys %$conf) {
+ print '#' . (exists $conf->{"$key.desc"}
+ ? $conf->{"$key.desc"}
+ : ' Undocumented property');
+ print "\n$key=$conf->{$key}\n\n";
+ }
+}
+
sub getopts (@) {
my %opts;
@@ -179,6 +201,12 @@ sub getopts (@) {
my %opts = getopts @ARGV;
my $conf = readconf $opts{config}, %opts;
+
+if (exists $conf->{keys}) {
+ showkeys($conf);
+ exit 0;
+}
+
$conf->{logger} = PerlDaemon::Logger->new($conf);
prestartup $conf;