systemctl-exit
Terminate user's systemd session
TLDR
Exit the user service manager
Exit the user service manager with a specific exit code
Ask the container's service manager to exit (equivalent of systemctl poweroff if not in a container)
SYNOPSIS
systemctl [OPTIONS...] exit [STATUS]
systemctl --user [OPTIONS...] exit [STATUS]
PARAMETERS
STATUS
An optional integer exit status code that the systemd manager should report upon termination. If omitted, the default exit status is 0 (success).
--user
Directs the command to communicate with the systemd user session manager instance instead of the system manager. This is crucial for terminating a user's session systemd.
--system
Directs the command to communicate with the systemd system manager (PID 1). This is the default behavior if neither --user nor --system is specified explicitly.
DESCRIPTION
The systemctl exit command is used to request the systemd manager instance it is communicating with to terminate. When executed without the --user option, it targets the main systemd system manager (PID 1). However, attempting to exit the PID 1 system manager on a live, production system is highly disruptive and effectively equivalent to an uncontrolled system shutdown, as systemd is responsible for managing all system processes. Therefore, this command is rarely used for the system manager in normal operations.
Its primary utility for the system manager lies in testing environments, debugging systemd itself, or within containerized setups where systemd might be running as a non-PID 1 process. In such scenarios, it allows for a controlled termination of the systemd instance without affecting the host.
When combined with the --user option (e.g., systemctl --user exit), the command targets the user's systemd session manager. Exiting the user manager terminates all services and processes managed by that user's systemd instance, which typically includes graphical session components and background applications. This can be used to gracefully end a user's entire session without logging out from the display manager.
CAVEATS
Using systemctl exit on the system manager (PID 1) of a running operating system will lead to severe system instability or an uncontrolled shutdown, as the systemd process is vital for managing nearly all other system services and processes. It should virtually never be used in a production environment.
Exiting the user manager with systemctl --user exit will terminate all services and applications managed by that user's systemd instance. This can include graphical environment components, potentially leading to the termination of the user's desktop session or background processes.
SYSTEM MANAGER VS. USER MANAGER BEHAVIOR
When invoked without --user, systemctl exit targets the global systemd instance (PID 1). This is dangerous on a live system. When used with --user, it targets the individual user's systemd instance, which manages processes specific to that user's session. Terminating the user manager is less destructive than the system manager but will still end the user's session-related services.
PRIMARY USE CASES
The command is primarily useful for:
1. Testing and Development: For developers working on systemd itself or related components.
2. Container Environments: When systemd runs as a non-PID 1 process inside a container or chroot, allowing graceful shutdown of that specific systemd instance.
3. User Session Management: With --user, it provides a programmatic way to terminate a user's entire systemd-managed session, useful in scripting or specific desktop environments.
HISTORY
The exit subcommand has been a part of systemctl since the early days of systemd's development. Its inclusion primarily serves internal testing, debugging, and specific containerization/chroot scenarios, rather than general system administration. It reflects systemd's architecture where both the system and user managers are themselves services that can be controlled and, in special cases, terminated.


