私のシステムサービス(起動時にBluetoothをオフにする)は起動時にのみ実行する必要があると思いますか?

私のシステムサービス(起動時にBluetoothをオフにする)は起動時にのみ実行する必要があると思いますか?

起動時にBluetoothをオフにするsystemdサービスを作成しましたが、必要に応じてBluetoothのトップパネルアプレットアイコンを介してBluetoothをオンにしたいと思います。

起動時にBluetoothをオフにする機能が素晴らしいです。手動でオンにすることをテストしたようです。

最近、Bluetoothスピーカーを購入して接続してみました。

しかし、Bluetoothの電源を入れるたびに(約10秒後に)再びオフになり、ログにはオフになるのが私のサービスと表示されます。

(もっと混乱しているのは、接続を試みた最初の日に数曲の交響曲を演奏できるほど長い間スピーカーに接続できたことです。3日目からBluetoothが消え続けました。)

私が間違って理解したのでしょうか?サービスは起動時に一度だけ実行されると思います。他に指定する必要がありますか?

以下は最新バージョンのサービスです。

私がコメントアウトするとType=oneshot同じように動作します。からのシンボリックリンクをWantedBy=bluetooth.target作成し、シンボリックリンクがないとサービスがまったく実行されないために含めました。/etc/systemd/system/bluetooth.target.wants/turn-bluetooth-off.service/etc/systemd/system/turn-bluetooth-off.service

sudo rfkill unblock bluetoothBluetoothをオンにしても効果はありません。

[Unit]
Description=Service to always turn bluetooth off at system start time
After=bluetooth.service
After=NetworkManager.service
After=network-online.target

[Service]
Type=oneshot
ExecStart=/usr/local/bin/turn-bluetooth-off.sh

[Install]
WantedBy=multi-user.target
WantedBy=bluetooth.target

とファイル/usr/local/bin/turn-bluetooth-off.sh

#!/bin/bash

date > /root/disk_space_report.txt
rfkill block bluetooth
du -sh /home/ >> /root/disk_space_report.txt

私は走る

$ systemctl daemon-reload
$ systemctl enable turn-bluetooth-off.service
Created symlink from /etc/systemd/system/default.target.wants/turn-bluetooth-off.service to /etc/systemd/system/turn-bluetooth-off.service.

再起動すると、次のようにjournalctl --unit=bluetooth 表示されます(一部の行は赤で表示されます)。

-- Logs begin at Mon 2020-06-08 17:18:28 CEST, end at Mon 2020-06-08 17:43:45 CEST. --
Jun 08 17:18:41 Otilia systemd[1]: Starting Bluetooth service...
Jun 08 17:18:41 Otilia bluetoothd[824]: Bluetooth daemon 5.37
Jun 08 17:18:41 Otilia systemd[1]: Started Bluetooth service.
Jun 08 17:18:41 Otilia bluetoothd[824]: Starting SDP server
Jun 08 17:18:42 Otilia bluetoothd[824]: Bluetooth management interface 1.13 initialized
Jun 08 17:18:44 Otilia bluetoothd[824]: Failed to obtain handles for "Service Changed" characteristic
Jun 08 17:18:44 Otilia bluetoothd[824]: Not enough free handles to register service
Jun 08 17:18:44 Otilia bluetoothd[824]: Error adding Link Loss service
Jun 08 17:18:44 Otilia bluetoothd[824]: Not enough free handles to register service
Jun 08 17:18:44 Otilia bluetoothd[824]: Not enough free handles to register service
Jun 08 17:18:44 Otilia bluetoothd[824]: Not enough free handles to register service
Jun 08 17:18:44 Otilia bluetoothd[824]: Current Time Service could not be registered
Jun 08 17:18:44 Otilia bluetoothd[824]: gatt-time-server: Input/output error (5)
Jun 08 17:18:44 Otilia bluetoothd[824]: Not enough free handles to register service
Jun 08 17:18:44 Otilia bluetoothd[824]: Not enough free handles to register service
Jun 08 17:18:44 Otilia bluetoothd[824]: Sap driver initialization failed.
Jun 08 17:18:44 Otilia bluetoothd[824]: sap-server: Operation not permitted (1)
Jun 08 17:19:38 Otilia bluetoothd[824]: Failed to obtain handles for "Service Changed" characteristic
Jun 08 17:19:38 Otilia bluetoothd[824]: Not enough free handles to register service
Jun 08 17:19:38 Otilia bluetoothd[824]: Error adding Link Loss service
Jun 08 17:19:38 Otilia bluetoothd[824]: Not enough free handles to register service
Jun 08 17:19:38 Otilia bluetoothd[824]: Not enough free handles to register service
Jun 08 17:19:38 Otilia bluetoothd[824]: Not enough free handles to register service
Jun 08 17:19:38 Otilia bluetoothd[824]: Current Time Service could not be registered
Jun 08 17:19:38 Otilia bluetoothd[824]: gatt-time-server: Input/output error (5)
Jun 08 17:19:38 Otilia bluetoothd[824]: Not enough free handles to register service
Jun 08 17:19:38 Otilia bluetoothd[824]: Not enough free handles to register service
Jun 08 17:19:38 Otilia bluetoothd[824]: Sap driver initialization failed.
Jun 08 17:19:38 Otilia bluetoothd[824]: sap-server: Operation not permitted (1)
Jun 08 17:19:39 Otilia bluetoothd[824]: Endpoint registered: sender=:1.48 path=/MediaEndpoint/A2DPSource
Jun 08 17:19:39 Otilia bluetoothd[824]: Endpoint registered: sender=:1.48 path=/MediaEndpoint/A2DPSink

以下journalctl --unit=turn-bluetooth-offを表示します。

-- Logs begin at Mon 2020-06-08 17:18:28 CEST, end at Mon 2020-06-08 17:43:45 CEST. --
Jun 08 17:18:51 Otilia systemd[1]: Starting Service to always turn bluetooth off at system start time...
Jun 08 17:21:21 Otilia systemd[1]: Started Service to always turn bluetooth off at system start time.

そしてrfkill list allショー

0: Toshiba Bluetooth: Bluetooth
    Soft blocked: no
    Hard blocked: no
1: phy0: Wireless LAN
    Soft blocked: no
    Hard blocked: no
3: hci0: Bluetooth
    Soft blocked: yes
    Hard blocked: no

注:時にはhci0表示されず、ソフトブロックが他の項目のいずれかに表示されることがあります。

今、Bluetoothのトップパネルアプレットを使ってBluetoothをオンにしようとしています。アプレットはONを表示し、約10秒後に再びOFFを表示します。

新しい出力は次のようになります。journalctl --unit=bluetooth

Jun 08 20:43:29 Otilia bluetoothd[824]: Failed to obtain handles for "Service Changed" characteristic
Jun 08 20:43:29 Otilia bluetoothd[824]: Not enough free handles to register service
Jun 08 20:43:29 Otilia bluetoothd[824]: Error adding Link Loss service
Jun 08 20:43:29 Otilia bluetoothd[824]: Not enough free handles to register service
Jun 08 20:43:29 Otilia bluetoothd[824]: Not enough free handles to register service
Jun 08 20:43:29 Otilia bluetoothd[824]: Not enough free handles to register service
Jun 08 20:43:29 Otilia bluetoothd[824]: Current Time Service could not be registered
Jun 08 20:43:29 Otilia bluetoothd[824]: gatt-time-server: Input/output error (5)
Jun 08 20:43:29 Otilia bluetoothd[824]: Not enough free handles to register service
Jun 08 20:43:29 Otilia bluetoothd[824]: Not enough free handles to register service
Jun 08 20:43:29 Otilia bluetoothd[824]: Sap driver initialization failed.
Jun 08 20:43:29 Otilia bluetoothd[824]: sap-server: Operation not permitted (1)
Jun 08 20:43:29 Otilia bluetoothd[824]: Endpoint registered: sender=:1.48 path=/MediaEndpoint/A2DPSource
Jun 08 20:43:29 Otilia bluetoothd[824]: Endpoint registered: sender=:1.48 path=/MediaEndpoint/A2DPSink
Jun 08 20:43:31 Otilia bluetoothd[824]: Endpoint unregistered: sender=:1.48 path=/MediaEndpoint/A2DPSource
Jun 08 20:43:31 Otilia bluetoothd[824]: Endpoint unregistered: sender=:1.48 path=/MediaEndpoint/A2DPSink

新しい出力は次のようになります。journalctl --unit=turn-bluetooth-off

Jun 08 20:43:30 Otilia systemd[1]: Starting Service to always turn bluetooth off at system start time...
Jun 08 20:43:33 Otilia systemd[1]: Started Service to always turn bluetooth off at system start time.

そしてrfkill list allショー

0: Toshiba Bluetooth: Bluetooth
    Soft blocked: yes
    Hard blocked: no
1: phy0: Wireless LAN
    Soft blocked: no
    Hard blocked: no

私のサービスが再実行される原因がわかりません。助ける!

ベストアンサー1

さて、解決策を見つけました。終了時にBluetooth設定(オンまたはオフ)が次回の起動時にも保持されることに気づきました。だから私のサービスはまったく必要ありません。笑顔。

一般的なBluetooth機能は良くありませんが、それでも使用できます。

おすすめ記事