Detectar pendente shutdown sheduled Ubuntu Server 16.04.1

4

Antes do systemd, alguém costumava ver um processo de desligamento na lista de processos (por exemplo, ps -ef | grep shutdown ). Agora, porém, o conselho mais recente que posso encontrar é usar systemctl status , mas não estou tendo sorte:

root@m________a:~# lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 16.04.1 LTS
Release:    16.04
Codename:   xenial
root@m________a:~# shutdown -r 14:00
Shutdown scheduled for Mon 2016-10-10 14:00:00 BST, use 'shutdown -c' to cancel.
root@m________a:~# ps -ef | grep "shutdown"
root     10584 10508  0 13:44 pts/0    00:00:00 grep --color=auto shutdown
root@m________a:~# systemctl status systemd-halt.service
● systemd-halt.service - Halt
   Loaded: loaded (/lib/systemd/system/systemd-halt.service; static; vendor preset: enabled)
   Active: inactive (dead)
     Docs: man:systemd-halt.service(8)
root@m________a:~# systemctl status systemd-reboot.service 
● systemd-reboot.service - Reboot
   Loaded: loaded (/lib/systemd/system/systemd-reboot.service; static; vendor preset: enabled)
   Active: inactive (dead)
     Docs: man:systemd-halt.service(8)
root@m________a:~# systemctl status systemd-poweroff.service 
● systemd-poweroff.service - Power-Off
   Loaded: loaded (/lib/systemd/system/systemd-poweroff.service; static; vendor preset: enabled)
   Active: inactive (dead)
     Docs: man:systemd-halt.service(8)

Eu ficaria muito grato se alguém pudesse explicar como eu posso detectar um desligamento agendado pendente e, de fato, por que tal desligamento não parece aparecer usando systemctl

    
por John H Woods 10.10.2016 / 15:01

3 respostas

3

Você pode usar

cat /run/systemd/shutdown/scheduled

Isso foi adicionado ao lançamento do systemd 220 como explicado aqui: link

    
por scampbell 11.04.2017 / 14:25
2
systemctl status systemd-shutdownd.service

página de manual para o serviço:

systemd-shutdownd.service is a system service that implements scheduled shutdowns, as exposed by shutdown(8). systemd-shutdownd.service is automatically activated on request and terminates itself when it is unused.

Quando não está ativo:

$ systemctl status systemd-shutdownd.service
● systemd-shutdownd.service - Delayed Shutdown Service
   Loaded: loaded (/lib/systemd/system/systemd-shutdownd.service; static; vendor preset: enabled)
   Active: inactive (dead)
     Docs: man:systemd-shutdownd.service(8)

Quando ativo:

 $ sudo shutdown +100
 Shutdown scheduled for ma 2016-10-10 17:12:56 CEST, use 'shutdown -c' to cancel.
 $ systemctl status systemd-shutdownd.service 
 ● systemd-shutdownd.service - Delayed Shutdown Service
   Loaded: loaded (/lib/systemd/system/systemd-shutdownd.service; static; vendor preset: enabled)
   Active: active (running) since ma 2016-10-10 15:32:56 CEST; 3s ago
     Docs: man:systemd-shutdownd.service(8)
 Main PID: 3129 (systemd-shutdow)
   Status: "Shutting down at Mon 2016-10-10 17:12:56 CEST (poweroff)..."
   CGroup: /system.slice/systemd-shutdownd.service
           └─3129 /lib/systemd/systemd-shutdownd

okt 10 15:32:56 x systemd[1]: Started Delayed Shutdown Service.
okt 10 15:32:56 x systemd[1]: Starting Delayed Shutdown Service...
okt 10 15:32:56 x systemd-shutdownd[3129]: Shutting down at Mon 2016-1...
Hint: Some lines were ellipsized, use -l to show in full.
    
por Rinzwind 10.10.2016 / 15:26
0

Em sistemas mais recentes (executando systemd 220 e acima, verifique com systemd --version ) o systemd-shutdownd.service foi removido e a maneira simples é %código%. Se o arquivo existir, um desligamento está pendente e o arquivo conterá algo como

USEC=1547919000000000
WARN_WALL=1
MODE=poweroff

Eu escrevi um pequeno script para lidar com esse caso:

#!/usr/bin/env bash

if [ -r /run/systemd/shutdown/scheduled ]; then
    source /run/systemd/shutdown/scheduled;
    echo "System will shutdown to mode=$MODE at $(date --date="@$(( USEC / 1000000 ))")";
    exit 0;
else
    echo "No pending shutdown";
    exit 1;
fi

Leitura adicional:

por 19.01.2019 / 19:03

Tags