needrestart icon indicating copy to clipboard operation
needrestart copied to clipboard

Exit codes are not documented in the man page

Open kpinc opened this issue 2 years ago • 4 comments

Hi,

There is no documentation of needrestart's exit codes. At least not in the man page needrestart(1). Knowing exit codes could be useful. For example, when writing a shell script to email needrestart output (Issue# 24, email frontend https://github.com/liske/needrestart/issues/24) the exit code might reveal whether or not anything needs restarting and so whether or not to send an email.

kpinc avatar Jan 18 '23 16:01 kpinc

I'm not sure needrestart exits differently than 0 by default (I've not made exhaustive tests though but right now it's exiting 0 should my user session is running outdated binaries or not...).

However, you can activate nagios mode with -p switch (equivalent of -t switch with checkrestart) and then you have different exit codes, nagios-compatible, depending on the situation. Those return codes are documented by Nagios itself here: https://assets.nagios.com/downloads/nagioscore/docs/nagioscore/4/en/pluginapi.html

l0f4r0 avatar Jun 23 '23 16:06 l0f4r0

However, you can activate nagios mode with -p switch (equivalent of -t switch with checkrestart) and then you have different exit codes, nagios-compatible, depending on the situation.

I think it does, yes - at least i'm seeing 0 as well as 128 when being run as part of an Ansible playbook.

I tried your suggestion of adding "-p" - however, it seems it's just doing the output anymore, no more service restarts seem to happen..

Relevant config in my playbook:

    - name: Restart services if needed
      ansible.builtin.command: needrestart -r a -p
      register: returned
      changed_when: returned.rc != 0

If anyone has helpful pointers on how to handle that, i'd really appreciate it (just getting my feet wet with Ansible).

phrozen77 avatar Apr 10 '24 16:04 phrozen77

I'm in the same boat using needrestart -r -a from ansible. Occasionally I see return code 128 with empty stderr and empty stdout. This is happening for months now, but I can not find out what is causing it. Running needrestart again leads to exit code 0. I would really like to know the meaning of the return code 128 to be able to decide on how to handle those situations.

nlsschmdt avatar Jul 08 '24 07:07 nlsschmdt

On Mon, 08 Jul 2024 00:25:31 -0700 nlsschmdt @.***> wrote:

I'm in the same boat using needrestart -r -a from ansible. Occasionally I see return code 128 with empty stderr and empty stdout. This is happening for months now, but I can not find out what is causing it. Running needrestart again leads to exit code 0. I would really like to know the meaning of the return code 128 to be able to decide on how to handle those situations.

FWIW, shell sets the high bit in the status byte to 1 (aka 128) when the process exits due to receipt of a signal. I am unclear on how this relates to lower-level system calls, if it does at all.

Regards,

Karl @.***> Free Software: "You don't pay back, you pay forward." -- Robert A. Heinlein

kpinc avatar Jul 11 '24 05:07 kpinc