【问题标题】:How to restart bluetooth service when my server service restarts in systemd当我的服务器服务在 systemd 中重新启动时如何重新启动蓝牙服务
【发布时间】: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


【解决方案1】:

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

PropagatesReloadTo=, ReloadPropagatedFrom=

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

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


或在[Service] 部分

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

或者在 bluetooth.service 上使用override.conf

systemctl edit bluetooth.service

放在这里

[Unit]
BindsTo=MyServ.service

【讨论】:

    猜你喜欢
    • 2011-04-21
    • 1970-01-01
    • 2019-08-23
    • 2017-08-11
    • 2015-10-28
    • 2017-05-07
    • 2021-11-20
    • 1970-01-01
    相关资源
    最近更新 更多