zmcontrol.pl: pod2usage (draft) + minor readability improvements.
Looks like "zmcontrol.pl" was based upon "zmfilter.pl" so it inherited commented description of the latter. Therefore "zmcontrol.pl" needs a description...
This commit is contained in:
parent
411b518b14
commit
fba085a1c5
|
@ -20,16 +20,39 @@
|
||||||
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||||
#
|
#
|
||||||
# ==========================================================================
|
# ==========================================================================
|
||||||
#
|
|
||||||
# This script continuously monitors the recorded events for the given
|
=head1 NAME
|
||||||
# monitor and applies any filters which would delete and/or upload
|
|
||||||
# matching events
|
zmcontrol.pl - ZoneMinder control script
|
||||||
#
|
|
||||||
|
=head1 SYNOPSIS
|
||||||
|
|
||||||
|
zmcontrol.pl --id {monitor_id} --command={command} [various options]
|
||||||
|
|
||||||
|
=head1 DESCRIPTION
|
||||||
|
|
||||||
|
FIXME FIXME
|
||||||
|
|
||||||
|
=head1 OPTIONS
|
||||||
|
|
||||||
|
--autostop -
|
||||||
|
--xcoord [ arg ] - X-coord
|
||||||
|
--ycoord [ arg ] - Y-coord
|
||||||
|
--speed [ arg ] - Speed
|
||||||
|
--step [ arg ] -
|
||||||
|
--panspeed [ arg ] -
|
||||||
|
--panstep [ arg ] -
|
||||||
|
--tiltspeed [ arg ] -
|
||||||
|
--tiltstep [ arg ] -
|
||||||
|
--preset [ arg ] -
|
||||||
|
|
||||||
|
=cut
|
||||||
use strict;
|
use strict;
|
||||||
|
|
||||||
@EXTRA_PERL_LIB@
|
@EXTRA_PERL_LIB@
|
||||||
use ZoneMinder;
|
use ZoneMinder;
|
||||||
use Getopt::Long;
|
use Getopt::Long;
|
||||||
|
use autouse 'Pod::Usage'=>qw(pod2usage);
|
||||||
use POSIX qw/strftime EPIPE/;
|
use POSIX qw/strftime EPIPE/;
|
||||||
use Socket;
|
use Socket;
|
||||||
#use Data::Dumper;
|
#use Data::Dumper;
|
||||||
|
@ -44,14 +67,6 @@ $ENV{PATH} = '/bin:/usr/bin';
|
||||||
$ENV{SHELL} = '/bin/sh' if exists $ENV{SHELL};
|
$ENV{SHELL} = '/bin/sh' if exists $ENV{SHELL};
|
||||||
delete @ENV{qw(IFS CDPATH ENV BASH_ENV)};
|
delete @ENV{qw(IFS CDPATH ENV BASH_ENV)};
|
||||||
|
|
||||||
sub Usage
|
|
||||||
{
|
|
||||||
print( "
|
|
||||||
Usage: zmcontrol.pl --id <monitor_id> --command=<command> <various options>
|
|
||||||
");
|
|
||||||
exit();
|
|
||||||
}
|
|
||||||
|
|
||||||
logInit();
|
logInit();
|
||||||
|
|
||||||
my $arg_string = join( " ", @ARGV );
|
my $arg_string = join( " ", @ARGV );
|
||||||
|
@ -59,29 +74,25 @@ my $arg_string = join( " ", @ARGV );
|
||||||
my $id;
|
my $id;
|
||||||
my %options;
|
my %options;
|
||||||
|
|
||||||
if ( !GetOptions(
|
GetOptions(
|
||||||
'id=i'=>\$id,
|
'id=i' =>\$id,
|
||||||
'command=s'=>\$options{command},
|
'command=s' =>\$options{command},
|
||||||
'xcoord=i'=>\$options{xcoord},
|
'xcoord=i' =>\$options{xcoord},
|
||||||
'ycoord=i'=>\$options{ycoord},
|
'ycoord=i' =>\$options{ycoord},
|
||||||
'speed=i'=>\$options{speed},
|
'speed=i' =>\$options{speed},
|
||||||
'step=i'=>\$options{step},
|
'step=i' =>\$options{step},
|
||||||
'panspeed=i'=>\$options{panspeed},
|
'panspeed=i' =>\$options{panspeed},
|
||||||
'tiltspeed=i'=>\$options{tiltspeed},
|
'tiltspeed=i' =>\$options{tiltspeed},
|
||||||
'panstep=i'=>\$options{panstep},
|
'panstep=i' =>\$options{panstep},
|
||||||
'tiltstep=i'=>\$options{tiltstep},
|
'tiltstep=i' =>\$options{tiltstep},
|
||||||
'preset=i'=>\$options{preset},
|
'preset=i' =>\$options{preset},
|
||||||
'autostop'=>\$options{autostop},
|
'autostop' =>\$options{autostop},
|
||||||
)
|
) or pod2usage(-exitstatus => -1);
|
||||||
)
|
|
||||||
{
|
|
||||||
Usage();
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( !$id || !$options{command} )
|
if ( !$id || !$options{command} )
|
||||||
{
|
{
|
||||||
print( STDERR "Please give a valid monitor id and command\n" );
|
print( STDERR "Please give a valid monitor id and command\n" );
|
||||||
Usage();
|
pod2usage(-exitstatus => -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
( $id ) = $id =~ /^(\w+)$/;
|
( $id ) = $id =~ /^(\w+)$/;
|
||||||
|
@ -90,13 +101,14 @@ Debug( $arg_string );
|
||||||
|
|
||||||
my $sock_file = $Config{ZM_PATH_SOCKS}.'/zmcontrol-'.$id.'.sock';
|
my $sock_file = $Config{ZM_PATH_SOCKS}.'/zmcontrol-'.$id.'.sock';
|
||||||
|
|
||||||
socket( CLIENT, PF_UNIX, SOCK_STREAM, 0 ) or Fatal( "Can't open socket: $!" );
|
socket( CLIENT, PF_UNIX, SOCK_STREAM, 0 )
|
||||||
|
or Fatal( "Can't open socket: $!" );
|
||||||
|
|
||||||
my $saddr = sockaddr_un( $sock_file );
|
my $saddr = sockaddr_un( $sock_file );
|
||||||
my $server_up = connect( CLIENT, $saddr );
|
my $server_up = connect( CLIENT, $saddr );
|
||||||
if ( !$server_up )
|
if ( !$server_up )
|
||||||
{
|
{
|
||||||
# The server isn't there
|
# The server isn't there
|
||||||
my $monitor = zmDbGetMonitorAndControl( $id );
|
my $monitor = zmDbGetMonitorAndControl( $id );
|
||||||
if ( !$monitor )
|
if ( !$monitor )
|
||||||
{
|
{
|
||||||
|
@ -129,16 +141,17 @@ if ( !$server_up )
|
||||||
Info( "Starting control server $id/$protocol" );
|
Info( "Starting control server $id/$protocol" );
|
||||||
close( CLIENT );
|
close( CLIENT );
|
||||||
|
|
||||||
if ( ! can_load( modules => { "ZoneMinder::Control::$protocol" => undef } ) ) {
|
if ( ! can_load( modules => { "ZoneMinder::Control::$protocol" => undef } ) ) {
|
||||||
Fatal("Can't load ZoneMinder::Control::$protocol");
|
Fatal("Can't load ZoneMinder::Control::$protocol");
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( my $cpid = fork() )
|
if ( my $cpid = fork() )
|
||||||
{
|
{
|
||||||
logReinit();
|
logReinit();
|
||||||
|
|
||||||
# Parent process just sleep and fall through
|
# Parent process just sleep and fall through
|
||||||
socket( CLIENT, PF_UNIX, SOCK_STREAM, 0 ) or die( "Can't open socket: $!" );
|
socket( CLIENT, PF_UNIX, SOCK_STREAM, 0 )
|
||||||
|
or die( "Can't open socket: $!" );
|
||||||
my $attempts = 0;
|
my $attempts = 0;
|
||||||
while (!connect( CLIENT, $saddr ))
|
while (!connect( CLIENT, $saddr ))
|
||||||
{
|
{
|
||||||
|
@ -156,7 +169,9 @@ if ( !$server_up )
|
||||||
|
|
||||||
logReinit();
|
logReinit();
|
||||||
|
|
||||||
Info( "Control server $id/$protocol starting at ".strftime( '%y/%m/%d %H:%M:%S', localtime() ) );
|
Info( "Control server $id/$protocol starting at "
|
||||||
|
.strftime( '%y/%m/%d %H:%M:%S', localtime() )
|
||||||
|
);
|
||||||
|
|
||||||
$0 = $0." --id $id";
|
$0 = $0." --id $id";
|
||||||
|
|
||||||
|
@ -166,7 +181,8 @@ if ( !$server_up )
|
||||||
|
|
||||||
$control->open();
|
$control->open();
|
||||||
|
|
||||||
socket( SERVER, PF_UNIX, SOCK_STREAM, 0 ) or Fatal( "Can't open socket: $!" );
|
socket( SERVER, PF_UNIX, SOCK_STREAM, 0 )
|
||||||
|
or Fatal( "Can't open socket: $!" );
|
||||||
unlink( $sock_file );
|
unlink( $sock_file );
|
||||||
bind( SERVER, $saddr ) or Fatal( "Can't bind: $!" );
|
bind( SERVER, $saddr ) or Fatal( "Can't bind: $!" );
|
||||||
listen( SERVER, SOMAXCONN ) or Fatal( "Can't listen: $!" );
|
listen( SERVER, SOMAXCONN ) or Fatal( "Can't listen: $!" );
|
||||||
|
@ -193,9 +209,9 @@ if ( !$server_up )
|
||||||
|
|
||||||
my $command = $params->{command};
|
my $command = $params->{command};
|
||||||
close( CLIENT );
|
close( CLIENT );
|
||||||
if ( $command eq 'quit' ) {
|
if ( $command eq 'quit' ) {
|
||||||
last;
|
last;
|
||||||
}
|
}
|
||||||
$control->$command( $params );
|
$control->$command( $params );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -220,7 +236,9 @@ if ( !$server_up )
|
||||||
last;
|
last;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Info( "Control server $id/$protocol exiting at ".strftime( '%y/%m/%d %H:%M:%S', localtime() ) );
|
Info( "Control server $id/$protocol exiting at "
|
||||||
|
.strftime( '%y/%m/%d %H:%M:%S', localtime() )
|
||||||
|
);
|
||||||
unlink( $sock_file );
|
unlink( $sock_file );
|
||||||
$control->close();
|
$control->close();
|
||||||
exit( 0 );
|
exit( 0 );
|
||||||
|
|
Loading…
Reference in New Issue