Logs, journald and strace
Read system logs with journalctl and see what a stuck program is doing with strace.
journalctl
journalctl -u nginx --since "1 hour ago" # one service, recent
journalctl -p err -b # errors since boot
journalctl -f -u myapp # follow live
journalctl --disk-usage-uselects a unit,-bthe current boot (-b -1the previous one).-pfilters by priority (err,warning,info).- Logs may be stored only in memory. Make them persistent with
Storage=persistentin/etc/systemd/journald.conf.
strace: what is it doing?
strace prints the system calls a process makes: files it opens, network connections it tries, errors it gets. It often explains a program that fails without a clear message.
strace -f -e trace=openat,connect -o trace.txt ./myprogram
sudo strace -p 1234 -f # attach to a running processSearch the output for ENOENT (file not found) or EACCES (permission denied) to see which file is the problem.
Carefulstrace slows the target a lot and can show secrets such as passwords in system call arguments. Use it deliberately and do not paste raw output in public.
Test yourself
Answer all the questions, then check them. Finish with every answer right to mark the lesson as done.