Skip to content

Linux & shell: Services (systemd)

Linux & shell commands for services (systemd) (tags: #systemd).

Index
4 items

Linux: Follow logs of a systemd service

Safe

Stream a service's journal, starting with the last 100 lines.

journalctl -u <service> -f -n 100
What each part does
  1. journalctlread the systemd journal
  2. -u <service>only this unit
  3. -ffollow new lines
  4. -n 100start with the last 100 lines
Example
$ journalctl -u nginx -f -n 100
Nov 20 09:12:01 web-1 nginx[812]: 10.0.3.4 - - "GET /healthz HTTP/1.1" 200

My note Add --since "10 min ago" when the service is chatty.

Also known as: journalctl · systemd logs · service logs

Linux: Show errors since last boot

Safe

Only priority err and worse from the current boot: fastest way to see what's wrong on a box.

journalctl -b -p err --no-pager
What each part does
  1. journalctlread the systemd journal
  2. -bthis boot only (-b -1 for the previous one)
  3. -p errpriority err and worse (crit, alert, emerg)
  4. --no-pagerprint directly

Also known as: boot errors · journalctl -p err

Linux: Check why a service failed

Safe

Status, last exit code and the most recent log lines of a unit.

systemctl status <service> --no-pager -l
What each part does
  1. systemctl status <service>state, main PID, exit code, and the last log lines of the unit
  2. --no-pagerprint directly instead of opening less
  3. -ldon't truncate long lines

Also known as: service failed · unit failed · systemctl status

Linux: Upgrade nginx and restart it safely

Caution

Restart only if the config still passes after the upgrade. A reload keeps the old binary running, so restart.

Dry run first
sudo dnf upgrade nginx --assumeno
sudo dnf upgrade nginx && sudo nginx -t && sudo systemctl restart nginx
What each part does
  1. dnf upgrade nginxnew nginx package (apt install --only-upgrade nginx on Ubuntu)
  2. nginx -ttest the config; stops the chain if it fails
  3. systemctl restart nginxstart the new binary
  • #linux
  • #patching
  • #systemd

Also known as: nginx update · nginx cve · upgrade nginx

My DevOps Playbook by Angelo John Calleja

New runbook

GitHub not connected

Saving is handled by the site: the GitHub token is stored in Cloudflare, not in your browser. Enter the editor password (the EDITOR_PASSWORD secret) to unlock saving in this browser.

Saving commits to gelogrammer/My_DevOps_Playbook. Create a fine-grained token with access to only this repo andContents: Read and write, then paste it here. It is stored only in this browser.

src/content/docs/…