Now versus at boot
There are two different questions for any service, and two different commands:
| Command | What it does |
|---|---|
systemctl start / stop | Run it (or stop it) right now |
systemctl restart | Stop then start — to pick up a new configuration |
systemctl enable / disable | Set whether it starts at boot |
systemctl is-enabled | Say whether it's set to start at boot |
Here's a demo service. Start it and check it's active, then stop it again:
sudo systemctl start demo.service
systemctl is-active demo.service
sudo systemctl stop demo.service
systemctl is-active demo.serviceIn the terminal (is-active prints inactive after stop, so the last command's exit status is 3)
student@vulntech:~$ sudo systemctl start demo.service [sudo] password for student: student@vulntech:~$ systemctl is-active demo.service active student@vulntech:~$ sudo systemctl stop demo.service student@vulntech:~$ systemctl is-active demo.service inactive
Enabling: start at every boot
start is forgotten on reboot; enable makes the choice permanent by linking the service into the boot sequence. enable --now does both at once:
sudo systemctl enable --now demo.service
systemctl is-enabled demo.service
systemctl is-active demo.serviceIn the terminal
student@vulntech:~$ sudo systemctl enable --now demo.service [sudo] password for student: Created symlink /etc/systemd/system/multi-user.target.wants/demo.service → /etc/systemd/system/demo.service. student@vulntech:~$ systemctl is-enabled demo.service enabled student@vulntech:~$ systemctl is-active demo.service active
Common mistake:
startandenableare independent. A service you onlystartis gone after a reboot; one you onlyenableisn't running until the next boot. Useenable --nowwhen you want both.
Remember:
start/stop/restartact now;enable/disableset what happens at boot.enable --nowdoes both;is-activeandis-enabledreport the two states.