2
I wrote a simple app that read serial (over USB) TTY. The process itself just works fine but I cannot understand why systemd keeps killing the service in the first seconds after start.
The problem seems to be related to reading the TTY device. Also it can easily be reproduced using cat
[Unit]
Description=Retrieve and publish power consumption daemon
After=network.target
[Service]
User=power
#ExecStart=/usr/bin/erdf_json_dump
ExecStart=/bin/cat /dev/ttyACM0
Restart=on-abort
[Install]
WantedBy=multi-user.target
Here is the device /dev/ttyACM0 created by udev when the USB device is plugged. It is readable by cat
$ ls -l /dev/ttyACM0
crw-rw---- 1 root uucp 166, 0 Jul 3 09:01 /dev/ttyACM0
And the user account used to run the service which grants access to the device with the group uucp
$ id power
uid=1001(power) gid=1001(power) groups=1001(power),14(uucp)
Finally, here is the output of journalctl for the original service, the KeyboardInterrupt indicates a SIGTERM kill. Systemd does not give any log around the start/kill period
Jul 03 09:03:44 pi0 systemd[1]: Started Retrieve and publish power consumption Daemon.
Jul 03 09:03:47 pi0 erdf_json_dump[496]: INFO:root:exiting
Jul 03 09:03:47 pi0 erdf_json_dump[496]: Traceback (most recent call last):
Jul 03 09:03:47 pi0 erdf_json_dump[496]: File "/usr/bin/erdf_json_dump", line 118, in <module>
Jul 03 09:03:47 pi0 erdf_json_dump[496]: tm.loop()
Jul 03 09:03:47 pi0 erdf_json_dump[496]: File "/usr/bin/erdf_json_dump", line 97, in loop
Jul 03 09:03:47 pi0 erdf_json_dump[496]: for key, mask in self._select.select():
Jul 03 09:03:47 pi0 erdf_json_dump[496]: File "/usr/lib/python3.5/selectors.py", line 432, in select
Jul 03 09:03:47 pi0 erdf_json_dump[496]: fd_event_list = self._epoll.poll(timeout, max_ev)
Jul 03 09:03:47 pi0 erdf_json_dump[496]: KeyboardInterrupt
Jul 03 09:03:47 pi0 systemd[1]: erdf-publisher.service: Main process exited, code=exited, status=1/FAILURE
Jul 03 09:03:47 pi0 systemd[1]: erdf-publisher.service: Unit entered failed state.
Jul 03 09:03:47 pi0 systemd[1]: erdf-publisher.service: Failed with result 'exit-code'.
The same symptoms occur with cat, but with less logs.
Can someone give me some hints ?
To add some context, the kill is sent by systemd as soon as the file /dev/ttyACM0 is open()'ed in the service – lootr – 2016-07-09T11:54:07.773
I'm not sure I see the killing, but I have a similar issue running
cat
from a systemd unit. No problem outside, but there, I get that the resource is unavailable or busy (althoughfuser
returns nothing). If you have insight, please share... – Gauthier – 2019-11-04T16:00:35.497