コメントに返信する

コメントに返信する

/lib/systemd/system-sleepコマンドラインで完全に実行されるスクリプトがあります。

$ ll /lib/systemd/system-sleep/smartplug

-rwxr-xr-x 1 root root 713 Feb  7 04:55 /lib/systemd/system-sleep/smartplug*

$ sudo /lib/systemd/system-sleep/smartplug pre Suspend

/lib/systemd/system-sleep/smartplug: Going to Suspend...
/lib/systemd/system-sleep/smartplug: Status of: 192.168.0.15 is: OFF

$ sudo /lib/systemd/system-sleep/smartplug post Suspend

/lib/systemd/system-sleep/smartplug: Waking up from Suspend...

ただし、systemd一時停止中にスクリプトが呼び出されると、スクリプト名が「汚染」され、呼び出されたスクリプトからnullが返されます。

$ journalctl -b-0 | grep smartplug

Feb 07 05:47:30 alien systemd-sleep[32243]: /lib/systemd/system-sleep/smartplug: Going to suspend...
Feb 07 05:47:30 alien systemd-sleep[32243]: 0000:00:14.0/lib/systemd/system-sleep/smartplug: Status of: 192.168.0.15 is:
Feb 07 16:36:10 alien systemd-sleep[32243]: /lib/systemd/system-sleep/smartplug: Waking up from suspend...

systemd次のように話す必要があります。

Feb 07 05:47:30 alien systemd-sleep[32243]: /lib/systemd/system-sleep/smartplug: Status of: 192.168.0.15 is: OFF

しかし、それは次のように言っています:

Feb 07 05:47:30 alien systemd-sleep[32243]: 0000:00:14.0/lib/systemd/system-sleep/smartplug: Status of: 192.168.0.15 is:

私は以前このような奇妙な行動を見たことがありません。以下はスクリプトの内容です。

#!/bin/bash

# NAME: smartplug
# PATH: /lib/systemd/system-sleep
# CALL: Called from SystemD automatically
# DESC: When suspending turn off Kasa smartplugs.
# NOTE: Copy hs100.sh and myip.sh from user directory to /usr/bin.

# DATE: Feb 6 2020.

TMPLIST=/tmp/smartplug-list
PlugArr=( "192.168.0.15" )

case $1/$2 in
  pre/*)
    echo "$0: Going to $2..."
    echo -n '' > "$TMPLIST"

    status=$(hs100.sh -i "${PlugArr[0]}" check | cut -f2)
    echo "$0: Status of: ${PlugArr[0]} is: $status"
    if [[ "$status" == ON ]] ; then
        hs100.sh -i "${PlugArr[0]}" off
        echo "${PlugArr[0]}" >> "$TMPLIST"
    fi
        ;;
  post/*)
    echo "$0: Waking up from $2..."
    rm $TMPLIST
        ;;
esac

コメントに返信する

なぜなら。 。 。結果lspci -vt

$ lspci -vt
-[0000:00]-+-00.0  Intel Corporation Xeon E3-1200 v5/E3-1500 v5/6th Gen Core Processor Host Bridge/DRAM Registers
           +-01.0-[01]--+-00.0  NVIDIA Corporation GM204M [GeForce GTX 970M]
           |            \-00.1  NVIDIA Corporation GM204 High Definition Audio Controller
           +-02.0  Intel Corporation HD Graphics 530
           +-04.0  Intel Corporation Xeon E3-1200 v5/E3-1500 v5/6th Gen Core Processor Thermal Subsystem
           +-14.0  Intel Corporation 100 Series/C230 Series Chipset Family USB 3.0 xHCI Controller

なぜなら。 。 。結果journalctl -b-0 | grep smartplug -A5

これは、PCIバスの接続解除が問題メッセージの原因であることを確認します。

--
Feb 07 22:40:15 alien systemd-sleep[14761]: /lib/systemd/system-sleep/smartplug: Going to suspend...
Feb 07 22:40:15 alien systemd-sleep[14761]: /lib/systemd/system-sleep/custom-xhci_hcd: Going to suspend...
Feb 07 22:40:15 alien systemd-sleep[14761]: Failed to connect to non-global ctrl_ifname: (nil)  error: No such file or directory
Feb 07 22:40:15 alien systemd-sleep[14762]: /lib/systemd/system-sleep/wpasupplicant failed with error code 255.
Feb 07 22:40:15 alien systemd-sleep[14762]: /lib/systemd/system-sleep/r8169-reset failed with error code 1.
Feb 07 22:40:15 alien kernel: xhci_hcd 0000:00:14.0: remove, state 4
--
Feb 07 22:40:15 alien systemd-sleep[14761]: 0000:00:14.0/lib/systemd/system-sleep/smartplug: Status of: 192.168.0.15 is:
Feb 07 22:40:15 alien kernel: usb 1-9: USB disconnect, device number 9
Feb 07 22:40:15 alien acpid[1320]: input device has been disconnected, fd 22
Feb 07 22:40:15 alien kernel: xhci_hcd 0000:00:14.0: USB bus 1 deregistered
Feb 07 22:40:15 alien kernel: xhci_hcd 0000:39:00.0: remove, state 4
Feb 07 22:40:15 alien kernel: usb usb4: USB disconnect, device number 1
--

この行は、すべてのUSBデバイスの接続を解除(バインド解除/電源オフ)するxhci_hcd 0000:00:14.0: USB bus 1 deregisteredスクリプトです。 Kasa SmartplugをオフにするにはWiFiが必要なため、スクリプトが失敗しますcustom-xhci_hcdsmartplug

ラップトップが止まってもスマートプラグがまだテレビの照明を消していないので、まだ森から出ていません。ネットワーク管理者がWiFiをすぐにオフにしているようですが、もう少し調査が必要です。

カーネルを無効にした後custom-xhci_hcd(数年前に書かれましたが、おそらくもう必要ありません)は4.14.170次のようになりますjournalctl

--
Feb 08 09:14:44 alien systemd-sleep[3032]: /lib/systemd/system-sleep/smartplug: Going to suspend...
Feb 08 09:14:44 alien systemd-sleep[3032]: Failed to connect to non-global ctrl_ifname: (nil)  error: No such file or directory
Feb 08 09:14:44 alien systemd-sleep[3033]: /lib/systemd/system-sleep/wpasupplicant failed with error code 255.
Feb 08 09:14:44 alien eyesome[3127]: Wakeup: Creating /tmp/eyesome-is-suspending
Feb 08 09:14:44 alien systemd-sleep[3032]: /lib/systemd/system-sleep/smartplug: Status of: 192.168.0.15 is:
Feb 08 09:14:44 alien systemd-sleep[3033]: /lib/systemd/system-sleep/display-auto-brightness failed with error code 1.
Feb 08 09:14:45 alien systemd-sleep[3033]: /lib/systemd/system-sleep/lag-suspend.sh failed with error code 1.
Feb 08 09:14:45 alien systemd-sleep[3033]: /lib/systemd/system-sleep/r8169-reset failed with error code 1.
Feb 08 09:14:45 alien systemd-sleep[3033]: /lib/systemd/system-sleep/iwlwifi-reset failed with error code 1.
Feb 08 09:14:45 alien systemd-sleep[3032]: Suspending system...
--
Feb 08 09:14:57 alien systemd-sleep[3032]: /lib/systemd/system-sleep/smartplug: Waking up from suspend...
Feb 08 09:14:57 alien systemd-sleep[3032]: Failed to connect to non-global ctrl_ifname: (nil)  error: No such file or directory
Feb 08 09:14:57 alien kernel: PM: suspend exit
Feb 08 09:14:57 alien eyesome[3346]: Wakeup: Called from suspend.
Feb 08 09:14:57 alien systemd-sleep[3032]: /dev/sda:
Feb 08 09:14:57 alien systemd-sleep[3032]:  setting Advanced Power Management level to 0xfe (254)

スクリプトの他のエラーコードは、/lib/systemd/system-sleepスクリプトが実行可能ではなく、記録上の理由で保持されるためです。

rick@alien:/lib/systemd/system-sleep$ ll
total 68
drwxr-xr-x 2 root root 4096 Feb  7 04:55 ./
drwxr-xr-x 8 root root 4096 Feb  6 16:53 ../
-rw-r--r-- 1 root root 1079 Oct 28  2018 custom-xhci_hcd
-rw-r--r-- 1 root root 1079 Oct 28  2018 custom-xhci_hcd~
-rw-r--r-- 1 root root 1539 Jun 10  2018 display-auto-brightness
-rwxr-xr-x 1 root root   92 Mar 17  2016 hdparm*
-rw-r--r-- 1 root root  716 Apr 22  2017 iwlwifi-reset
-rw-r--r-- 1 root root  572 Oct 28  2018 lag-suspend.sh
-rw-r--r-- 1 root root  522 Oct 21  2018 lag-suspend.sh~
-rw-r--r-- 1 root root 2820 Aug  5  2018 r8169-reset
-rwxr-xr-x 1 root root  713 Feb  7 04:55 smartplug*
-rwxr-xr-x 1 root root  661 Feb  7 04:53 smartplug~*
-rwxr-xr-x 1 root root 1114 Oct 28  2018 sound*
-rwxr-xr-x 1 root root 1171 Aug  5  2018 sound~*
-rwxr-xr-x 1 root root  317 Aug 29 05:44 systemd-wake-eyesome*
-rwxr-xr-x 1 root root  219 Apr 29  2019 unattended-upgrades*
-rwxr-xr-x 1 root root  182 Oct 26  2015 wpasupplicant*

なぜなら。 。 。結果cat -v

フィードバックの要求に応じて:

$ sudo /lib/systemd/system-sleep/smartplug pre Suspend |& cat -v
/lib/systemd/system-sleep/smartplug: Going to Suspend...
/lib/systemd/system-sleep/smartplug: Status of: 192.168.0.15 is: ON

配管は|& cat -v出力を変更しません。

ベストアンサー1

Systemd はまずネットワーク管理者を閉じます。

サスペンド中にUSBバスを取り外さずにエラーメッセージが修正されても、問題はまだ残り、サスペンド中にWiFiコマンドを送信できません。

Network Managerは、一時停止/休止状態とシャットダウン中に終了する最初のサービスです。この期間中にWiFi無線信号をデバイスに送信するには、次のものが必要です。これを読んでください

Systemd「ハッキング」でスクリプトを移動します。

私の問題を解決するためにスクリプトを作成しました。

/etc/NetworkManager/dispatcher.d/pre-down.d/smartplug_off

スクリプトは実行可能(chmod a+x scriptname)としてマークする必要があります。私の考えには以下が含まれています。

#!/bin/bash

# NAME: smartplug_off
# PATH: /etc/NetworkManager/dispatcher.d/pre-down.d
# DESC: Turn off smartplug light power for TV light
# DATE: March 7, 2020.

# CALL: Called by Network Manager before going down. Network manager in turn
#       is called by systemd during suspend/hibernate/shutdown

# NOTE: myisp.sh and hs100.sh must be installed for hs100 tp-link power plug.
#       https://developer.gnome.org/NetworkManager/stable/NetworkManager.html

PlugName="192.168.0.15"

status=$(hs100.sh -i "$PlugName" check | cut -f2)
if [ $status == "OFF" ] ; then
    : # Nothing to do already off
elif [ $status == "ON" ] ; then
    hs100.sh -i "$PlugName" off
else
    echo Error hs100.sh not responding check connection and IP "$PlugName".
fi

おすすめ記事