# systemd ## systemctl Inspect units: ```text systemctl [opts] [cmd] [opts] --user --type=TYPE List only given types eg, service, timer, socket (use --type=help for a list) --state=STATE List only given states eg running, enabled (use --state=help for a list) --failed List only failed services [cmd] list-units List units in memory status Show runtime status of unit start Start a unit stop Stop a unit restart Restart a unit reload Reload a unit enable Enable a unit (persistent) disable Disable a unit cat Print unit file show Show properties of unit ``` ### Example: List failed units ```bash # List all system failed units. systemctl --failed # List all user failed units. systemctl --user --failed ``` ### Example: Trivial user unit ```bash # Generate unit mkdir -p ~/.config/systemd/user echo '[Unit] Description=Test logger [Service] Type=oneshot ExecStart=logger "Hello from test unit"' > ~/.config/systemd/user/test.service # Run unit systemctl --user start test # See log message journalctl --user -u test -n 5 ``` ## journalctl Inspect journal logs: ```text journalctl [opts] [matches] --user Current user journal (system by default) -u Show logs for specified -n Show only last -f Follow journal -g Grep for ``` Cleanup: ```text journalctl [opts] --disk-usage Show current disk usage --vacuum-size= Reduce journal log to (K/M/G) ``` ## References - [man systemd.unit(5)](https://www.man7.org/linux/man-pages/man5/systemd.unit.5.html) - [man systemd.service(5)](https://www.man7.org/linux/man-pages/man5/systemd.service.5.html)