我计划使用树莓派作为通过 WiFi/以太网的 USB 隧道,所以我编写了脚本来自动绑定 udev、编译并插入内核模块,现在我被守护进程困住了。我之前的方法在旧系统上运行良好,守护进程在 rc.local 中启动。
我添加的内容/etc/systemd/system/usbipd.service:
[Unit]
Description=usbip host daemon
After=network-online.target
Wants=network-online.target
[Service]
Type=simple
Restart=always
ExecStart=/usr/sbin/usbipd -D
[Install]
WantedBy=multi-user.target
我在系统日志中得到的内容:
Sep 9 23:47:25 raspi-conn systemd[1]: Started usbip host daemon.
...
Sep 9 23:47:26 raspi-conn systemd[1]: usbipd.service: Succeeded.
Sep 9 23:47:27 raspi-conn systemd[1]: usbipd.service: Scheduled restart job, restart counter is at 1.
...
Sep 9 23:47:27 raspi-conn systemd[1]: Stopped usbip host daemon.
Sep 9 23:47:27 raspi-conn systemd[1]: Started usbip host daemon.
...
Sep 9 23:47:27 raspi-conn usbipd: usbipd: info: starting usbipd (usbip-utils 2.0)
Sep 9 23:47:27 raspi-conn usbipd: usbipd: info: listening on 0.0.0.0:3240
Sep 9 23:47:27 raspi-conn usbipd: usbipd: info: listening on :::3240
Sep 9 23:47:27 raspi-conn usbipd: usbipd: info: shutting down usbipd
Sep 9 23:47:27 raspi-conn systemd[1]: usbipd.service: Succeeded.
...
Sep 9 23:47:27 raspi-conn systemd[1]: usbipd.service: Scheduled restart job, restart counter is at 2.
...
Sep 9 23:47:27 raspi-conn systemd[1]: Stopped usbip host daemon.
...
Sep 9 23:47:27 raspi-conn systemd[1]: Started usbip host daemon.
...
Sep 9 23:47:28 raspi-conn usbipd: usbipd: info: starting usbipd (usbip-utils 2.0)
Sep 9 23:47:28 raspi-conn usbipd: usbipd: info: listening on 0.0.0.0:3240
Sep 9 23:47:28 raspi-conn usbipd: usbipd: info: listening on :::3240
...
Sep 10 08:15:17 raspi-conn systemd[1]: usbipd.service: State 'stop-sigterm' timed out. Killing.
Sep 10 08:15:17 raspi-conn systemd[1]: usbipd.service: Killing process 560 (usbipd) with signal SIGKILL.
Sep 10 08:15:17 raspi-conn systemd[1]: usbipd.service: Failed with result 'timeout'.
Sep 10 08:15:17 raspi-conn systemd[1]: usbipd.service: Scheduled restart job, restart counter is at 3.
Sep 10 08:15:17 raspi-conn systemd[1]: Stopped usbip host daemon.
Sep 10 08:15:17 raspi-conn systemd[1]: Started usbip host daemon.
Sep 10 08:15:17 raspi-conn usbipd: usbipd: info: starting usbipd (usbip-utils 2.0)
Sep 10 08:15:17 raspi-conn usbipd: usbipd: info: listening on 0.0.0.0:3240
Sep 10 08:15:17 raspi-conn usbipd: usbipd: info: listening on :::3240
...
Sep 10 08:16:47 raspi-conn systemd[1]: usbipd.service: State 'stop-sigterm' timed out. Killing.
Sep 10 08:16:47 raspi-conn systemd[1]: usbipd.service: Killing process 1449 (usbipd) with signal SIGKILL.
Sep 10 08:16:47 raspi-conn systemd[1]: usbipd.service: Failed with result 'timeout'.
Sep 10 08:16:47 raspi-conn systemd[1]: usbipd.service: Scheduled restart job, restart counter is at 4.
Sep 10 08:16:47 raspi-conn systemd[1]: Stopped usbip host daemon.
Sep 10 08:16:47 raspi-conn systemd[1]: Started usbip host daemon.
Sep 10 08:16:47 raspi-conn usbipd: usbipd: info: starting usbipd (usbip-utils 2.0)
Sep 10 08:16:47 raspi-conn usbipd: usbipd: info: listening on 0.0.0.0:3240
Sep 10 08:16:47 raspi-conn usbipd: usbipd: info: listening on :::3240
...
Sep 10 08:18:18 raspi-conn systemd[1]: usbipd.service: State 'stop-sigterm' timed out. Killing.
Sep 10 08:18:18 raspi-conn systemd[1]: usbipd.service: Killing process 1482 (usbipd) with signal SIGKILL.
Sep 10 08:18:18 raspi-conn systemd[1]: usbipd.service: Failed with result 'timeout'.
Sep 10 08:18:18 raspi-conn systemd[1]: usbipd.service: Scheduled restart job, restart counter is at 5.
Sep 10 08:18:18 raspi-conn systemd[1]: Stopped usbip host daemon.
Sep 10 08:18:18 raspi-conn systemd[1]: Started usbip host daemon.
Sep 10 08:18:18 raspi-conn usbipd: usbipd: info: starting usbipd (usbip-utils 2.0)
Sep 10 08:18:18 raspi-conn usbipd: usbipd: info: listening on 0.0.0.0:3240
Sep 10 08:18:18 raspi-conn usbipd: usbipd: info: listening on :::3240
我对 systemd 内部没有太多经验,我不知道如何调试它。没有明确的原因说明进程被停止然后重新启动,看起来 systemd 没有获取进程状态。
答案1
你的Type=
和ExecStart=
定义不匹配。
您已经设置了Type=Simple
,它期望一个程序不会分叉到后台,但您使用-D
将进程分叉到后台的参数。
要么-D
省略参数,要么使用Type=forking
.
我更喜欢第一个选项,因为它允许 systemd 处理日志记录。