systemd

system administrationLinux
The systemd command is one of the most frequently used commands in Linux/Unix-like operating systems. systemd System and service manager for Linux operating systems

Quick Reference

Command Name:

systemd

Category:

system administration

Platform:

Linux

Basic Usage:

systemd [options] [arguments]

Common Use Cases

    Syntax

    systemd [options...]

    Options

    Option Description
    --help Show help text
    --version Show version information
    --test Determine startup sequence, dump it and exit
    --dump-configuration-items Dump understood configuration items
    --unit= Set default unit to activate
    --system Run as system service manager
    --user Run as user service manager
    --dump-core Dump core on crash
    --crash-vt= Change to specified VT on crash
    --crash-reboot Reboot on crash
    --crash-shell Run emergency shell on crash
    --confirm-spawn Ask for confirmation when spawning processes
    --show-status Show status updates on the console during boot
    --log-target= Set log target (console, journal, kmsg, journal-or-kmsg, null)
    --log-level= Set log level (debug, info, notice, warning, err, crit, alert, emerg)
    --log-color Highlight important log messages
    --log-location Include code location in log messages
    --default-standard-output= Set default standard output for services
    --default-standard-error= Set default standard error output for services

    Examples

    How to Use These Examples

    The examples below show common ways to use the systemd command. Try them in your terminal to see the results. You can copy any example by clicking on the code block.

    # Note: systemd itself is not typically called directly, # but is instead used through interfaces like systemctl
    # View systemd version systemd --version
    # Check if system is running systemd ps --no-headers -o comm 1
    # Check systemd boot time systemd-analyze
    # Check service startup times systemd-analyze blame
    # View critical chain of boot process systemd-analyze critical-chain
    # Generate boot timeline as SVG graph systemd-analyze plot > boot-graph.svg # Check for systemd file hierarchy problems systemd-analyze verify # Verify a specific unit file systemd-analyze verify apache2.service # List active systemd cgroups on the system systemd-cgls # Control cgroup tree (through systemd-run) systemd-run --unit=test-unit --slice=test-slice sleep 100 systemd-cgls | grep test # Execute a command in a transient scope unit systemd-run --scope --user htop # Creating a timer to run a command every 30 minutes systemd-run --on-calendar="*:0/30" --unit=backup-timer.timer /path/to/backup.sh # Creating an ephemeral service that runs once systemd-run --on-active=30 --unit=delayed-job /path/to/script.sh # Create an ephemeral service with resource limits systemd-run --property=CPUQuota=10% --property=MemoryLimit=500M /path/to/resource-intensive-app # Create a transient timer unit systemd-run --on-calendar='2023-12-31 23:59:59' --unit=newyear /path/to/celebration.sh

    Try It Yourself

    Practice makes perfect! The best way to learn is by trying these examples on your own system with real files.

    Understanding Syntax

    Pay attention to the syntax coloring: commands, options, and file paths are highlighted differently.

    Notes

    Systemd is a system and service manager for Linux operating systems, designed as a replacement for the traditional System V init system. It has become the standard init system for most major Linux distributions, including Ubuntu, Fedora, Debian, CentOS, RHEL, and others. As the first process started during boot (PID 1), systemd serves as the root of the process tree and is responsible for initializing the system and managing services. Its design allows for parallel startup of services, dependency-based service control, and on-demand service activation, among many other features. While systemd itself is a single binary, it encompasses a suite of tools and utilities that together form a comprehensive system management framework. These include: 1. **systemctl**: The primary command-line interface for controlling systemd and managing services. 2. **journald**: A centralized logging service that collects and stores logs from various sources. 3. **logind**: Manages user logins and sessions. 4. **networkd**: Provides network configuration capabilities. 5. **resolved**: Offers DNS resolution services. 6. **timesyncd**: Synchronizes the system clock with remote time servers. 7. **bootctl**: Manages boot loader configuration. Systemd organizes its functionality around the concept of "units," which represent resources the system knows how to manage. Common unit types include: - **service**: A process or group of processes - **socket**: An IPC or network socket for socket-based activation - **target**: A group of units for synchronization points (replacing runlevels) - **device**: A hardware device that needs systemd management - **mount**: A filesystem mount point - **timer**: A scheduled task similar to cron jobs - **path**: A file or directory for path-based activation Unit files are configuration files that define how systemd should manage these resources. They are typically located in the following directories, listed in order of precedence: - `/etc/systemd/system/`: System-specific unit files - `/run/systemd/system/`: Runtime unit files - `/usr/lib/systemd/system/`: Unit files installed by packages Despite its widespread adoption, systemd has been a subject of controversy in the Linux community, with critics arguing that it violates the Unix philosophy of "do one thing and do it well" by incorporating numerous functionalities beyond the traditional init system's scope. However, its proponents value the benefits of its unified approach to system management, including faster boot times, standardized service configuration, and comprehensive resource management. In daily use, system administrators rarely interact with the systemd binary directly, instead using interfaces like systemctl, journalctl, and other command-line tools that communicate with systemd to control the system and its services.

    Related Commands

    These commands are frequently used alongside systemd or serve similar purposes:

    Use Cases

    Learn By Doing

    The best way to learn Linux commands is by practicing. Try out these examples in your terminal to build muscle memory and understand how the systemd command works in different scenarios.

    $ systemd
    View All Commands