INTERACT FORUM

Please login or register.

Login with username, password and session length
Advanced search  
Pages: [1]   Go Down

Author Topic: More graceful SIGTERM?  (Read 1123 times)

BryanC

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 2665
More graceful SIGTERM?
« on: May 25, 2023, 06:18:47 pm »

I was having issues with MC remembering some library changes after stopping the program with systemd, such as the recent commands list, playlist deletions, profiles, settings, etc (likely anything committed on program exit). I found that shutting down MC using File>Exit or the window manager buttons wouldn't trigger this issue and narrowed it down to the MC process getting killed by systemd using SIGTERM (I also tried SIGHUP as well as various other KillMode= and KillSignal= settings to no avail).

Currently I'm working around this by calling MCC_EXIT in the ExecStop= directive and setting KillMode=none to disable systemd from issuing any kill signals and instead relying on the MCC command to cleanly shut down MC:

Code: [Select]
[Unit]
Description=JRiver Media Center 31
After=graphical.target

[Service]
Type=simple
Environment=DISPLAY=:0
Environment=XAUTHORITY=/run/user/1000/.mutter-Xwaylandauth.HW2B51
ExecStart=/usr/bin/mediacenter31
ExecStop=/usr/bin/mc31 /MCC 20007
KillMode=none
Restart=always
RestartSec=10
TimeoutStopSec=30

[Install]
WantedBy=graphical.target

This works swimmingly (my library changes are retained after program restart) but setting KillMode=none and relying solely on ExecStop= is strongly recommended against by the docs (since systemd can't know for sure that the process has exited--what if the stub is missing or fails?). If/when possible, it's better to have the program respond to SIGTERM properly with a clean shutdown. Also, I vaguely recall a discussion on this years ago but can't seem to locate it now, so perhaps there's some other reason that MC is treating SIGTERM more like a SIGKILL/SIGHUP?
Logged

bob

  • Administrator
  • Citizen of the Universe
  • *****
  • Posts: 13875
Re: More graceful SIGTERM?
« Reply #1 on: May 26, 2023, 09:54:41 am »

SIGHUP is trapped by MC to do a clean shutdown.

You can do an easy test of this from a terminal with MC running.

killall -HUP mediacenter31

(install killall if necessary).

Sending a MCC via the stub should work as well but it's in /usr/lib/jriver/MC31/mc31 not /usr/bin.

Logged

Hendrik

  • Administrator
  • Citizen of the Universe
  • *****
  • Posts: 10944
Re: More graceful SIGTERM?
« Reply #2 on: May 26, 2023, 10:15:45 am »

Should probably trap TERM as well, its technically the correct one to use.

If someone wants instant shutdown, thats what KILL would be for.
Logged
~ nevcairiel
~ Author of LAV Filters

BryanC

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 2665
Re: More graceful SIGTERM?
« Reply #3 on: May 26, 2023, 12:26:35 pm »

SIGHUP is trapped by MC to do a clean shutdown.

You can do an easy test of this from a terminal with MC running.

killall -HUP mediacenter31

(install killall if necessary).

Sending a MCC via the stub should work as well but it's in /usr/lib/jriver/MC31/mc31 not /usr/bin.

(I typically symlink the stub to /usr/bin so it's in my PATH)

Killing MC with `killall -HUP mediacenter31` doesn't save my right-click recent commands either. Can you reproduce? Interestingly it takes longer to stop the process with SIGHUP (so it looks like it's trapped and trying to cleanly shutdown) than with SIGTERM or SIGKILL, so maybe something else is awry.
Logged

bob

  • Administrator
  • Citizen of the Universe
  • *****
  • Posts: 13875
Re: More graceful SIGTERM?
« Reply #4 on: May 26, 2023, 01:32:26 pm »

(I typically symlink the stub to /usr/bin so it's in my PATH)

Killing MC with `killall -HUP mediacenter31` doesn't save my right-click recent commands either. Can you reproduce? Interestingly it takes longer to stop the process with SIGHUP (so it looks like it's trapped and trying to cleanly shutdown) than with SIGTERM or SIGKILL, so maybe something else is awry.
We are NOT trapping either SIGTERM or SIGKILL. Both will simply exit messily.
Exiting via SIGHUP should be the same as hitting the x button or exit in MC. It exits the run loop and lets the program close normally (including signing out of any network DLNA devices which is what actually takes time).
Logged

bob

  • Administrator
  • Citizen of the Universe
  • *****
  • Posts: 13875
Re: More graceful SIGTERM?
« Reply #5 on: May 26, 2023, 01:34:24 pm »

Should probably trap TERM as well, its technically the correct one to use.

If someone wants instant shutdown, thats what KILL would be for.
Not seeing a lot of difference with regards to a non-daemon program between TERMINATE and HANGUP
I could add TERM though.

Logged

BryanC

  • MC Beta Team
  • Citizen of the Universe
  • *****
  • Posts: 2665
Re: More graceful SIGTERM?
« Reply #6 on: May 26, 2023, 01:59:33 pm »

We are NOT trapping either SIGTERM or SIGKILL. Both will simply exit messily.
Exiting via SIGHUP should be the same as hitting the x button or exit in MC. It exits the run loop and lets the program close normally (including signing out of any network DLNA devices which is what actually takes time).

I'm only testing with SIGHUP from here on (honestly I don't care if I'm using SIGHUP/SIGTERM as long as one of them works correctly).

It looks like SIGHUP is acting differently for me (using killall -HUP mediacenter31) than using the internal exit mechanisms. I just tested in a Debian 11 VM and could reproduce on a fresh install. I'm only testing right-click command history for brevity.
Logged

bob

  • Administrator
  • Citizen of the Universe
  • *****
  • Posts: 13875
Re: More graceful SIGTERM?
« Reply #7 on: May 26, 2023, 03:23:36 pm »

I'm only testing with SIGHUP from here on (honestly I don't care if I'm using SIGHUP/SIGTERM as long as one of them works correctly).

It looks like SIGHUP is acting differently for me (using killall -HUP mediacenter31) than using the internal exit mechanisms. I just tested in a Debian 11 VM and could reproduce on a fresh install. I'm only testing right-click command history for brevity.
It's possible I suppose that exiting the mainloop isn't running the same sequence of closing/saving.
I'll take a look at it when I get a chance.
Thanks.
Logged
Pages: [1]   Go Up