liske / needrestart

Restart daemons after library updates.
GNU General Public License v2.0
420 stars 67 forks source link

Exit codes are not documented in the man page #261

Open kpinc opened 1 year ago

kpinc commented 1 year ago

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.

l0f4r0 commented 1 year ago

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

phrozen77 commented 5 months ago

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).

nlsschmdt commented 2 months ago

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.

kpinc commented 2 months ago

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