A service is a program that runs in the background so others can use it. systemctl starts and stops one now, and enable decides whether it starts at every boot. These are two separate things.
Open these in Waypoints Prepare with one click. To share a file another way, copy its address and paste it into Load URL, or download the file and import it. In Prepare, the worksheet's Teacher edition shows the answers; the student copy hides them.
WorksheetOpen in PrintDownload Print the student copy; the Teacher edition has the answers.
Students will be able to
I can start and stop a service, and enable it for boot.
I can say why running now and starting at boot are different.
I can read a service's log with journalctl.
Timing
Predict and Try 8 min · Worked example 10 min · Vary 10 min · Practise and Make 12 min
Before class
Try the boards yourself.
The one idea: the operating system starts and watches background programs. A service's state and its boot setting are separate.
Simplifications: the pretend Pi has five services (ssh, cron, smbd, jellyfin, unattended-upgrades). reboot is instant. On a real Pi systemctl status pages its output: press q to leave.
Other options: service smbd start is the older form of the same thing; Docker or containers are another way to run a service (parked).
With internet: services that others reach over the internet are a bigger risk than ones on the school network, because anyone can try them (see the last lesson).
Running the lesson
Predict: wrong answers think enable starts it.
Try: ask which command did which job.
Worked example: show status before and after on the board.
Vary: after the reboot task, ask which services a server must have enabled.
Make: ask why it is proved by rebooting.
In class
On the slides at these points. Students can do the whole lesson on their own; these are for the room. In the deck, the Run, Modify and Make slides have the live playground in them (the tutorial link is the backup), and the notes above are in each slide's speaker notes.
Think, pair, share(start) A program has to be running before anyone can use it. Who starts it, and what if the computer restarts?
What happens to your programs when you restart your own computer?
Which should come back by themselves?
The operating system starts services; enable decides which come back.
Now or boot(predict, 4 min)
Two cards: NOW and BOOT. Read out commands (start, enable, stop, disable); students hold up the card that matches.
enable-now combines both.
Boot(investigate) status says disabled. What does that mean? It will not start at boot Disabled is about boot, not about now.
The hard part (on purpose)
Enable versus start. Make students say both out loud: 'now' and 'at boot'.
enable: smbd is stopped. You type sudo systemctl enable smbd. Is smbd running now? No. enable decides what happens at boot. To run it now you need start (or enable --now).
Try: start it and keep it: smbd is stopped and will not start at boot. Make it run now and at every boot.
sudo systemctl start smbd, and sudo systemctl enable smbd. Two commands, because now and at boot are different.
Two different switches: What is the difference between start and enable? start runs it now; enable runs it at every boot A service has a state (running or not now) and a boot setting (will it start next time). systemctl status shows both.
Find the mistake: Sam thinks the share is up. Click the line where it first goes wrong. line 3 Line 3 is where Sam's belief starts: no error doesn't mean running. enable only changes the boot setting. Check with systemctl status smbd.
Read the log: Where can you read why a service stopped or failed? journalctl -u name journalctl -u smbd prints that service's log. It is the first place an administrator looks.
Switch it off: smbd is running and enabled. Stop it now and stop it starting at boot.
sudo systemctl stop smbd, and sudo systemctl disable smbd.
After a reboot: smbd is running but not enabled. Reboot with sudo reboot. Is smbd running afterwards?
Not running: it was never enabled, so it did not start at boot. This is why enable matters on a server.
Read the log: Read smbd's log with journalctl -u smbd.
journalctl -u smbd shows when it started and stopped.
Reading status: status shows: active (running), disabled. You reboot. What happens to the service? It stays off after the reboot Running now and starting at boot are separate. This one was running but disabled.
Both at once: Which single command starts a service now and sets it to start at every boot? sudo systemctl enable --now name enable --now does both in one go.
Review: -aG: Review: Sam adds alex to a group with usermod -G. What went wrong? -G without -a replaces all Alex's groups -aG adds and keeps the rest.
survive a reboot: smbd is running but would vanish at a reboot. Fix that, then reboot and check that it is running.
enable first, then reboot to prove it. Never trust a service you have not rebooted with.
Solutions
One possible solution for each task. Other correct programs are fine.
Vary: change one thing › Switch it off
Open task: any program that does what the step asks.
Vary: change one thing › After a reboot
Open task: any program that does what the step asks.
Vary: change one thing › Read the log
Open task: any program that does what the step asks.
survive a reboot
Open task: any program that does what the step asks.
Stretch and support
Stretch: Find out what a unit file is and where the Pi keeps them.
Support: Two sticky notes: NOW (start, stop) and BOOT (enable, disable).
Exit ticket
smbd is running but disabled. What happens after a reboot?
It stays off: disabled means it does not start at boot.
What each step is for
enable: Committing to what enable does tests the new move: starting now and starting at boot are different things.
Try: start it and keep it: Doing both settles the prediction.
Worked example: Two different switches: Following the method once, then finding where a plausible account goes wrong, models the new move.
Vary: change one thing: Each task changes one thing: switch it off, test what a reboot does, and read the log.
Practise: Reading status and choosing commands without the board is the same move in new forms, plus a review of users.
survive a reboot: Making a service survive a reboot, and proving it, is the whole move.
Where it leads
Links: Networks (ports and servers); next: Share files with Samba.