Как systemctl планирует отключение системы?

2518
patryk.beza

Когда я печатаю shutdown -h +30, Linux каким-то образом планирует изменение уровня выполнения в течение 30 минут. На Debian /sbin/shutdownесть символическая ссылка на /bin/systemctl. Мои тесты показывают, что shutdownвовсе не используют ни хроны, ни Systemd таймеры .

Как осуществляется отключение системы systemd?

9
Вы можете уточнить вопрос? Я не думаю, что понимаю это. Konrad Gajewski 8 лет назад 0

1 ответ на вопрос

9
bertieb

Good question. I tried what I now realise you must have tried- scheduling a shutdown and querying the systemd timers!

That showed that the shutdown was not in the systemd timers, as you noted. So then a quick perusal of the systemctl source gives us this call, as part of halt_main():

r = sd_bus_call_method( b, "org.freedesktop.login1", "/org/freedesktop/login1", "org.freedesktop.login1.Manager", "ScheduleShutdown", &error, NULL, "st", arg_action == ACTION_HALT ? "halt" : arg_action == ACTION_POWEROFF ? "poweroff" : arg_action == ACTION_KEXEC ? "kexec" : "reboot", arg_when); 

(systemctl.c line 7387)

So it would appear that shutdowns are handled by logind. You can continue to pursue the details if you like- see login-dbus.c. There are methods there for scheduling, cancelling, managing shutdowns. But for a deeper understanding, you may need to know more about logind/systemd than I do.

Long story short, the shutdown info is stored (at least) in a schedule file at /run/systemd/shutdown/scheduled, the contents of mine as an example were:

USEC=1435715559055789 WARN_WALL=1 MODE=poweroff 

Indicating time (in microseconds, presumably); whether to warn via wall, and which mode (cf restart, kexec etc).

Hope this points you in the right direction at least!

Похожие вопросы