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

时间:2017-04-26 10:00:02

标签: linux ubuntu systemd

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

基本上

首先,停止服务:

sudo systemctl stop bluetooth.service

然后禁用它:

sudo systemctl disable 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 wiki上它也说它应该可以解决我做错了什么?

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.

2 个答案:

答案 0 :(得分:2)

也许服务是由依赖项启动的。您可以尝试third level of "off" with systemd,称为"屏蔽":

systemctl mask bluetooth.service

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

答案 1 :(得分: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]括号下添加其他行以在启动时运行其他脚本,例如: < / p>

ExecStart=/full-script-filepath/newscript.sh