why won't a service start

Read what a systemd service said when it failed, check its unit file and its configuration, then start it again.

systemservices

steps
  1. systemctl status NAME

    its state, its last log lines and its exit code

  2. journalctl -u NAME -b -n 50 --no-pager

    its last 50 log lines since the machine started

  3. systemctl cat NAME

    the unit file it runs: the command, the user, the paths

  4. systemd-analyze verify NAME.service

    look for mistakes in the unit file

  5. sudo ss -tulpn

    see whether another program already holds its port

  6. sudo systemctl daemon-reload

    after editing a unit file, make systemd read it again

  7. sudo systemctl restart NAME

    start it again, then look at its status

notes
  • Put the service's name in place of NAME: nginx, ssh, docker.
  • Many services check their own configuration: sudo nginx -t, sudo apachectl configtest, sudo sshd -t.
  • "Permission denied" in the log often means a file or folder it needs belongs to another user.
  • macOS uses launchd: launchctl list | grep NAME, and its logs with log show --last 10m.
commands used

systemctljournalctlsystemd-analyze

Each has a page in lore: lore systemctl opens it.