# Troubleshooting with Systemd
- `systemd` replaces SysV init and BSD init for managing kernel boot
- tool for managing linux units such as services (daemons), sockets, targets (groups of units), kernel devices, mount points, automount, timers, swap, paths, slices (hierarchy of units), scope
- can be used for analyzing system issues
- `journalctl` to view systemd journal (log)
- `systemctl` to manage service
- `systemctl list-units --type=service --state=active` shows active service ![[images/Pasted image 20250717194450.png]]
- `systemctl list-units --failed` shows non-functional units ![[images/Pasted image 20250717194227.png]]
- `journalctl | grep -i openipmi | tail` to show `openipmi` associated log entries for debugging ![[images/Pasted image 20250717194744.png]]
- `sudo systemctl status graphical.target` shows status of GUI ![[images/Pasted image 20250731105028.png]]
- `systemctl status apache2` shows status of apache2 daemon
- `systemtl stop apache1` stops apache2 service
- `systemctl enable apache2` auto starts apache2 service on next reboot
- `systemctl reboot` reboots system
- alternatively, `sudo init 6`
- `systemctl poweroff` shutsdown system
- alternatively, `sudo init 0`
- `systemctl rescue` forces system into rescue mode
- `systemd-analyze blame` shows how long each startup service takes to startup ![[images/Pasted image 20250717193904.png]]
- need baseline to analyze properly
- `sudo systemctl kill -s 9 apache2` to kill apache2 service with signal 9
- `sudo systemctl isolate multi-user.target` to change runlevel to multi-user
- `systemd-coredump` used to debug app crashes
- contains memory info from time of crash
# `strace`
- trace system calls and signals
- usage for debugging system call related process/service crashes
- `strace [options] [process] [args]`
- -p to specify PID instead of process name, -c for summary only, -o to specify output file, -k for stack trace, -r for timestamps for each call, -T for time spent on each call, -i for instruction pointer
- ![[images/Pasted image 20250804193353.png]]