Modified to handle setting isActive for custom states

This commit is contained in:
Pliable Pixels 2015-06-21 09:30:46 -04:00
parent 754091b55d
commit e758d9bf7c
1 changed files with 30 additions and 0 deletions

View File

@ -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;