stelas / GCLog

GCLOG is a lightweight daemon running in the background and constantly reporting your Geiger counter readings to various radiation monitoring websites. With a small footprint and minimal dependencies it is aimed to run on Linux embedded computers.
https://www.gclog.de/
GNU General Public License v3.0
9 stars 1 forks source link

GCLog fails to stay running on debian 12.. #5

Open jult opened 1 year ago

jult commented 1 year ago

I did a make from the latest on here, created a systemd service gclog.service, containing:

[Unit]
Description=GClog radioactive data feeder
After=network.target

[Service]
ExecStart=/usr/local/bin/gclog -v -c /etc/gclog.conf
Restart=on-failure
RestartSec=20s

[Install]
WantedBy=default.target

Then this happens at boot:

2023-08-07T12:28:22.176925+02:00 greeny systemd[1]: Started gclog.service - GClog radioactive data feeder.
2023-08-07T12:28:22.796038+02:00 greeny gclog[2570]: Configuration:
2023-08-07T12:28:22.796192+02:00 greeny gclog[2570]: #011#011GQ GMC Geiger Counter on /dev/ttyUSB0 @ 0010002,
2023-08-07T12:28:22.796276+02:00 greeny gclog[2570]: #011#011Location: x
2023-08-07T12:28:22.796344+02:00 greeny gclog[2570]: #011#011netc.com: (null),
2023-08-07T12:28:22.796411+02:00 greeny gclog[2570]: #011#011radmon.org: x / xblahblah,
2023-08-07T12:28:22.796497+02:00 greeny gclog[2570]: #011#011safecast.org: xDidtfLG2YK / Device ID xx5,
2023-08-07T12:28:22.796567+02:00 greeny gclog[2570]: #011#011gmcmap.com: x45x7 / Device ID 5x75x05x750,
2023-08-07T12:28:22.796664+02:00 greeny gclog[2570]: #011#01160s interval
2023-08-07T12:28:22.797361+02:00 greeny gclog[2571]: Configuration:
2023-08-07T12:28:22.797475+02:00 greeny gclog[2571]: #011#011GQ GMC Geiger Counter on /dev/ttyUSB0 @ 0010002,
2023-08-07T12:28:22.797666+02:00 greeny gclog[2571]: #011#011Location: x
2023-08-07T12:28:22.797837+02:00 greeny gclog[2571]: #011#011netc.com: (null),
2023-08-07T12:28:22.797985+02:00 greeny gclog[2571]: #011#011radmon.org: x / xblahblah,
2023-08-07T12:28:22.798066+02:00 greeny gclog[2571]: #011#011safecast.org: xidtfLG2YK / Device ID xx5,
2023-08-07T12:28:22.798156+02:00 greeny gclog[2571]: #011#011gmcmap.com: x45x7 / Device ID 5x75x05x750,
2023-08-07T12:28:22.798275+02:00 greeny gclog[2571]: #011#01160s interval
2023-08-07T12:28:22.798401+02:00 greeny gclog[2571]: [DEBUG] Entering main loop...
2023-08-07T12:28:22.798677+02:00 greeny gclog[2571]: [DEBUG] Main loop exited. Cleaning up...
2023-08-07T12:28:22.799433+02:00 greeny systemd[1]: gclog.service: Deactivated successfully.

and the process just ends there. First it's strange it seems to run twice in a row after starting it from the service file, then it exits and deactivates, while nothing in the service would implicate this. SElinux or apparmor aren't running on this machine, so those can't be it. Furthermore, when I run it by hand from the commandline, just running /usr/local/bin/gclog -v -c /etc/gclog.conf it does just fine and keeps running in the background, Entering main loop without ending....

What am I doing wrong here?

stelas commented 1 year ago

GCLog spawns a child process on startup. To allow systemd to monitor this, add the Type=forking option to the service section.

The start routine would have to be adapted to the current requirements.

jult commented 1 year ago

OK, I think I have it functional now, this is the correct service:

[Unit]
Description=GCLog radioactive data feeder
After=network-online.target

[Service]
Type=forking
User=root
ExecStart=/root/io/gclog.sh
RemainAfterExit=yes

[Install]
WantedBy=multi-user.target

where /root/io/gclog.sh contains;

#!/bin/sh

gclog -v -c /etc/gclog.conf

I added the User root option because it will in some cases otherwise fail to run a shell script residing under /root. Either way, it works now! May the force be with you.

You could push this to your master, but I don't have the time to do so.

stelas commented 1 year ago

Great that it works now. As a starting point, I added a systemd service template.

jult commented 11 months ago

Great that it works now. As a starting point, I added a systemd service template.

This service file does not work (on deb 12 anyway). It starts and then fails to get data from the device. No sure why, but it only gets "ZERO" values. (Your service also runs /usr/bin/gclog not /usr/local/bin/gclog as stated in your howto, not that that matters, but still) Again, the only way I get it to function is by letting the service call gclog via a script as root. This is my /etc/systemd/system/gclog.service :

[Unit]
Description=GCLog radioactive data feeder
After=network-online.target

[Service]
Type=forking
User=root
ExecStart=/root/io/gclog.sh
RemainAfterExit=yes

[Install]
WantedBy=multi-user.target
theY4Kman commented 10 months ago

FWIW, I simply run gclog with the -d debug flag to disable the forking, allowing systemd to manage the process directly

[Unit]
Description=GCLog Daemon
After=network-online.target

[Service]
SyslogIdentifier=gclogd
Restart=always
RestartSec=5
Type=simple
ExecStart=/usr/bin/gclog -c /etc/gclog.conf -vv -d
TimeoutStopSec=30

[Install]
WantedBy=multi-user.target