linux - 当我的服务器服务在 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=
一个或多个单元的空格分隔列表,该单元上的重新加载请求将被传播到该单元,或者另一个单元上的重新加载请求将分别传播到该单元。在单元上发出重新加载请求也会自动将重新加载请求排入所有单元上,重新加载请求应通过这两个设置传播到。
它通过 dbus 发送 bluetoothd 命令以重新加载。不杀死守护进程,只是重新读取配置。
或在[Service]
部分
ExecStopPost=/usr/bin/systemctl restart bluetooth.service
或override.conf
在 bluetooth.service 上使用
systemctl edit bluetooth.service
在这里放
[Unit]
BindsTo=MyServ.service
推荐阅读
- css - 如何在垂直对齐的 Angular Material 选项卡(mat-tabs)上启用分页?
- paypal - PayPal 智能结账按钮是否容易受到攻击?
- jenkins - Jenkins Webhook Header 作为 Shell 脚本的参数
- cmake - 是否有一种解决方法可以在 Windows 下的 CMake 中设置相对 RPATH
- javascript - 查找 HTML 元素的最佳方法是什么
- regex - 如何检查正则表达式是否匹配所有目标字符串?
- django - 如何在django中更改manytomany表的主键
- multithreading - 在 QT 中使用 QtConcurrent 但主线程再次冻结
- java - Java:无法使用 Java-Streams 过滤 ArrayList
- java - 测试 Web 层时 MockMvc 为空