簡體   English   中英

重新啟動后systemctl disable name.service不會持久存在

[英]systemctl disable name.service doesn't persist after reboot

我正在嘗試找到一種在啟動時在Ubuntu 16.04上禁用藍牙的方法,我一直在網上絆腳石的一種方法是使用systemd

基本上

首先,停止服務:

sudo systemctl停止bluetooth.service

然后禁用它:

sudo systemctl禁用bluetooth.service

校驗:

sudo systemctl狀態為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.

也許服務是由依賴項啟動的。 您可以嘗試使用systemd第三級“關閉” ,稱為“屏蔽”:

systemctl mask bluetooth.service

一旦被屏蔽,就根本無法啟動服務,即使是手動也無法啟動。 您可以稍后對其進行“取消屏蔽”。

這是創建腳本的方法,該腳本將在啟動時運行,並執行一項操作以終止Bluetooth服務,並且將執行以下操作(我使用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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM