From d2472f177d64e76123fc903c0b438afad66ac6af Mon Sep 17 00:00:00 2001 From: Pliable Pixels Date: Sun, 21 Jun 2015 09:30:14 -0400 Subject: [PATCH 1/4] Added isRunning column --- db/zm_create.sql.in | 2 ++ 1 file changed, 2 insertions(+) diff --git a/db/zm_create.sql.in b/db/zm_create.sql.in index c7d51641c..63d423731 100644 --- a/db/zm_create.sql.in +++ b/db/zm_create.sql.in @@ -382,12 +382,14 @@ CREATE TABLE `Monitors` ( -- -- Table structure for table `States` +-- Added IsActive to track custom run states -- DROP TABLE IF EXISTS `States`; CREATE TABLE `States` ( `Name` varchar(64) NOT NULL default '', `Definition` text NOT NULL, + `IsActive` tinyint(3) unsigned NOT NULL default '0', PRIMARY KEY (`Name`) ) ENGINE=@ZM_MYSQL_ENGINE@; From 754091b55da7062531768c5471956ee0bb96422b Mon Sep 17 00:00:00 2001 From: Pliable Pixels Date: Sun, 21 Jun 2015 09:30:23 -0400 Subject: [PATCH 2/4] Added isRunning column --- db/zm_update-1.28.99.sql | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/db/zm_update-1.28.99.sql b/db/zm_update-1.28.99.sql index 3aab54345..d8b41c18e 100644 --- a/db/zm_update-1.28.99.sql +++ b/db/zm_update-1.28.99.sql @@ -324,4 +324,20 @@ WHERE NOT EXISTS ( -- UPDATE `zm`.`Config` SET `Category`='hidden' WHERE `Name`='ZM_USE_DEEP_STORAGE'; +--- 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; + From e758d9bf7cf7393acde9af45f8260c1219e5b757 Mon Sep 17 00:00:00 2001 From: Pliable Pixels Date: Sun, 21 Jun 2015 09:30:46 -0400 Subject: [PATCH 3/4] Modified to handle setting isActive for custom states --- scripts/zmpkg.pl.in | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) 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; From 1a0d4d2221ebe75f5b046161b43e655c95526780 Mon Sep 17 00:00:00 2001 From: Pliable Pixels Date: Sun, 21 Jun 2015 09:31:21 -0400 Subject: [PATCH 4/4] Console now shows custom run state in header (if applicable) --- web/skins/classic/views/console.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) 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') );