Servers and cloud

Start, stop and read the logs of a service

Control a background service like nginx or a database and see why it stopped.

Fill these in once

macOS doesn't use systemctl. Services you installed with Homebrew are controlled with brew services, for example brew services restart {{service}}.

  1. Check the service
    Terminal · Ubuntu / Debian
    systemctl status nginx

    Press q to leave.

  2. Start, stop or restart itNeeds sudo
    Terminal · Ubuntu / Debian
    sudo systemctl restart nginx

    Swap restart for start or stop.

  3. Start it every time the server bootsNeeds sudo
    Terminal · Ubuntu / Debian
    sudo systemctl enable nginx
  4. Read its latest log linesNeeds sudo
    Terminal · Ubuntu / Debian
    sudo journalctl -u nginx -n 50 --no-pager

    Add -f instead of --no-pager to keep watching.

Check it worked

  1. Check it is running
    Terminal · Ubuntu / Debian
    systemctl is-active nginx

    It should say active.

  1. Check the service
    PowerShell
    Get-Service nginx
  2. Start, stop or restart itRun as administrator
    PowerShell
    Restart-Service nginx

    Swap Restart for Start or Stop.

  3. Start it every time Windows startsRun as administrator
    PowerShell
    Set-Service nginx -StartupType Automatic

Check it worked

  1. Check it is running
    PowerShell
    (Get-Service nginx).Status

    It should say Running.