#!/usr/bin/perl
use
5.010;
our
$VERSION
=
'0.05'
;
my
%opts
= (
log_stderr_size
=> 10*1024*1024,
log_stderr_histories
=> 10,
pid_dir
=>
"/var/run"
,
);
Getopt::Long::Configure(
"no_permute"
);
GetOptions(
"--help"
=> \
$opts
{help},
"--name=s"
=> \
$opts
{name},
"--single-instance"
=> \
$opts
{single_instance},
"--log-stderr-dir=s"
=> \
$opts
{log_stderr_dir},
"--log-stderr-size=i"
=> \
$opts
{log_stderr_size},
"--log-stderr-histories=i"
=> \
$opts
{log_stderr_histories},
"--log-stderr-period=s"
=> \
$opts
{log_stderr_period},
"--timeout=i"
=> \
$opts
{timeout},
"--pid-dir=s"
=> \
$opts
{pid_dir},
"--on-multiple-instance=s"
=> \
$opts
{on_multiple_instance},
);
if
(
$opts
{help} || !
@ARGV
) {
print
<<_;
Run child process and govern its various aspects
Usage: $0 [OPTS] -- [COMMAND ...]
Options:
--name=S Set process name.
--single-instance Prevent running multiple instances simultaneously.
--log-stderr-dir=S Enable logging of stderr and set log directory.
--log-stderr-size=N Set log file size limit, in bytes, default 10MB.
--log-stderr-histories=N Set number of rotated log files to keep, default 10.
--log-stderr-period=S Enable periodic rotation (daily/monthly/yearly).
--timeout=N Set execution time limit, in seconds.
--pid-dir=S Directory to put PID file, if --single-instance set.
--on-multiple-instance=S Can be set to 'exit' to silently exit when another
instance is already running.
_
exit
0;
}
my
%ga
= (
command
=> \
@ARGV
,
name
=>
$opts
{name},
single_instance
=>
$opts
{single_instance},
pid_dir
=>
$opts
{pid_dir},
timeout
=>
$opts
{timeout},
on_multiple_instance
=>
$opts
{on_multiple_instance},
);
if
(
$opts
{log_stderr_dir}) {
$ga
{log_stderr} = {
dir
=>
$opts
{log_stderr_dir},
size
=>
$opts
{log_stderr_size},
histories
=>
$opts
{log_stderr_histories},
period
=>
$opts
{log_stderr_period},
};
}
Process::Govern::govern_process(
%ga
);
1;