#!/usr/bin/perl use feature ":5.10"; use warnings; use strict; use threads; use Proc::Daemon; ### Global Variables use constant false => 0; use constant true => 1; my $app = $0; my $continue = true; $SIG{TERM} = sub { $continue = false }; # Directory Server Agent (DSA) info my @ListOfDSAs = ( { name => "Myself (inbound)", host => "ldap.myco.ca", base => "ou=mydir,o=myco,c=ca", }, { name => "Company 2", host => "ldap.comp2.ca", base => "ou=their-dir,o=comp2,c=ca", } ); ### Subroutines sub checkConnections { # runs every 5 minutes my (@DSAs, $logfile) = @_; # Code to ldapsearch threads->detach(); } sub validateRevocationLists { # runs every hour on minue xx:55 my (@DSAs, $logfile) = @_; # Code to validate CRLs haven't expired, etc threads->detach(); } ### Main program Proc::Daemon::Init; while ($continue) { my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time); # Question 1: Queues?? if ($min % 5 == 0 || $min == 0) { threads->create(&checkConnections, @ListOfDSAs, "/var/connect.log"); } if ($min % 55 == 0) { threads->create(&validateRevocationLists, @ListOfDSAs, "/var/RLs.log"); } sleep 60; # Question 2: Safer/better way to prevent multiple threads being started for same check in one matching minute? } # TERM RECEIVED exit 0; __END__