/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_hcd
됩니다 .smartplug
노트북이 멈춰도 스마트 플러그가 여전히 TV 조명을 끄지 않기 때문에 아직 숲에서 나오지 않았습니다. 네트워크 관리자가 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