patchman icon indicating copy to clipboard operation
patchman copied to clipboard

Detect if reboot is required on RHEL and CentOS >= 7

Open ocnbb opened this issue 4 years ago • 2 comments

Hi,

do you think it would be possible to add this (or something like that) to patchman-client at reboot_required() to also detect if a reboot is required on RHEL and CentOS >= 7 ?

    # On RHEL and CentOS >= 7 clients, the yum-utils or dnf
    # package needs to be installed for this to work.
    if check_command_exists needs-restarting ; then
        if [[ $(needs-restarting -r >/dev/null) -eq 1 ]]; then
            reboot=True
        else
            reboot=ServerCheck
        fi
    elif check_command_exists dnf ; then
        if [[ $(dnf needs-restarting -r >/dev/null) -eq 1 ]]; then
            reboot=True
        else
            reboot=ServerCheck
        fi
    fi

ocnbb avatar Apr 16 '21 11:04 ocnbb

Looks good, please submit a PR and I'll test it.

furlongm avatar Apr 16 '21 14:04 furlongm

@ocnbb

If you add ; echo $? to your command substitution, then it should work as expected. => $(needs-restarting -r >/dev/null ; echo $?) -eq 1

Otherwise it won't ouput the correct linux status code. I tested it and it is now working as expected.

prismisch avatar Oct 27 '22 14:10 prismisch