4 use POSIX qw/setsid setuid setgid/;
7 my ($nodaemon, $verbose, $pidfile, $logfile, $user, $group, $uid, $gid);
8 $pidfile = '/var/run/runcheckdir.pid';
9 $logfile = '/var/log/runcheckdir.log';
12 "nodaemon" => \$nodaemon,
13 "verbose" => \$verbose,
14 "pidfile=s" => \$pidfile,
15 "logfile=s" => \$logfile,
20 my $dir = abs_path(shift);
22 print "No directory specified\n";
26 print "$dir is not a directory\n";
30 $uid = (getpwnam($user))[2] if $user;
31 $gid = (getpwnam($group))[3] if $group;
40 if (open STDOUT, ">>$logfile") {
41 open STDERR, ">>$logfile";
42 chown $uid, $gid, $logfile;
44 print "WARNING: Could not open logfile. You will get NO error output.\n";
45 open STDOUT, ">/dev/null";
46 open STDERR, ">/dev/null";
48 open STDIN, "/dev/null";
50 open PID, ">$pidfile" or warn "Could not write PID file\n";
53 chown $uid, $gid, $pidfile;
56 print "Daemon started at ",scalar gmtime(),"\n";
59 daemonize unless $nodaemon;
67 opendir(CHECKS, $dir);
68 while (my $d = readdir(CHECKS)) {
69 next if (! -d "$dir/$d" || $d eq '.' || $d eq '..');
70 unless (-f "$dir/$d/check") {
71 print "No check script in $dir/$d\n";
74 print "Running check $dir/$d: ";
75 system("runcheck $dir/$d");
76 my $exitstatus = $? >> 8;