Linux Labs

Packages, services, and logs / Stage 5 of 13

Systemd services: state and startup

Not running Starting usually ~20 s
Leave the lesson

Step 3 of 6 · on a machine · 4 min

Start and stop

The first state, running now, is changed by three commands. Here you can see whether they touch the second one.

bash
sudo systemctl start cron     # start
sudo systemctl stop cron      # stop
sudo systemctl restart cron   # stop and start again right away

Only root may change the state of a service, which is why these commands begin with sudo. Reading the state — status, is-active, is-enabled — works without it.

Note

Without sudo, systemctl stop cron asks for a password: Authentication is required to stop 'cron.service'. Press Ctrl+C and type the command with sudo.

In the morning the on-call engineer ran start, and cron came back to work. Stop cron and see what happens to its autostart.

Exercise · look

Stop cron

Stop cron, then ask the machine about its two states: is it running now, and will it start at boot.

First, predict

What will systemctl is-enabled cron print after the stop?

Now start the exercise, run the command and compare your prediction with the output.

Sign in and start The machine is available after signing in
Ubuntu 24.04
Loading…