Date sent: Fri, 13 Jul 2007 08:53:56 +0200 From: "Gregory Machin" <[EMAIL PROTECTED]> > What I want to do is to write a service monitoring daemon, where the > core or body of the script parses a directory, that contains the > config / perl scripts, and is loaded into the core script, if one of > the scripts has an unrecoverable error, it's dumped, thus preserving > the daemon, but more importantly it allows for more inflexibility, as > each script can be tailored to suite that particular service, without > bloating the core script, obviously keeping all good reusable code in > the core script... The script needs to have as few dependencies as > posible as it's going to be run on a custom os thats very minimal ... > and not only will in need to monitor other daemons but also the status > on network interfaces and there connectivity, monitor daemons log > files can carry out actions based on the content, thus also trying to > do preventative maintenance .. > > Quite an under taking for a nubee, but it'll help fast track my perl > skills i'm sure ..
I'm doing something similar. The way it works is each of the scriptlets looks somewhat like this: ## AutoPost.uix package UIX::AutoPost; my $config = $main::Defaults->{AutoPost}; # the daemon loads an INI file into a global HoH named $Defaults my $hostname = $config->{'hostname'} || die "No FTP server hostname to fetch the XML files from specified!\n"; my $username = $config->{'username'} || die "No username specified!\n"; my $password = $config->{'password'} || die "No password specified!\n"; my $remote_dir = $config->{'remote_dir'} || ''; ... use strict; use ... sub something { ... }; sub other{ ... something(some, params); ... } ... some code that initializes the scriptlet ... if (whatever) return (); # the scriptlet found out that due to the settings it doesn't # need to be scheduled. } else { return ($the_interval_in_minutes, \&the_subroutine_to_call) } __END__ and then in the daemon there's something like ... if (! opendir DIR, $scriptdir) { Log("Cannot open script directory!\nRun UpdateIndexer.exe - dir=directory!"); Win32::Daemon::StopService(); exit(1); } Log("Started reading tasks from $scriptdir"); my $script; while (defined($script = readdir DIR)) { next unless $script =~ /\.uix$/i; my $name = $script; $name =~ s/\.uix$//i; if ($Defaults->{$name}->{skip}) { LogNT("Task '$name' is skipped!"); next; } LogNT("Reading task '$name'"); my ($delay, $sub) = do "<$scriptdir\\$script"; if ($@) { Log("\tThe script in $scriptdir\\$script contains errors :\n\t\t$@"); Win32::Daemon::StopService(); exit(1); } if (! defined $delay) { Log(" The script doesn't want to be scheduled."); } else { push @tasks, [$delay, $sub]; } } closedir DIR; ... HTH, Jenda ===== [EMAIL PROTECTED] === http://Jenda.Krynicky.cz ===== When it comes to wine, women and song, wizards are allowed to get drunk and croon as much as they like. -- Terry Pratchett in Sourcery -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/