Bug 354 - Added facility to signal scripts to rotate logs.
git-svn-id: http://svn.zoneminder.com/svn/zm/trunk@2008 e3e1d417-86f3-4887-817a-d78f3d33393f
This commit is contained in:
parent
834bc81a07
commit
fd92f7bcb0
|
@ -136,6 +136,7 @@ sub confirm
|
|||
}
|
||||
|
||||
zmDbgInit( DBG_ID, level=>DBG_LEVEL );
|
||||
zmDbgSetSignal();
|
||||
|
||||
if ( !GetOptions( 'report'=>\$report, 'interactive'=>\$interactive, 'continuous'=>\$continuous ) )
|
||||
{
|
||||
|
|
|
@ -76,7 +76,7 @@ my @daemons = (
|
|||
|
||||
my $command = shift @ARGV;
|
||||
die( "No command given" ) unless( $command );
|
||||
my $needs_daemon = $command !~ /(?:startup|shutdown|status|check)/;
|
||||
my $needs_daemon = $command !~ /(?:startup|shutdown|status|check|logrot)/;
|
||||
my $daemon = shift( @ARGV );
|
||||
die( "No daemon given" ) unless( !$needs_daemon || $daemon );
|
||||
my @args;
|
||||
|
@ -114,6 +114,10 @@ my $saddr = sockaddr_un( SOCK_FILE );
|
|||
my $server_up = connect( CLIENT, $saddr );
|
||||
if ( !$server_up )
|
||||
{
|
||||
if ( $command eq "logrot" )
|
||||
{
|
||||
exit();
|
||||
}
|
||||
if ( $command eq "check" )
|
||||
{
|
||||
print( "stopped\n" );
|
||||
|
@ -170,7 +174,7 @@ if ( !$server_up )
|
|||
$SIG{INT} = \&shutdownAll;
|
||||
$SIG{TERM} = \&shutdownAll;
|
||||
$SIG{ABRT} = \&shutdownAll;
|
||||
$SIG{HUP} = \&status;
|
||||
$SIG{HUP} = \&logrot;
|
||||
|
||||
my %cmd_hash;
|
||||
my %pid_hash;
|
||||
|
@ -234,6 +238,10 @@ if ( !$server_up )
|
|||
status();
|
||||
}
|
||||
}
|
||||
elsif ( $command eq 'logrot' )
|
||||
{
|
||||
logrot();
|
||||
}
|
||||
else
|
||||
{
|
||||
dPrint( DBG_ERROR, "Invalid command '$command'\n" );
|
||||
|
@ -353,7 +361,6 @@ if ( !$server_up )
|
|||
$SIG{INT} = 'DEFAULT';
|
||||
$SIG{TERM} = 'DEFAULT';
|
||||
$SIG{ABRT} = 'DEFAULT';
|
||||
$SIG{HUP} = 'DEFAULT';
|
||||
dPrint( DBG_INFO, "'".join( ' ', ( $daemon, @args ) )."' started at ".strftime( '%y/%m/%d %H:%M:%S', localtime() )."\n" );
|
||||
|
||||
if ( $daemon =~ /^${daemon_patt}$/ )
|
||||
|
@ -472,6 +479,17 @@ if ( !$server_up )
|
|||
}
|
||||
}
|
||||
}
|
||||
sub logrot
|
||||
{
|
||||
zmDbgReinit();
|
||||
foreach my $process ( values( %pid_hash ) )
|
||||
{
|
||||
if ( $process->{pid} && $process->{command} =~ /^zm.*\.pl/ )
|
||||
{
|
||||
kill( 'HUP', $process->{pid} );
|
||||
}
|
||||
}
|
||||
}
|
||||
sub reaper
|
||||
{
|
||||
my $saved_status = $!;
|
||||
|
|
|
@ -56,6 +56,7 @@ use Getopt::Long;
|
|||
use constant EVENT_PATH => ZM_PATH_WEB.'/'.ZM_DIR_EVENTS;
|
||||
|
||||
zmDbgInit( DBG_ID, level=>DBG_LEVEL );
|
||||
zmDbgSetSignal();
|
||||
|
||||
if ( ZM_OPT_UPLOAD )
|
||||
{
|
||||
|
|
|
@ -60,7 +60,7 @@ my $state;
|
|||
|
||||
my $dbh = DBI->connect( "DBI:mysql:database=".ZM_DB_NAME.";host=".ZM_DB_HOST, ZM_DB_USER, ZM_DB_PASS );
|
||||
|
||||
if ( !$command || $command !~ /^(?:start|stop|restart|status)$/ )
|
||||
if ( !$command || $command !~ /^(?:start|stop|restart|status|logrot)$/ )
|
||||
{
|
||||
if ( $command )
|
||||
{
|
||||
|
@ -86,7 +86,7 @@ if ( !$command || $command !~ /^(?:start|stop|restart|status)$/ )
|
|||
}
|
||||
if ( !$command )
|
||||
{
|
||||
print( "Usage: zmpkg.pl <start|stop|restart|status|'state'>\n" );
|
||||
print( "Usage: zmpkg.pl <start|stop|restart|status|logrot|'state'>\n" );
|
||||
exit( -1 );
|
||||
}
|
||||
}
|
||||
|
@ -230,6 +230,11 @@ if ( $command eq "status" )
|
|||
print( STDOUT $status."\n" );
|
||||
}
|
||||
|
||||
if ( $command eq "logrot" )
|
||||
{
|
||||
runCommand( "zmdc.pl logrot" );
|
||||
}
|
||||
|
||||
exit( $retval );
|
||||
|
||||
sub getCmdFormat
|
||||
|
|
|
@ -75,6 +75,7 @@ if ( !GetOptions( 'monitor=s'=>\$mid ) )
|
|||
}
|
||||
|
||||
zmDbgInit( DBG_ID, level=>DBG_LEVEL );
|
||||
zmDbgSetSignal();
|
||||
|
||||
my ( $detaint_mid ) = $mid =~ /^(\d+)$/;
|
||||
$mid = $detaint_mid;
|
||||
|
|
|
@ -70,13 +70,12 @@ $ENV{SHELL} = '/bin/sh' if exists $ENV{SHELL};
|
|||
delete @ENV{qw(IFS CDPATH ENV BASH_ENV)};
|
||||
|
||||
zmDbgInit( DBG_ID, level=>DBG_LEVEL );
|
||||
zmDbgSetSignal();
|
||||
|
||||
Info( "Trigger daemon starting\n" );
|
||||
|
||||
my $dbh = DBI->connect( "DBI:mysql:database=".ZM_DB_NAME.";host=".ZM_DB_HOST, ZM_DB_USER, ZM_DB_PASS );
|
||||
|
||||
$SIG{HUP} = \&status;
|
||||
|
||||
my $base_rin = '';
|
||||
foreach my $connection ( @connections )
|
||||
{
|
||||
|
@ -175,7 +174,7 @@ while( 1 )
|
|||
}
|
||||
else
|
||||
{
|
||||
die( "Can't select: $!" );
|
||||
Fatal( "Can't select: $!" );
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -64,6 +64,7 @@ my $web_uid = (getpwnam( ZM_WEB_USER ))[2];
|
|||
my $use_log = (($> == 0) || ($> == $web_uid));
|
||||
|
||||
zmDbgInit( DBG_ID, level=>DBG_LEVEL, to_log=>$use_log );
|
||||
zmDbgSetSignal();
|
||||
|
||||
my $interactive = 1;
|
||||
my $check = 0;
|
||||
|
|
|
@ -65,6 +65,7 @@ Usage: zmwatch.pl
|
|||
}
|
||||
|
||||
zmDbgInit( DBG_ID, level=>DBG_LEVEL );
|
||||
zmDbgSetSignal();
|
||||
|
||||
Info( "Watchdog starting\n" );
|
||||
Info( "Watchdog pausing for ".START_DELAY." seconds\n" );
|
||||
|
|
|
@ -70,6 +70,7 @@ Parameters are :-
|
|||
}
|
||||
|
||||
zmDbgInit( DBG_ID, level=>DBG_LEVEL );
|
||||
zmDbgSetSignal();
|
||||
|
||||
my $command;
|
||||
my $unit_code;
|
||||
|
|
Loading…
Reference in New Issue