【发布时间】:2020-05-27 05:03:48
【问题描述】:
我在嵌入式系统上使用 systemd 服务。我有一个网络服务,每次重新启动时都需要重新启动蓝牙。我该如何为此编写单元文件。我拥有的服务也被放入 systemd/user 而不是 systemd/system。 我尝试使用 PartOf=bluetooth.service 但没有奏效。
[Unit]
# Human readable name of the unit
Description=Python User Service
#Link it to bluetooth
After=bluetooth.service
Requires=bluetooth.service
PartOf=bluetooth.service
[Service]
# Command to execute when the service is started
ExecStart=/usr/bin/python3 /home/root/MyServ.py
# Disable Python's buffering of STDOUT and STDERR, so that output from the
# service shows up immediately in systemd's logs
Environment=PYTHONUNBUFFERED=1
# Automatically restart the service if it crashes
Restart=on-failure
# Our service will notify systemd once it is up and running
#Type=notify
Type=simple
# Use a dedicated user to run our service
User=root
[Install]
# Tell systemd to automatically start this service when the system boots
# (assuming the service is enabled)
WantedBy=default.target
【问题讨论】:
-
# Tell systemd to automatically start this service when the system boots # (assuming the service is enabled) WantedBy=default.target但最好使用WantedBy=multi-user.target,然后再使用systemd enable服务。 -
我将 default.target 更改为“multi-user.target”并开始看到“bluetooth.service not found”。然后我将其更改为“蓝牙”。它重新启动了我的服务,但它没有重新启动蓝牙,因为“systemctl status bluetooth”表明它已经运行了一个多小时。
标签: linux embedded-linux systemd