Eu tenho um script /lib/systemd/system-sleep
que funciona perfeitamente na linha de comando:
$ 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...
No entanto, quando systemd
chama o script durante a suspensão, ele está "contaminando" o nome do script e retornando null do script chamado:
$ 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
deveria estar dizendo:
Feb 07 05:47:30 alien systemd-sleep[32243]: /lib/systemd/system-sleep/smartplug: Status of: 192.168.0.15 is: OFF
Mas está dizendo:
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:
Eu nunca vi esse comportamento bizarro antes. Aqui está o conteúdo dos scripts:
#!/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
Responder aos comentários
Resultados delspci -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
Resultados dejournalctl -b-0 | grep smartplug -A5
Isso confirma que a desconexão do barramento PCI era a raiz da mensagem problemática
--
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
--
Observe que a linha xhci_hcd 0000:00:14.0: USB bus 1 deregistered
deles é um script custom-xhci_hcd
cujo trabalho é desconectar todos os dispositivos USB (unbind / power off). Estava causando smartplug
a falha do script porque precisa de WiFi para desligar o Kasa Smartplug.
Ainda não estou fora de perigo porque o Smartplug ainda não desliga a luz da TV quando o laptop é suspenso. Acho que isso se deve ao Network Manager derrubar o WiFi muito rapidamente, mas é necessária mais investigação.
Depois de desabilitar custom-xhci_hcd
(escrito anos atrás, mas provavelmente não é mais necessário com o kernel, 4.14.170
isso é 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)
Os outros códigos de erro dos scripts /lib/systemd/system-sleep
são porque os scripts não são executáveis, mas são mantidos por motivos históricos.
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*
Resultados decat -v
Conforme pedido de comentário:
$ 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
Observe que a tubulação |& cat -v
não altera a saída.
Systemd derruba o Network Manager primeiro
Mesmo depois de corrigir a mensagem de erro não desconectando o barramento USB durante a suspensão, os problemas permanecem, você não pode enviar um comando WiFi durante a suspensão.
O Network Manager é o primeiro serviço que é desativado durante a suspensão/hibernação e desligamento. Se você deseja enviar um sinal de rádio WiFi para um dispositivo durante esses horários, você precisa ler isso .
Mova seu script para fora dos "hacks" do Systemd
Para corrigir meu problema, criei o script:
O script deve ser marcado como executável (
chmod a+x scriptname
) e para mim contém: