diff --git a/scripts/zmaudit.pl b/scripts/zmaudit.pl index fcca26177..af1b9040b 100644 --- a/scripts/zmaudit.pl +++ b/scripts/zmaudit.pl @@ -136,6 +136,7 @@ sub confirm } zmDbgInit( DBG_ID, level=>DBG_LEVEL ); +zmDbgSetSignal(); if ( !GetOptions( 'report'=>\$report, 'interactive'=>\$interactive, 'continuous'=>\$continuous ) ) { diff --git a/scripts/zmdc.pl b/scripts/zmdc.pl index e2efc2c3a..eea31721d 100644 --- a/scripts/zmdc.pl +++ b/scripts/zmdc.pl @@ -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 = $!; diff --git a/scripts/zmfilter.pl b/scripts/zmfilter.pl index 5e3d8866a..eaaf09c34 100644 --- a/scripts/zmfilter.pl +++ b/scripts/zmfilter.pl @@ -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 ) { diff --git a/scripts/zmpkg.pl b/scripts/zmpkg.pl index 033aa67c5..27cdd583c 100644 --- a/scripts/zmpkg.pl +++ b/scripts/zmpkg.pl @@ -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 \n" ); + print( "Usage: zmpkg.pl \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 diff --git a/scripts/zmtrack.pl b/scripts/zmtrack.pl index c8b1eb9a6..34f1cb57f 100644 --- a/scripts/zmtrack.pl +++ b/scripts/zmtrack.pl @@ -75,6 +75,7 @@ if ( !GetOptions( 'monitor=s'=>\$mid ) ) } zmDbgInit( DBG_ID, level=>DBG_LEVEL ); +zmDbgSetSignal(); my ( $detaint_mid ) = $mid =~ /^(\d+)$/; $mid = $detaint_mid; diff --git a/scripts/zmtrigger.pl b/scripts/zmtrigger.pl index dbd6775e1..a985fc97a 100644 --- a/scripts/zmtrigger.pl +++ b/scripts/zmtrigger.pl @@ -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: $!" ); } } diff --git a/scripts/zmupdate.pl b/scripts/zmupdate.pl index dd94005da..54e131f4c 100644 --- a/scripts/zmupdate.pl +++ b/scripts/zmupdate.pl @@ -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; diff --git a/scripts/zmwatch.pl b/scripts/zmwatch.pl index 30a316ccc..df272c965 100644 --- a/scripts/zmwatch.pl +++ b/scripts/zmwatch.pl @@ -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" ); diff --git a/scripts/zmx10.pl b/scripts/zmx10.pl index 8e365731c..d867d27bc 100644 --- a/scripts/zmx10.pl +++ b/scripts/zmx10.pl @@ -70,6 +70,7 @@ Parameters are :- } zmDbgInit( DBG_ID, level=>DBG_LEVEL ); +zmDbgSetSignal(); my $command; my $unit_code;