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.
Samba is installed, but nobody can reach the share. Is it broken?
Programs on a server have to be running before anyone can use them. A service is a program started by the operating system and kept running. The operating system's job is to start, stop and watch services, which is why one command, systemctl, controls them all.
How this lesson works: Predict, Try, Investigate, Modify, Practise, Make
Predict: Read the problem and decide what you think before you try anything. A wrong guess is fine: it shows you what to look for.
Try: Try it on the board and compare the result with your prediction.
Investigate: Work out why it happens, one step at a time.
Modify: Change the problem on purpose and see what happens.
Practise: A few on your own, to check you have it.
Make: Make your own problem using what you have learned. Expect a few tries; that is normal.
Make your prediction first. Help opens once you've locked it in.
PredictRead the problem and decide what you think before you try anything. A wrong guess is fine: it shows you what to look for.
Enable
TryTry it on the board and compare the result with your prediction.
Try: start it and keep it
Was your prediction right?
Try it yourselfYour edits are saved in this browser.
smbd is stopped and will not start at boot. Make it run now and at every boot.
Use the board. This ticks when you get there.
InvestigateWork out why it happens, one step at a time.
Worked example: Two different switches
Worked exampleBefore each step, say what you think comes next.
systemctl status smbdis it running now, and will it start at boot?
sudo systemctl start smbdrun it now.
sudo systemctl enable smbdalso start it at every boot.
journalctl -u smbdread what the service has logged.
Now try it yourself.
Sam thinks the share is up. Click the line where it first goes wrong.
ModifyChange the problem on purpose and see what happens.
Vary: change one thing
Try it yourselfYour edits are saved in this browser.
smbd is running and enabled. Stop it now and stop it starting at boot.
Use the board. This ticks when you get there.
smbd is running but not enabled. Reboot with sudo reboot. Is smbd running afterwards?
Use the board. This ticks when you get there.
Read smbd's log with journalctl -u smbd.
Use the board. This ticks when you get there.
PractiseA few on your own, to check you have it.
Practise
MakeMake your own problem using what you have learned. Expect a few tries; that is normal.
Survive a reboot
Then: on a real Pi, run systemctl status ssh and systemctl list-units --type=service.
Try it yourselfYour edits are saved in this browser.
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. About 40 minutes.
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.
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.
The hard part (on purpose)
Enable versus start. Make students say both out loud: 'now' and 'at boot'.
When students get stuck
A student enabled the service but cannot connect. Ask: Is it running? What does status say? Fix: sudo systemctl start name, or enable --now.
systemctl says 'Interactive authentication required'. Ask: Did you use sudo? Fix: sudo systemctl ...
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).
Where it leads
Links: Networks (ports and servers); next: Share files with Samba.
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.