systemctl disable name.service在重新启动后不会保留

问题描述 投票:0回答:2

我试图在启动时找到一种在Ubuntu 16.04上禁用蓝牙的方法,我在网上遇到的一种方法就是使用systemd

基本上

首先,停止服务:

sudo systemctl stop bluetooth.service

然后禁用它:

sudo systemctl禁用bluetooth.service

校验:

sudo systemctl status bluetooth.service

https://askubuntu.com/questions/744640/best-way-to-deactivate-bluetooth-on-system-startup-with-systemd-and-not-upstar

但每次我重新启动它重新开启,我找不到任何在线抱怨systemd disable命令不能像我的情况一样工作

甚至在ubuntu维基上,它说它应该工作我做错了什么?

https://wiki.ubuntu.com/SystemdForUpstartUsers

这是我运行这些命令时的输出

    mohamed@mohamed-UX330UAK:~$ sudo systemctl stop bluetooth.service
[sudo] password for mohamed: 
mohamed@mohamed-UX330UAK:~$ sudo systemctl disable bluetooth.service
Synchronizing state of bluetooth.service with SysV init with /lib/systemd/systemd-sysv-install...
Executing /lib/systemd/systemd-sysv-install disable bluetooth
insserv: warning: current start runlevel(s) (empty) of script `bluetooth' overrides LSB defaults (2 3 4 5).
insserv: warning: current stop runlevel(s) (0 1 2 3 4 5 6) of script `bluetooth' overrides LSB defaults (0 1 6).
insserv: warning: current start runlevel(s) (empty) of script `bluetooth' overrides LSB defaults (2 3 4 5).
insserv: warning: current stop runlevel(s) (0 1 2 3 4 5 6) of script `bluetooth' overrides LSB defaults (0 1 6).
mohamed@mohamed-UX330UAK:~$ sudo systemctl status bluetooth.service
● bluetooth.service - Bluetooth service
   Loaded: loaded (/lib/systemd/system/bluetooth.service; disabled; vendor prese
   Active: inactive (dead) since Wed 2017-04-26 19:56:04 AEST; 23s ago
     Docs: man:bluetoothd(8)
 Main PID: 882 (code=exited, status=0/SUCCESS)
   Status: "Quitting"

Apr 26 19:42:19 mohamed-UX330UAK bluetoothd[882]: Endpoint registered: sender=:1
Apr 26 19:42:19 mohamed-UX330UAK bluetoothd[882]: Endpoint registered: sender=:1
Apr 26 19:42:19 mohamed-UX330UAK bluetoothd[882]: RFCOMM server failed for Heads
Apr 26 19:42:34 mohamed-UX330UAK bluetoothd[882]: Endpoint unregistered: sender=
Apr 26 19:42:34 mohamed-UX330UAK bluetoothd[882]: Endpoint unregistered: sender=
Apr 26 19:56:04 mohamed-UX330UAK systemd[1]: Stopping Bluetooth service...
Apr 26 19:56:04 mohamed-UX330UAK bluetoothd[882]: Terminating
Apr 26 19:56:04 mohamed-UX330UAK bluetoothd[882]: Endpoint unregistered: sender=
Apr 26 19:56:04 mohamed-UX330UAK bluetoothd[882]: Endpoint unregistered: sender=
Apr 26 19:56:04 mohamed-UX330UAK systemd[1]: Stopped Bluetooth service.
lines 1-17/17 (END)...skipping...
● bluetooth.service - Bluetooth service
   Loaded: loaded (/lib/systemd/system/bluetooth.service; disabled; vendor prese
   Active: inactive (dead) since Wed 2017-04-26 19:56:04 AEST; 23s ago
     Docs: man:bluetoothd(8)
 Main PID: 882 (code=exited, status=0/SUCCESS)
   Status: "Quitting"

Apr 26 19:42:19 mohamed-UX330UAK bluetoothd[882]: Endpoint registered: sender=:1
Apr 26 19:42:19 mohamed-UX330UAK bluetoothd[882]: Endpoint registered: sender=:1
Apr 26 19:42:19 mohamed-UX330UAK bluetoothd[882]: RFCOMM server failed for Heads
Apr 26 19:42:34 mohamed-UX330UAK bluetoothd[882]: Endpoint unregistered: sender=
Apr 26 19:42:34 mohamed-UX330UAK bluetoothd[882]: Endpoint unregistered: sender=
Apr 26 19:56:04 mohamed-UX330UAK systemd[1]: Stopping Bluetooth service...
Apr 26 19:56:04 mohamed-UX330UAK bluetoothd[882]: Terminating
Apr 26 19:56:04 mohamed-UX330UAK bluetoothd[882]: Endpoint unregistered: sender=
Apr 26 19:56:04 mohamed-UX330UAK bluetoothd[882]: Endpoint unregistered: sender=
Apr 26 19:56:04 mohamed-UX330UAK systemd[1]: Stopped Bluetooth service.
~
~
~
~
~
~
~
lines 1-17/17 (END)...skipping...
● bluetooth.service - Bluetooth service
   Loaded: loaded (/lib/systemd/system/bluetooth.service; disabled; vendor preset: enabled)
   Active: inactive (dead) since Wed 2017-04-26 19:56:04 AEST; 23s ago
     Docs: man:bluetoothd(8)
 Main PID: 882 (code=exited, status=0/SUCCESS)
   Status: "Quitting"

Apr 26 19:42:19 mohamed-UX330UAK bluetoothd[882]: Endpoint registered: sender=:1.79 path=/MediaEndpoint/A2DPSource
Apr 26 19:42:19 mohamed-UX330UAK bluetoothd[882]: Endpoint registered: sender=:1.79 path=/MediaEndpoint/A2DPSink
Apr 26 19:42:19 mohamed-UX330UAK bluetoothd[882]: RFCOMM server failed for Headset Voice gateway: rfcomm_bind: Address already in use (98)
Apr 26 19:42:34 mohamed-UX330UAK bluetoothd[882]: Endpoint unregistered: sender=:1.43 path=/MediaEndpoint/A2DPSource
Apr 26 19:42:34 mohamed-UX330UAK bluetoothd[882]: Endpoint unregistered: sender=:1.43 path=/MediaEndpoint/A2DPSink
Apr 26 19:56:04 mohamed-UX330UAK systemd[1]: Stopping Bluetooth service...
Apr 26 19:56:04 mohamed-UX330UAK bluetoothd[882]: Terminating
Apr 26 19:56:04 mohamed-UX330UAK bluetoothd[882]: Endpoint unregistered: sender=:1.79 path=/MediaEndpoint/A2DPSource
Apr 26 19:56:04 mohamed-UX330UAK bluetoothd[882]: Endpoint unregistered: sender=:1.79 path=/MediaEndpoint/A2DPSink
Apr 26 19:56:04 mohamed-UX330UAK systemd[1]: Stopped Bluetooth service.
linux ubuntu systemd
2个回答
2
投票

也许服务是由依赖项启动的。有一个third level of "off" with systemd,你可以尝试,称为“掩蔽”:

systemctl mask bluetooth.service

一旦屏蔽,即使手动也无法启动服务。你可以稍后“揭开”它。


0
投票

以下是如何创建一个将在启动时运行并执行操作以终止蓝牙服务的脚本,这将是以下内容(我使用nano,随意使用任何其他文本编辑器):

第1步:导航到该文件夹

cd /etc/systemd/system/

第2步:首先创建一个脚本,一旦运行就会终止蓝牙服务:

nano bluetoothkill.sh

第3步:输入以下代码,保存并退出:

#!/bin/bash
rfkill block bluetooth
exit 0

第4步:在同一文件夹/ etc / systemd / system /中创建一个foo.service文件:

nano foo.service

步骤5:输入以下代码,保存并退出:

[Unit]
Details=Additional startup scripts
After=network.target

[Service]
ExecStart=/etc/systemd/system/bluetoothkill.sh

[Install]
WantedBy=default.target

步骤6:在终端中运行以下命令:

sudo chmod 744 bluetoothkill.sh

步骤7:在终端中运行以下命令:

sudo systemctl start foo.service

步骤8:重新启动计算机,在下次启动时,您会注意到启动时默认情况下不再启用蓝牙服务。您仍然可以在设置中随时启用它,或者它在没有任何错误的情况下运行的终端。

如果您想在启动时添加更多脚本,可以随时编辑foo.service文件并在[Service]括号下添加其他行以在启动时运行其他脚本,例如:

ExecStart=/full-script-filepath/newscript.sh
© www.soinside.com 2019 - 2024. All rights reserved.