diff --git a/db/zm_create.sql.in b/db/zm_create.sql.in index 9768b1241..803045a5b 100644 --- a/db/zm_create.sql.in +++ b/db/zm_create.sql.in @@ -382,6 +382,7 @@ CREATE TABLE `Monitors` ( -- -- Table structure for table `States` +-- Added IsActive to track custom run states -- DROP TABLE IF EXISTS `States`; @@ -389,6 +390,7 @@ CREATE TABLE `States` ( `Id` int(10) unsigned NOT NULL auto_increment, `Name` varchar(64) NOT NULL default '', `Definition` text NOT NULL, + `IsActive` tinyint(3) unsigned NOT NULL default '0', PRIMARY KEY (`Id`) ) ENGINE=@ZM_MYSQL_ENGINE@; diff --git a/db/zm_update-1.28.99.sql b/db/zm_update-1.28.99.sql index 2e1802966..eef570132 100644 --- a/db/zm_update-1.28.99.sql +++ b/db/zm_update-1.28.99.sql @@ -342,6 +342,22 @@ SET @s = (SELECT IF( PREPARE stmt FROM @s; EXECUTE stmt; +--- The States table will be updated to have a new column called IsActive +--- used to keep track of which custom state is active (if any) +SET @s = (SELECT IF( + (SELECT COUNT(*) + FROM INFORMATION_SCHEMA.COLUMNS + WHERE table_name = 'States' + AND table_schema = DATABASE() + AND column_name = 'IsActive' + ) > 0, +"SELECT 'Column IsActive exists in States'", +"ALTER TABLE `States` ADD `IsActive` tinyint(3) unsigned not null default 0 AFTER `Definition`" +)); + +PREPARE stmt FROM @s; +EXECUTE stmt; + SET @s = (SELECT IF( (SELECT COUNT(*) FROM INFORMATION_SCHEMA.TABLES @@ -356,3 +372,7 @@ SET @s = (SELECT IF( PRIMARY KEY (`Id`) )" )); + +PREPARE stmt FROM @s; +EXECUTE stmt; + diff --git a/scripts/zmpkg.pl.in b/scripts/zmpkg.pl.in index 362f4f6a6..46ea825c4 100644 --- a/scripts/zmpkg.pl.in +++ b/scripts/zmpkg.pl.in @@ -55,6 +55,7 @@ use autouse 'Pod::Usage'=>qw(pod2usage); $ENV{PATH} = '/bin:/usr/bin'; $ENV{SHELL} = '/bin/sh' if exists $ENV{SHELL}; delete @ENV{qw(IFS CDPATH ENV BASH_ENV)}; +my $store_state=""; # PP - will remember state name passed logInit(); @@ -90,6 +91,7 @@ if ( !$command || $command !~ /^(?:start|stop|restart|status|logrot|version)$/ ) { Id=>$id, Function=>$function, Enabled=>$enabled } ); } + $store_state=$command; # PP - Remember the name that was passed to search in DB $command = 'state'; } else @@ -149,6 +151,18 @@ if ( $command eq "state" ) } } $sth->finish(); + #PP - lets go ahead and modify States DB + + + Debug ("Marking $store_state as Enabled"); + # PP - Zero out other states being active + resetStates(); + # PP - Now mark a specific state as active + $sql = "update States set IsActive = '1' where Name = ?"; + $sth = $dbh->prepare_cached( $sql ) + or Fatal( "Can't prepare '$sql': ".$dbh->errstr() ); + $res = $sth->execute( $store_state ) + or Fatal( "Can't execute: ".$sth->errstr() ); $command = "restart"; } @@ -159,6 +173,9 @@ if ( $command =~ /^(start|stop|restart)$/ ) # We have to detaint to keep perl from complaining $command = $1; + # PP - if we are not switching to a custom state, zero out all isActive + resetStates() if (!$store_state); + if ( systemdRunning() && !calledBysystem() ) { qx(@BINDIR@/zmsystemctl.pl $command); $command = ""; @@ -290,6 +307,19 @@ if ( $command eq "logrot" ) exit( $retval ); +# PP - when the system is restarted/started/stopped, it will +# not be in a custom state, so lets keep the DB consistent +sub resetStates +{ + $dbh = zmDbConnect() if ! $dbh; + my $sql = "update States set IsActive = '0'"; + my $sth = $dbh->prepare_cached( $sql ) + or Fatal( "Can't prepare '$sql': ".$dbh->errstr() ); + my $res = $sth->execute() + or Fatal( "Can't execute: ".$sth->errstr() ); + +} + sub systemdRunning { my $result = 0; diff --git a/web/skins/classic/views/console.php b/web/skins/classic/views/console.php index bf33802d9..1d600d0d0 100644 --- a/web/skins/classic/views/console.php +++ b/web/skins/classic/views/console.php @@ -70,6 +70,8 @@ $eventCounts = array( $running = daemonCheck(); $status = $running?translate('Running'):translate('Stopped'); +$run_state_array = dbFetchOne('select Name from States where IsActive = 1'); +$run_state = implode($run_state_array); $group = NULL; if ( ! empty($_COOKIE['zmGroup']) ) { @@ -188,7 +190,7 @@ xhtmlHeaders( __FILE__, translate('Console') );