[pve-devel] [PATCH ha-manager v2] is_node_shutdown: check for correct systemd targets

Thomas Lamprecht t.lamprecht at proxmox.com
Thu Jan 5 12:26:34 CET 2017


any comments?


On 12/20/2016 09:33 AM, Thomas Lamprecht wrote:
> shutdown.target is active every time when the node shuts down, be it
> reboot, poweroff, halt or kexec.
> As we want to return true only when the node powers down without a
> restart afterwards this was wrong.
> Match only poweroff.target and halt.target, those two systemd targets
> which cause a node shutdown without a reboot.
>
> Enhance also the regular expression so that we do not falsely match
> when a target includes poweroff.target in its name, e.g.
> not-a-poweroff.target
>
> Also pass the 'full' flag to systemctl to ensure that target name do
> not get ellipsized or cut off.
>
> Signed-off-by: Thomas Lamprecht <t.lamprecht at proxmox.com>
> ---
>
> changes since v1:
> * use a regex which avoids return true by matching only a sub part of a target
>    name, like not-a-poweroff.target
> * add the '--full' flag to systemctl call to ensure nothing gets cut off
>
>   src/PVE/HA/Env/PVE2.pm | 5 +++--
>   1 file changed, 3 insertions(+), 2 deletions(-)
>
> diff --git a/src/PVE/HA/Env/PVE2.pm b/src/PVE/HA/Env/PVE2.pm
> index 4fdab2f..382b61c 100644
> --- a/src/PVE/HA/Env/PVE2.pm
> +++ b/src/PVE/HA/Env/PVE2.pm
> @@ -89,10 +89,11 @@ sub is_node_shutdown {
>       my $code = sub {
>   	my $line = shift;
>   
> -	$shutdown = 1 if ($line =~ m/shutdown\.target/);
> +	# ensure we match the full unit name by matching /^JOB_ID UNIT /
> +	$shutdown = 1 if ($line =~ m/^\d+\s+(poweroff|halt)\.target\s+/);
>       };
>   
> -    my $cmd = ['/bin/systemctl', 'list-jobs'];
> +    my $cmd = ['/bin/systemctl', '--full', 'list-jobs'];
>       eval { PVE::Tools::run_command($cmd, outfunc => $code, noerr => 1); };
>   
>       return $shutdown;





More information about the pve-devel mailing list