From 5f5d8b12cec3d4c63a34a7f0fb0b0202a4c26244 Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Mon, 30 May 2011 19:19:16 +0000 Subject: Passing of startup options work --- CHANGELOG | 6 ++++++ TODO | 1 - bin/perldaemon | 7 ++++--- conf/perldaemon.conf | 2 +- lib/PerlDaemon/PerlDaemon.pl | 24 ++++++++++++++++++++---- 5 files changed, 31 insertions(+), 9 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 166961d..02116db 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,9 @@ +Mo 30. Mai 21:10:53 CEST 2011 +* Added passing of startup options. E.g. + ./control start daemon.daemonize=no daemon.loopinterval=10 + starts perldaemon in foreground w/ a loopinterval of 10 seconds. + It's possible to overwrite all defaults specified in perldaemon.conf + Di 24. Mai 08:46:09 CEST 2011 * Renamed modules config options daemon.modulesruninterval -> daemon.modules.runiterval diff --git a/TODO b/TODO index 0a63fa6..3648fbe 100644 --- a/TODO +++ b/TODO @@ -1,3 +1,2 @@ * Complete Time::HiRes job scheduler * Add error handling (catch eval if dynamic loadable module errors) -* Allow command line arguments diff --git a/bin/perldaemon b/bin/perldaemon index 0558006..d3991bd 100755 --- a/bin/perldaemon +++ b/bin/perldaemon @@ -1,4 +1,4 @@ -#!/usr/bin/env bash +#!/usr/bin/env bash declare -r ARG=$1 declare -a LIBPATHS=(./lib ../lib /lib /usr/lib /usr/local/lib /opt/lib) @@ -17,7 +17,7 @@ fi start () { echo Starting daemon now... - perl -I$LIBDIR $LIBDIR/PerlDaemon/PerlDaemon.pl ./conf/perldaemon.conf + perl -I$LIBDIR $LIBDIR/PerlDaemon/PerlDaemon.pl config=./conf/perldaemon.conf $@ } stop () { @@ -36,7 +36,8 @@ logrotate () { case $ARG in start) - start + shift + start $@ ;; stop) diff --git a/conf/perldaemon.conf b/conf/perldaemon.conf index c0071a1..aa5464f 100644 --- a/conf/perldaemon.conf +++ b/conf/perldaemon.conf @@ -6,4 +6,4 @@ daemon.pidfile = ./run/perldaemon.pid daemon.logfile = ./log/perldaemon.log daemon.modules.dir = ./lib/PerlDaemonModules daemon.modules.runinterval = 3 -daemon.daemonize = no +daemon.daemonize = yes diff --git a/lib/PerlDaemon/PerlDaemon.pl b/lib/PerlDaemon/PerlDaemon.pl index 1bee431..58e9755 100644 --- a/lib/PerlDaemon/PerlDaemon.pl +++ b/lib/PerlDaemon/PerlDaemon.pl @@ -62,10 +62,11 @@ sub writepid ($) { } -sub readconf ($) { - my $conffile = shift; +sub readconf ($%) { + my ($confile, %opts) = @_; - open my $fh, $conffile or die "Can't read $conffile\n"; + open my $fh, $confile or + die "Can't read config file $confile (specify using config=filepath)\n"; my %conf; while (<$fh>) { @@ -88,6 +89,7 @@ sub readconf ($) { die "$msg $key\n" unless exists $conf{$key}; } + @conf{keys %opts} = values %opts; return \%conf; } @@ -153,7 +155,21 @@ sub daemonloop ($) { } } -my $conf = readconf shift; +sub getopts (@) { + my %opts; + + for my $opt (@_) { + next unless $opt =~ /=/; + my ($key, $val) = split '=', $opt, 2; + $opts{$key} = $val; + } + + return %opts; +} + +my %opts = getopts @ARGV; + +my $conf = readconf $opts{config}, %opts; $conf->{logger} = PerlDaemon::Logger->new($conf); prestartup $conf; -- cgit v1.2.3