'systemctl stop' sends SIGKILL not SIGTERM on RPi

535 views
Skip to first unread message

Graham Eddy

unread,
Apr 2, 2021, 10:36:50 AM4/2/21
to weewx...@googlegroups.com
using the provided weewx.service on an RPi, ‘sudo systemctl stop weewx’ sends SIGKILL instantly (twice), which is a very unclean termination of weewx and causes me problems. has anyone encountered this and has a proper fix?

so far as i can tell from the manuals (particularly ‘systemd.kill' and ‘systemd.service’), this is defective behaviour by systemd - it should send a SIGTERM followed by a SIGKILL (if necessary) 90 secs later by default. instead, i can only stop it sending SIGKILL by setting ‘FinalKillSignal=SIGTERM’ in weewx.service, where systemd sends SIGTERM twice instead. ‘KillSignal=SIGTERM’ is ignored

my workaround is ‘SendSIGKILL=no’ in weewx.service, which nicely sends SIGTERM for clean shutdown, but there is no followup SIGwhatever for contingent termination of rogue process(es)

weewx.service with workaround is:
# systemd configuration for weewx

[Unit]
Description=weewx weather system
Requires=time-sync.target
After=time-sync.target
RequiresMountsFor=/home

[Service]
ExecStart=/home/weewx/bin/weewxd --daemon --pidfile=/run/weewx/weewx.pid /home/weewx/weewx.conf
ExecReload=/bin/kill -HUP $MAINPID
Type=forking
PIDFile=/run/weewx/weewx.pid
User=weewx
Group=weewx
SendSIGKILL=no  # workaround to stop SIGKILL sent instantly (systemd bug)

[Install]
WantedBy=multi-user.target

Tom Keffer

unread,
Apr 2, 2021, 10:42:35 AM4/2/21
to weewx-user
SIGKILL is unclean behavior, but it should not cause any harm. The only state worth worrying about is the database and, there, all writes are done as transactions. If the SIGKILL happens in the middle of one, it will not be committed.

Of course, that's the theory!

--
You received this message because you are subscribed to the Google Groups "weewx-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to weewx-user+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/weewx-user/57F87F51-50BC-4359-A437-F8CDEF455BB3%40gmail.com.

Graham Eddy

unread,
Apr 2, 2021, 10:45:24 AM4/2/21
to weewx...@googlegroups.com
some of my services do have state that i need to save on termination, so it is important to me

mwall

unread,
Apr 2, 2021, 5:34:42 PM4/2/21
to weewx-user
KILL is definitely not desirable.  i'm debugging this now on centos with systemd, weewx, and rtl_433.

for example, the sdr driver spawns the rtl_433 command, and if you kill weewx, you end up with a rogue process, and the next time you start weewx, weewx will fail.

as another example, if you are doing database activities, sending a kill could end up in lost data, not because of database transaction atomicity (databases take care of that), but because there can be data in weewx that is not yet inserted.

as another example, sometimes it takes weewx awhile to generate a report.  so the 60-second default of systemd is not appropriate.  we probably should default to a 5 minute default (assuming that no one will have a system where the report generation takes longer than an archive interval, at least not intentionally).

bell...@gmail.com

unread,
Apr 11, 2022, 3:14:17 PM4/11/22
to weewx-user
I'm seeing this on all my Pis and my Ubuntu VM. I'm no systemd expert, but a created a pull request that works for me. 
rich

Reply all
Reply to author
Forward
0 new messages