Linux 101 : Using Systemd to shut down and halt a system
We could use systemd to shutdown a system.
The easiest way to shutdown a system is to use the below command:
The above command moves the system into the "poweroff.target" systemd target.
The unit file of the above target looks something like the below:
Below a short explanation of the main parameters:
- JobTimeoutSec : allows systemd time to properly shutdown all the services before it turns off the machine.
- JobTimeoutAction=poweroff-force : forces the system to shutdown after the "JobTimeoutSec" time has elapsed even if the running programs didn't have time to properly shutdown.
The [Install] section has an alias that we could mask for security reasons - for restarting the machine -:
We could disable it using the below command:
If we use the "--force" parameter with our command "systemctl poweroff", the system turns itself off without stopping programs or unmouting the filesystems.
Usually the "--force" option is used when the system is not responding because of a failed program for example.
Halting a system on the other hand, stops it without powering it off.
To halt a system, we could use the below command: