我编写了一个简单的应用程序来读取串行(通过 USB)TTY。该过程本身运行良好,但我不明白为什么 systemd 在启动后的前几秒内不断终止服务。
问题似乎与读取 TTY 设备有关。也可以使用 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
这是设备/dev/ttyACM0当 USB 设备插入时由 udev 创建。它可被 cat 读取
$ ls -l /dev/ttyACM0
crw-rw---- 1 root uucp 166, 0 Jul 3 09:01 /dev/ttyACM0
以及用于运行该服务的用户帐户,该服务授予该组对设备的访问权限统一通信协议
$ id power
uid=1001(power) gid=1001(power) groups=1001(power),14(uucp)
最后,这是 journalctl 的输出原服务,KeyboardInterrupt 表示 SIGTERM 终止。Systemd 在启动/终止期间不提供任何日志
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'.
猫也出现了同样的症状,但日志较少。
有人可以给我一些提示吗?