diff --git a/scripts/zmpkg.pl.z b/scripts/zmpkg.pl.z index 5e35a005a..36509afcc 100755 --- a/scripts/zmpkg.pl.z +++ b/scripts/zmpkg.pl.z @@ -41,12 +41,12 @@ use constant ZM_DB_SERVER => ""; use constant ZM_DB_NAME => ""; use constant ZM_DB_USERA => ""; use constant ZM_DB_PASSA => ""; +use constant ZM_SHM_KEY => ""; use constant ZM_OPT_FAST_DELETE => ""; use constant ZM_OPT_X10 => ""; use constant ZM_OPT_FRAME_SERVER => ""; use constant LOG_FILE => ZM_PATH_LOGS.'/zmpkg.log'; -use constant WEB_USER => '@WEB_USER@/'; use constant VERBOSE => 0; # Whether to output more verbose debug # ========================================================================== @@ -69,6 +69,28 @@ if ( !$command || $command !~ /^(?:start|stop|restart|status)$/ ) exit( -1 ); } +sub remove_shm +{ + print( STDERR "Removing shared memory\n" ); + # Find ZoneMinder shared memory + my $command = "ipcs -m | grep '^".substr( sprintf( "0x%x", ZM_SHM_KEY ), 0, -2 )."'"; + print( "Checking for shared memory with '$command'\n" ) if ( VERBOSE ); + open( CMD, "$command |" ) or die( "Can't execute '$command': $!" ); + while( ) + { + chomp; + my ( $key, $id ) = split( /\s+/ ); + if ( $id =~ /^(\d+)/ ) + { + $id = $1; + my $command = "ipcrm shm $id"; + print( "Removing shared memory with '$command'\n" ) if ( VERBOSE ); + qx( $command ); + } + } + close( CMD ); +} + sub execute { my $command = shift; @@ -108,6 +130,7 @@ if ( $command =~ /^(?:stop|restart)$/ ) if ( $status eq "running" ) { execute( ZM_PATH_BIN."/zmdc.pl shutdown" ); + remove_shm(); } else { @@ -121,6 +144,7 @@ if ( $command =~ /^(?:start|restart)$/ ) chomp( $status ); if ( $status eq "stopped" ) { + remove_shm(); execute( ZM_PATH_BIN."/zmfix" ); execute( ZM_PATH_BIN."/zmdc.pl status" );