我正在嵌入式系统上使用systemd服务。我有一个Web服务,每次重新启动时都需要重新启动蓝牙。我如何为此编写单位文件。我拥有的服务也放到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
在[Unit]
部分,您可以重新加载服务
PropagatesReloadTo =,ReloadPropagatedFrom =
以空格分隔的一个或多个单元的列表,该单元上的重载请求将传播到该单元上或在该单元上的重载请求其他单元将分别传播到该单元。发行在单元上重新加载请求还将自动将重新加载请求加入到通过这两个设置将重新加载请求传播到的所有单元上。
它发送蓝牙命令以通过dbus重新加载。不杀死守护程序,只需重新读取配置即可。
或在[Service]
部分上
ExecStopPost=/usr/bin/systemctl restart bluetooth.service
或在bluetooth.service上使用override.conf
systemctl edit bluetooth.service
然后放在这里
[Unit]
BindsTo=MyServ.service