>_ IzzyLab

Hands-on task

This task is step 4 of the course “Server: first steps”

Restart a service

easy~5 min

A colleague is moving the website to a new directory, /var/www/shop, and has already updated the nginx config. But http://localhost/ still shows the old "Coming soon" page.

Check the status of the nginx service and restart it so the new "Shop is open" page shows up. You don't need to change the config or the site files.

On a regular server, services are managed with systemctl, but the sandbox has no systemd — the service command works here instead.

What you'll practise:
  • service
  • systemctl
  • service status
  • restart
  • nginx -t

Topic breakdown

A service (daemon) is a program that runs in the background and waits for work: the nginx web server, a database, the cron scheduler. They're run by a service manager.

On a regular Ubuntu server that's systemd, and its command is systemctl:

systemctl status cron      # is it running and what does it say
systemctl restart cron     # stop it and start it again

Containers usually have no systemd — and neither does the sandbox. There the old service command works, with the same actions but in a different order: the name first, then the action (service cron status). On a server with systemd, service works too — it passes the command on to systemctl itself.

The actions: status shows the state, start and stop start and stop the service, restart restarts it, reload re-reads the settings without stopping (not every service supports it).

Important: most services read their config only when they start. If the config has changed, restart the service, otherwise it keeps working the old way.

What's checked

  1. nginx is running
  2. http://localhost/ shows the new page
  3. The config and site files are untouched

What it looks like