linux - 无法使用 systemctl 以 root 身份运行脚本

标签 linux bluetooth debian systemd

我需要在 Debian linux 启动时将补丁 ram 应用到蓝牙芯片。此补丁使用 /dev/mem 重置 GPIO。此更新的蓝牙初始化脚本包含在 /etc/init.d/bluetooth 中。

我的bluetooth.service

[Unit]
Description=Bluetooth service
Documentation=man:bluetoothd(8)

[Service]
Type=dbus
BusName=org.bluez
ExecStart=/etc/init.d/bluetooth start
User=root
NotifyAccess=main

[Install]
WantedBy=bluetooth.target
Alias=dbus-org.bluez.service

但是,当我重新启动时,我收到一条错误消息“无法打开/dev/mem:不允许操作”

我知道 /dev/mem 只能由 root 访问,但我不是以 root 身份运行我的初始化脚本吗?

最佳答案

明明说你没有运行脚本的权限,你可以 您需要以 root 用户身份运行脚本 ExecStart=/etc/init.d/bluetooth 启动 此命令应以根用户身份运行

只需以 root 身份登录并重新运行脚本

系统启动时运行脚本

  1. 在/etc/init.d/目录中创建一个名为 bluetooth.service 的脚本(以 root 身份登录) vi/etc/init.d/bluetooth.service

  2. 设置脚本的可执行权限: chmod +x/etc/init.d/bluetooth.service

  3. 确保每次 Debian Linux 系统启动/启动时执行此脚本:

    update-rc.d bluetooth.service 默认为 100

其中,bluetooth.service: 是你的启动脚本名称 defaults :参数“defaults”指的是默认运行级别,即 2 到 5。 100 :数字 100 表示脚本将在任何包含数字 101 的脚本之前执行。 只需运行命令

ls –l /etc/rc3.d/

此命令将使用数字软链接(soft link)到/etc/init.d。

下次您重新启动系统时,您的自定义命令或脚本将通过 bluetooth.services 执行。对

  1. 在系统启动时执行shell脚本 打开/etc/init.d/目录下的 bluetooth.service 文件

关于linux - 无法使用 systemctl 以 root 身份运行脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31258141/

相关文章:

android - Polar Wearlink 蓝牙数据包

Android 蓝牙套接字关闭 : read return: -1

android - 以编程方式,如何识别信标是属于 Eddystone 还是 iBeacon?

Debian 挤压和设置 ulimit

linux - 虚拟机: virtual port serial between 2 vm

mysql - SQLSTATE[HY000] : General error: 2053 update/delete

linux - Linux 中的进程间通信

regex - 使用正则表达式列出 Linux 驱动程序

linux - 配置为静态 IP 的 Raspberry Pi 也获得 DHCP IP

android - 如何在禁用 NEON 的情况下在 aarch64 上编译 wxwidgets