Detect if system is running and prompt to stop it before doing the update.
This commit is contained in:
parent
d4488ac4e1
commit
5e0f1a03c5
|
@ -28,6 +28,7 @@ our %EXPORT_TAGS = (
|
|||
makePath
|
||||
jsonEncode
|
||||
jsonDecode
|
||||
status
|
||||
) ]
|
||||
);
|
||||
push( @{$EXPORT_TAGS{all}}, @{$EXPORT_TAGS{$_}} ) foreach keys %EXPORT_TAGS;
|
||||
|
@ -531,6 +532,38 @@ sub jsonDecode {
|
|||
return $result;
|
||||
}
|
||||
|
||||
sub packageControl {
|
||||
my $command = shift;
|
||||
my $string = $Config{ZM_PATH_BIN}.'/zmpkg.pl '.$command;
|
||||
$string .= ' 2>/dev/null >&- <&- >/dev/null';
|
||||
executeShellCommand($string);
|
||||
}
|
||||
|
||||
sub daemonControl {
|
||||
my ($command, $daemon, $args) = @_;
|
||||
my $string = $Config{ZM_PATH_BIN}.'/zmdc.pl '.$command;
|
||||
if ( $daemon ) {
|
||||
$string .= ' ' . $daemon;
|
||||
if ( $args ) {
|
||||
$string .= ' ' . $args;
|
||||
}
|
||||
}
|
||||
#$string .= ' 2>/dev/null >&- <&- >/dev/null';
|
||||
executeShellCommand($string);
|
||||
}
|
||||
|
||||
sub systemStatus {
|
||||
my $command = shift;
|
||||
my $output = qx($command);
|
||||
my $status = $? >> 8;
|
||||
if ( $status || logDebugging() ) {
|
||||
$output = '' if !defined($output);
|
||||
chomp($output);
|
||||
Debug("Command: $command Output: $output");
|
||||
}
|
||||
return $output;
|
||||
}
|
||||
|
||||
1;
|
||||
__END__
|
||||
# Below is stub documentation for your module. You'd better edit it!
|
||||
|
|
|
@ -142,7 +142,7 @@ if ( ($check + $freshen + $rename + $zoneFix + $migrateEvents + ($version?1:0))
|
|||
}
|
||||
|
||||
if ( $check && $Config{ZM_CHECK_FOR_UPDATES} ) {
|
||||
print( "Update agent starting at ".strftime( '%y/%m/%d %H:%M:%S', localtime() )."\n" );
|
||||
print('Update agent starting at '.strftime('%y/%m/%d %H:%M:%S', localtime() )."\n");
|
||||
|
||||
my $currVersion = $Config{ZM_DYN_CURR_VERSION};
|
||||
my $lastVersion = $Config{ZM_DYN_LAST_VERSION};
|
||||
|
@ -153,18 +153,18 @@ if ( $check && $Config{ZM_CHECK_FOR_UPDATES} ) {
|
|||
|
||||
my $sql = "update Config set Value = ? where Name = 'ZM_DYN_CURR_VERSION'";
|
||||
my $sth = $dbh->prepare_cached($sql) or die("Can't prepare '$sql': ".$dbh->errstr());
|
||||
my $res = $sth->execute( "$currVersion" ) or die( "Can't execute: ".$sth->errstr() );
|
||||
my $res = $sth->execute($currVersion) or die("Can't execute: ".$sth->errstr());
|
||||
$sth->finish();
|
||||
}
|
||||
|
||||
while ( 1 ) {
|
||||
my $now = time();
|
||||
if ( !$lastVersion || !$lastCheck || (($now-$lastCheck) > CHECK_INTERVAL) ) {
|
||||
Info( "Checking for updates\n" );
|
||||
Info('Checking for updates');
|
||||
|
||||
use LWP::UserAgent;
|
||||
my $ua = LWP::UserAgent->new;
|
||||
$ua->agent( "ZoneMinder Update Agent/".ZM_VERSION );
|
||||
$ua->agent('ZoneMinder Update Agent/'.ZM_VERSION);
|
||||
if ( $Config{ZM_UPDATE_CHECK_PROXY} ) {
|
||||
$ua->proxy('http', $Config{ZM_UPDATE_CHECK_PROXY});
|
||||
}
|
||||
|
@ -176,24 +176,24 @@ if ( $check && $Config{ZM_CHECK_FOR_UPDATES} ) {
|
|||
chomp($lastVersion);
|
||||
$lastCheck = $now;
|
||||
|
||||
Info( "Got version: '".$lastVersion."'\n" );
|
||||
Info('Got version: '.$lastVersion);
|
||||
|
||||
my $lv_sql = "update Config set Value = ? where Name = 'ZM_DYN_LAST_VERSION'";
|
||||
my $lv_sql = 'UPDATE Config SET Value = ? WHERE Name = \'ZM_DYN_LAST_VERSION\'';
|
||||
my $lv_sth = $dbh->prepare_cached($lv_sql) or die("Can't prepare '$lv_sql': ".$dbh->errstr());
|
||||
my $lv_res = $lv_sth->execute($lastVersion) or die("Can't execute: ".$lv_sth->errstr());
|
||||
$lv_sth->finish();
|
||||
|
||||
my $lc_sql = "update Config set Value = ? where Name = 'ZM_DYN_LAST_CHECK'";
|
||||
my $lc_sql = 'UPDATE Config SET Value = ? WHERE Name = \'ZM_DYN_LAST_CHECK\'';
|
||||
my $lc_sth = $dbh->prepare_cached($lc_sql) or die("Can't prepare '$lc_sql': ".$dbh->errstr());
|
||||
my $lc_res = $lc_sth->execute($lastCheck) or die("Can't execute: ".$lc_sth->errstr());
|
||||
$lc_sth->finish();
|
||||
} else {
|
||||
Error( "Error check failed: '".$res->status_line()."'\n" );
|
||||
Error('Error check failed: \''.$res->status_line().'\'');
|
||||
}
|
||||
}
|
||||
sleep(3600);
|
||||
}
|
||||
print( "Update agent exiting at ".strftime( '%y/%m/%d %H:%M:%S', localtime() )."\n" );
|
||||
print('Update agent exiting at '.strftime('%y/%m/%d %H:%M:%S', localtime())."\n");
|
||||
}
|
||||
|
||||
if ( $rename ) {
|
||||
|
@ -212,17 +212,17 @@ if ( $rename ) {
|
|||
if ( $file !~ /(capture|analyse)-(\d+)(\.jpg)/ ) {
|
||||
return;
|
||||
}
|
||||
my $newFile = "$2-$1$3";
|
||||
my $newFile = $2.'-'.$1.$3;
|
||||
|
||||
print("Renaming '$file' to '$newFile'\n");
|
||||
rename($file, $newFile) or warn("Can't rename '$file' to '$newFile'");
|
||||
}
|
||||
|
||||
File::Find::find(\&renameImage, '.');
|
||||
}
|
||||
if ( $zoneFix ) {
|
||||
} # end if rename
|
||||
|
||||
my $sql = "select Z.*, M.Width as MonitorWidth, M.Height as MonitorHeight from Zones as Z inner join Monitors as M on Z.MonitorId = M.Id where Z.Units = 'Percent'";
|
||||
if ( $zoneFix ) {
|
||||
my $sql = "SELECT Z.*, M.Width AS MonitorWidth, M.Height AS MonitorHeight FROM Zones AS Z INNER JOIN Monitors AS M ON Z.MonitorId = M.Id WHERE Z.Units = 'Percent'";
|
||||
my $sth = $dbh->prepare_cached($sql) or die("Can't prepare '$sql': ".$dbh->errstr());
|
||||
my $res = $sth->execute() or die("Can't execute: ".$sth->errstr());
|
||||
my @zones;
|
||||
|
@ -231,7 +231,7 @@ if ( $zoneFix ) {
|
|||
}
|
||||
$sth->finish();
|
||||
|
||||
$sql = 'update Zones set MinAlarmPixels = ?, MaxAlarmPixels = ?, MinFilterPixels = ?, MaxFilterPixels = ?, MinBlobPixels = ?, MaxBlobPixels = ? where Id = ?';
|
||||
$sql = 'UPDATE Zones SET MinAlarmPixels = ?, MaxAlarmPixels = ?, MinFilterPixels = ?, MaxFilterPixels = ?, MinBlobPixels = ?, MaxBlobPixels = ? WHERE Id = ?';
|
||||
$sth = $dbh->prepare_cached($sql) or die("Can't prepare '$sql': ".$dbh->errstr());
|
||||
foreach my $zone ( @zones ) {
|
||||
my $zone_width = (($zone->{HiX}*$zone->{MonitorWidth})-($zone->{LoX}*$zone->{MonitorWidth}))/100;
|
||||
|
@ -249,7 +249,8 @@ if ( $zoneFix ) {
|
|||
) or die("Can't execute: ".$sth->errstr());
|
||||
}
|
||||
$sth->finish();
|
||||
}
|
||||
} # end if zoneFix
|
||||
|
||||
if ( $migrateEvents ) {
|
||||
my $webUid = (getpwnam($Config{ZM_WEB_USER}))[2];
|
||||
my $webGid = (getgrnam($Config{ZM_WEB_USER}))[2];
|
||||
|
@ -265,7 +266,11 @@ if ( $migrateEvents ) {
|
|||
$< = $webUid;
|
||||
$> = $webUid;
|
||||
|
||||
print( "\nAbout to convert saved events to deep storage, please ensure that ZoneMinder is fully stopped before proceeding.\nThis process is not easily reversible. Are you sure you wish to proceed?\n\nPress 'y' to continue or 'n' to abort : " );
|
||||
print('
|
||||
About to convert saved events to deep storage, please ensure that ZoneMinder is fully stopped before proceeding.
|
||||
This process is not easily reversible. Are you sure you wish to proceed?
|
||||
|
||||
Press \'y\' to continue or \'n\' to abort : ');
|
||||
my $response = <STDIN>;
|
||||
chomp($response);
|
||||
while ( $response !~ /^[yYnN]$/ ) {
|
||||
|
@ -278,7 +283,7 @@ if ( $migrateEvents ) {
|
|||
print("Converting all events to deep storage.\n");
|
||||
|
||||
chdir($Config{ZM_PATH_WEB});
|
||||
my $sql = "select *, unix_timestamp(StartTime) as UnixStartTime from Events";
|
||||
my $sql = 'SELECT *, unix_timestamp(StartTime) AS UnixStartTime FROM Events';
|
||||
my $sth = $dbh->prepare_cached($sql) or Fatal("Can't prepare '$sql': ".$dbh->errstr());
|
||||
my $res = $sth->execute();
|
||||
if ( !$res ) {
|
||||
|
@ -293,9 +298,9 @@ if ( $migrateEvents ) {
|
|||
next;
|
||||
}
|
||||
|
||||
print( "Converting event ".$event->{Id}."\n" );
|
||||
my $newDatePath = $Config{ZM_DIR_EVENTS}.'/'.$event->{MonitorId}.'/'.strftime( "%y/%m/%d", localtime($event->{UnixStartTime}) );
|
||||
my $newTimePath = strftime( "%H/%M/%S", localtime($event->{UnixStartTime}) );
|
||||
print('Converting event '.$event->{Id}."\n");
|
||||
my $newDatePath = $Config{ZM_DIR_EVENTS}.'/'.$event->{MonitorId}.'/'.strftime('%y/%m/%d', localtime($event->{UnixStartTime}));
|
||||
my $newTimePath = strftime('%H/%M/%S', localtime($event->{UnixStartTime}));
|
||||
my $newEventPath = $newDatePath.'/'.$newTimePath;
|
||||
( my $truncEventPath = $newEventPath ) =~ s|/\d+$||;
|
||||
makePath($truncEventPath, $Config{ZM_PATH_WEB});
|
||||
|
@ -316,6 +321,7 @@ if ( $migrateEvents ) {
|
|||
print("Aborting event conversion.\n\n");
|
||||
}
|
||||
}
|
||||
|
||||
if ( $freshen ) {
|
||||
print("\nFreshening configuration in database\n");
|
||||
migratePaths();
|
||||
|
@ -338,8 +344,13 @@ if ( $interactive ) {
|
|||
$sth->finish();
|
||||
|
||||
if ( @MyISAM_Tables ) {
|
||||
print( "\nPrevious versions of ZoneMinder used the MyISAM database engine.\nHowever, the recommended database engine is InnoDB.\n");
|
||||
print( "\nHint: InnoDB tables are much less likely to be corrupted during an unclean shutdown.\n\nPress 'y' to convert your tables to InnoDB or 'n' to skip : ");
|
||||
print('
|
||||
Previous versions of ZoneMinder used the MyISAM database engine.
|
||||
However, the recommended database engine is InnoDB.
|
||||
|
||||
Hint: InnoDB tables are much less likely to be corrupted during an unclean shutdown.
|
||||
|
||||
Press \'y\' to convert your tables to InnoDB or \'n\' to skip : ');
|
||||
my $response = <STDIN>;
|
||||
chomp( $response );
|
||||
if ( $response =~ /^[yY]$/ ) {
|
||||
|
@ -365,10 +376,21 @@ if ( $version ) {
|
|||
exit(0);
|
||||
}
|
||||
|
||||
my $start_zm = 0;
|
||||
if ( (systemStatus() eq 'running') and $interactive ) {
|
||||
print "\nZoneMinder system appears to be running. While not strictly required, it is advised to stop ZM during the update process. Would you like to stop ZM now? [Yn]:";
|
||||
my $response = <STDIN>;
|
||||
chomp($response);
|
||||
if ( $response !~ /Yy/ ) {
|
||||
packageControl('stop');
|
||||
$start_zm = 1;
|
||||
}
|
||||
}
|
||||
|
||||
print("\nInitiating database upgrade to version ".ZM_VERSION." from version $version\n");
|
||||
if ( $interactive ) {
|
||||
if ( $Config{ZM_DYN_DB_VERSION} && $Config{ZM_DYN_DB_VERSION} ne $version ) {
|
||||
print( "\nWARNING - You have specified an upgrade from version $version but the database version found is ".$Config{ZM_DYN_DB_VERSION}.". Is this correct?\nPress enter to continue or ctrl-C to abort : " );
|
||||
if ( $Config{ZM_DYN_DB_VERSION} && ($Config{ZM_DYN_DB_VERSION} ne $version) ) {
|
||||
print("\nWARNING - You have specified an upgrade from version $version but the database version found is $Config{ZM_DYN_DB_VERSION}. Is this correct?\nPress enter to continue or ctrl-C to abort : ");
|
||||
my $response = <STDIN>;
|
||||
}
|
||||
|
||||
|
@ -939,7 +961,12 @@ if ( $version ) {
|
|||
#my $sth = $dbh->prepare_cached( $sql ) or die( "Can't prepare '$sql': ".$dbh->errstr() );
|
||||
#my $res = $sth->execute( ) or die( "Can't execute: ".$sth->errstr() );
|
||||
#$sth->finish();
|
||||
|
||||
print("\nDatabase upgrade to version ".ZM_VERSION." successful.\n\n");
|
||||
if ( $start_zm ) {
|
||||
print("Starting ZM since we stopped it for the update\n");
|
||||
packageControl('start');
|
||||
}
|
||||
} # end if version
|
||||
|
||||
zmDbDisconnect();
|
||||
|
|
Loading…
Reference in New Issue