Modified to handle setting isActive for custom states
This commit is contained in:
parent
754091b55d
commit
e758d9bf7c
|
@ -55,6 +55,7 @@ use autouse 'Pod::Usage'=>qw(pod2usage);
|
||||||
$ENV{PATH} = '/bin:/usr/bin';
|
$ENV{PATH} = '/bin:/usr/bin';
|
||||||
$ENV{SHELL} = '/bin/sh' if exists $ENV{SHELL};
|
$ENV{SHELL} = '/bin/sh' if exists $ENV{SHELL};
|
||||||
delete @ENV{qw(IFS CDPATH ENV BASH_ENV)};
|
delete @ENV{qw(IFS CDPATH ENV BASH_ENV)};
|
||||||
|
my $store_state=""; # PP - will remember state name passed
|
||||||
|
|
||||||
logInit();
|
logInit();
|
||||||
|
|
||||||
|
@ -90,6 +91,7 @@ if ( !$command || $command !~ /^(?:start|stop|restart|status|logrot|version)$/ )
|
||||||
{ Id=>$id, Function=>$function, Enabled=>$enabled }
|
{ Id=>$id, Function=>$function, Enabled=>$enabled }
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
$store_state=$command; # PP - Remember the name that was passed to search in DB
|
||||||
$command = 'state';
|
$command = 'state';
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -149,6 +151,18 @@ if ( $command eq "state" )
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$sth->finish();
|
$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";
|
$command = "restart";
|
||||||
}
|
}
|
||||||
|
@ -159,6 +173,9 @@ if ( $command =~ /^(start|stop|restart)$/ )
|
||||||
# We have to detaint to keep perl from complaining
|
# We have to detaint to keep perl from complaining
|
||||||
$command = $1;
|
$command = $1;
|
||||||
|
|
||||||
|
# PP - if we are not switching to a custom state, zero out all isActive
|
||||||
|
resetStates() if (!$store_state);
|
||||||
|
|
||||||
if ( systemdRunning() && !calledBysystem() ) {
|
if ( systemdRunning() && !calledBysystem() ) {
|
||||||
qx(@BINDIR@/zmsystemctl.pl $command);
|
qx(@BINDIR@/zmsystemctl.pl $command);
|
||||||
$command = "";
|
$command = "";
|
||||||
|
@ -290,6 +307,19 @@ if ( $command eq "logrot" )
|
||||||
|
|
||||||
exit( $retval );
|
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
|
sub systemdRunning
|
||||||
{
|
{
|
||||||
my $result = 0;
|
my $result = 0;
|
||||||
|
|
Loading…
Reference in New Issue