mirror of
https://github.com/php/systems.git
synced 2026-03-24 07:42:12 +01:00
- make runone exit with the exit code of the executed program - log stdout/stderr of all programs to /var/log/php-cron-box.log - log failed executions with error code to /var/log/php-cron-box.fail - don't swallow errors from named
32 lines
631 B
Perl
Executable File
32 lines
631 B
Perl
Executable File
#!/usr/bin/perl -w
|
|
use strict;
|
|
|
|
die "usage: $0 lockfile command [arg ...]\n"
|
|
unless @ARGV >= 2;
|
|
|
|
my $lockfile = shift;
|
|
|
|
if (-e $lockfile) {
|
|
open FILE, "<$lockfile"
|
|
or die "unable to open file '$lockfile' for reading: $!\n";
|
|
my $pid = <FILE>;
|
|
if (kill 0, $pid) {
|
|
# only warn when the lock is more than an hour old
|
|
print "already running, pid $pid\n"
|
|
if (stat _)[9] < time() - 3600;
|
|
exit(99);
|
|
}
|
|
close FILE;
|
|
}
|
|
|
|
open FILE, ">$lockfile"
|
|
or die "unable to open file '$lockfile' for writing: $!\n";
|
|
print FILE $$;
|
|
close FILE;
|
|
|
|
system @ARGV;
|
|
my $err = $? >> 8; # perl wtf
|
|
unlink $lockfile;
|
|
|
|
exit($err);
|