Icinga / icinga2

The core of our monitoring platform with a powerful configuration language and REST API.
https://icinga.com/docs/icinga2/latest
GNU General Public License v2.0
2.03k stars 578 forks source link

Windows: daemon does not stop gracefully #7822

Open mcktr opened 4 years ago

mcktr commented 4 years ago

Describe the bug

On Windows the Icinga 2 daemon does not stop gracefully. The log does not contain information about the shutdown i.e. Received request to shut down. is missing. The log just stops without any log message.

To Reproduce

  1. Stop the Icinga 2 daemon on Windows.

    Powershell:

    Stop-Service icinga2

or

Shell:

net stop icinga2

or via graphical service manager.

Expected behavior

Having a look into the log file on Windows I would expect something like the following:

[2020-02-10 08:38:42 +0100] information/Application: Received request to shut down.
[2020-02-10 08:38:43 +0100] information/Application: Shutting down...
[2020-02-10 08:38:43 +0100] information/CheckerComponent: 'checker' stopped.
[2020-02-10 08:38:43 +0100] information/ApiListener: 'api' stopped.

But the log just stops without any information about the shutdown.

Your Environment

Additional context

Running the daemon in foreground mode and stopping it with CTRL+C triggers a gracefull shutdown. My guess is that stopping the Icinga 2 Windows service does not send the correct signal to the process to trigger a gracefull shutdown. This maybe is related to the new umbrella process handling.

Another guess is that the logger to early on Windows.

dnsmichi commented 4 years ago

Keep in mind that the Umbrella process was mainly invented for Linux/Unix. Windows already had this implemented with the exit 7 and reload handling. AFAIK this behavior on Windows is there for a long time.

mcktr commented 4 years ago

You are right, this behavior did not come with the umbrella process handling.

The related code is sitting here:

https://github.com/Icinga/icinga2/blob/2f820477379e9157b12ccdff3250ab48cd3df170/icinga-app/icinga.cpp#L826-L832

This terminates the Icinga 2 daemon process without any prior shutdown/stop handling

dnsmichi commented 4 years ago

Might be on purpose. I only remember that Windows services are a tricky beast.

Al2Klimov commented 2 years ago

Colleagues, do we care at all? After all only agents are on Windows and they're just command endpoints.

julianbrost commented 2 years ago

It looks like most tings needed are already there, i.e. you can notify the process and it shuts down. It's just that the wrapper service doesn't do that. Ideally that should only take a few lines of code change, so if someone figures out how to do this in the service and creates a PR to fix it, I'd accept it. It's just that this issue is something I'd prioritize for fixing ourselves.