当我的服务器服务在 systemd 中重新启动时如何重新启动蓝牙服务

How to restart bluetooth service when my server service restarts in systemd

我在嵌入式系统上使用 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

[Unit] 部分您可以重新加载服务

PropagatesReloadTo=, ReloadPropagatedFrom=

A space-separated list of one or more units where reload requests on this unit will be propagated to, or reload requests on the other unit will be propagated to this unit, respectively. Issuing a reload request on a unit will automatically also enqueue a reload request on all units that the reload request shall be propagated to via these two settings.

它发送bluetoothd 命令通过dbus 重新加载。不是杀死守护进程,只是重新读取配置。


或在 [Service] 部分

ExecStopPost=/usr/bin/systemctl restart bluetooth.service

或在 bluetooth.service

上使用 override.conf
systemctl edit bluetooth.service

这里放

[Unit]
BindsTo=MyServ.service