首页 > 解决方案 > 当我的服务器服务在 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

标签: linuxembedded-linuxsystemd

解决方案


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

PropagatesReloadTo=, ReloadPropagatedFrom=

一个或多个单元的空格分隔列表,该单元上的重新加载请求将被传播到该单元,或者另一个单元上的重新加载请求将分别传播到该单元。在单元上发出重新加载请求也会自动将重新加载请求排入所有单元上,重新加载请求应通过这两个设置传播到。

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


或在[Service]部分

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

override.conf在 bluetooth.service 上使用

systemctl edit bluetooth.service

在这里放

[Unit]
BindsTo=MyServ.service

推荐阅读