AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / unix / 问题 / 696057
Accepted
kart-able
kart-able
Asked: 2022-03-20 01:46:10 +0800 CST2022-03-20 01:46:10 +0800 CST 2022-03-20 01:46:10 +0800 CST

Systemd 找不到蓝牙服务

  • 772

我在使用内核 5.15.28-1 的 Manjaro

我的问题与蓝牙有关。我有 bluez 5.61-1(我从 5.63-2 降级)。

我可以使用 systemctl 激活蓝牙,但不能从我编写的 systemd 服务激活:

#/etc/systemd/system/bt-restart.service

 [Unit]
 Description=restart bt and connect keypad

 [Service]
 Type=oneshot
 User=root

 RemainAfterExit=yes

 ExecStart=/usr/bin/sleep 1
 ExecStart=-/usr/lib/systemd/system/bluetooth
 ExecStart=/usr/bin/sleep 3
 ExecStart=/home/jcw/bin/enable-bt.sh

 [Install]
 WantedBy=multi-user.target

输出自

sudo systemctl status bt-restart

● bt-restart.service - restart bt and connect keypad
     Loaded: loaded (/etc/systemd/system/bt-restart.service; enabled; vendor preset: disabled)
     Active: active (exited) since Sat 2022-03-19 09:00:35 CET; 1h 27min ago
    Process: 2762 ExecStart=/usr/bin/sleep 1 (code=exited, status=0/SUCCESS)
    Process: 2763 ExecStart=/usr/lib/systemd/system/bluetooth (code=exited, status=0/SUCCESS)
    Process: 2764 ExecStart=/usr/bin/sleep 3 (code=exited, status=0/SUCCESS)
    Process: 2766 ExecStart=/home/jcw/bin/enable-bt.sh (code=exited, status=0/SUCCESS)
   Main PID: 2766 (code=exited, status=0/SUCCESS)
        CPU: 41ms

mars 19 08:59:50 jcw-k30amjafk31amj systemd[1]: Starting restart bt and connect keypad...
mars 19 08:59:51 jcw-k30amjafk31amj systemd[2763]: bt-restart.service: Executable /usr/lib/systemd/system/bluetooth missing,>
mars 19 09:00:35 jcw-k30amjafk31amj enable-bt.sh[2767]: Attempting to connect to 2B:24:13:DB:7C:99
mars 19 09:00:35 jcw-k30amjafk31amj enable-bt.sh[2767]: Failed to connect: org.bluez.Error.Failed
mars 19 09:00:35 jcw-k30amjafk31amj systemd[1]: Finished restart bt and connect keypad.

从Executable /usr/lib/systemd/system/bluetooth missing可以看出,systemd 没有找到 bluetooth.service。

但该文件存在。可以通过 systemctl 访问。所以呢?

编辑:第二行的结尾是“缺少可执行文件/usr/lib/systemd/system/bluetooth,跳过:没有这样的文件或目录”

systemd bluetooth
  • 1 1 个回答
  • 839 Views

1 个回答

  • Voted
  1. Best Answer
    telcoM
    2022-03-20T07:04:56+08:002022-03-20T07:04:56+08:00

    目录中应该没有可执行文件/usr/lib/systemd/system/。

    可能有一个/usr/lib/systemd/system/bluetooth.service,但它不是一个可执行文件:它只是一个服务定义文件,就像你自己的/etc/systemd/system/bt-restart.service.

    尽管您可以.service在命令中省略后缀,但systemctl您不能在ExecStart=定义中省略任何后缀,因此ExecStart=-/usr/lib/systemd/system/bluetooth没有任何意义。即使您指定.../bluetooth.service了 ,也不能以.service这种方式启动文件。

    如果您只想让您bt-restart.service在bluetooth.service运行时使用它,您应该在[Unit]您的部分添加两行bt-restart.service:

    Wants=bluetooth.service
    After=bluetooth.service
    

    即“bt-restart.service需要bluetooth.service运行(但如果系统在启动时失败,系统不应崩溃进入恢复模式),并且bt-restart.service应该在启动后 bluetooth.service运行。”

    那么你根本不需要这ExecStart=-/usr/lib/systemd/system/bluetooth条线。

    根据您所追求的确切行为,您可能希望使用BindsTo=或PartOf=代替Wants=.

    如果您明确希望在它正在运行时始终停止bluetooth.service并在您的 中重新启动它bt-restart.service,那么您应该将您的替换ExecStart=-/usr/lib/systemd/system/bluetooth为:

    ExecStart=/bin/systemctl restart bluetooth.service
    

    但是,如果您的目标是enable-bt.sh每次bluetooth.service启动或重新启动脚本时都运行,那么组合

    PartOf=bluetooth.service
    After=bluetooth.service
    

    应该做的工作。

    • 0

相关问题

  • journalctl 中的区分级别

  • 将默认编辑器更改为 vim for _ sudo systemctl edit [unit-file] _

  • systemd:如何在服务启动时运行脚本,而不编辑服务定义

  • 使用 systemd 看门狗支持重新启动应用程序

  • 使用键盘快捷键启动/停止 systemd 服务 [关闭]

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    模块 i915 可能缺少固件 /lib/firmware/i915/*

    • 3 个回答
  • Marko Smith

    无法获取 jessie backports 存储库

    • 4 个回答
  • Marko Smith

    如何将 GPG 私钥和公钥导出到文件

    • 4 个回答
  • Marko Smith

    我们如何运行存储在变量中的命令?

    • 5 个回答
  • Marko Smith

    如何配置 systemd-resolved 和 systemd-networkd 以使用本地 DNS 服务器来解析本地域和远程 DNS 服务器来解析远程域?

    • 3 个回答
  • Marko Smith

    dist-upgrade 后 Kali Linux 中的 apt-get update 错误 [重复]

    • 2 个回答
  • Marko Smith

    如何从 systemctl 服务日志中查看最新的 x 行

    • 5 个回答
  • Marko Smith

    Nano - 跳转到文件末尾

    • 8 个回答
  • Marko Smith

    grub 错误:你需要先加载内核

    • 4 个回答
  • Marko Smith

    如何下载软件包而不是使用 apt-get 命令安装它?

    • 7 个回答
  • Martin Hope
    user12345 无法获取 jessie backports 存储库 2019-03-27 04:39:28 +0800 CST
  • Martin Hope
    Carl 为什么大多数 systemd 示例都包含 WantedBy=multi-user.target? 2019-03-15 11:49:25 +0800 CST
  • Martin Hope
    rocky 如何将 GPG 私钥和公钥导出到文件 2018-11-16 05:36:15 +0800 CST
  • Martin Hope
    Evan Carroll systemctl 状态显示:“状态:降级” 2018-06-03 18:48:17 +0800 CST
  • Martin Hope
    Tim 我们如何运行存储在变量中的命令? 2018-05-21 04:46:29 +0800 CST
  • Martin Hope
    Ankur S 为什么 /dev/null 是一个文件?为什么它的功能不作为一个简单的程序来实现? 2018-04-17 07:28:04 +0800 CST
  • Martin Hope
    user3191334 如何从 systemctl 服务日志中查看最新的 x 行 2018-02-07 00:14:16 +0800 CST
  • Martin Hope
    Marko Pacak Nano - 跳转到文件末尾 2018-02-01 01:53:03 +0800 CST
  • Martin Hope
    Kidburla 为什么真假这么大? 2018-01-26 12:14:47 +0800 CST
  • Martin Hope
    Christos Baziotis 在一个巨大的(70GB)、一行、文本文件中替换字符串 2017-12-30 06:58:33 +0800 CST

热门标签

linux bash debian shell-script text-processing ubuntu centos shell awk ssh

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve