Frequently Asked Question
How do I write a simple .service unit?
A minimal service file has three sections. [Unit] carries metadata and dependencies;
a Description= line, After= to order this unit after another, and Wants= or
Requires= to express soft or hard dependencies. [Service] describes how to run the
program: Type= (usually exec or simple for a long-running foreground program),
User= and Group= to drop privileges, WorkingDirectory=, ExecStart= for the
command itself, and Restart=on-failure to have systemd respawn the service if it dies.
[Install] tells systemd where the unit plugs in when you enable it, almost always
WantedBy=multi-user.target.
Save the file as /etc/systemd/system/myservice.service, run sudo systemctl daemon-reload so systemd notices the new file, then sudo systemctl enable --now myservice to start it now and at every boot. systemctl status myservice will confirm
it is running and show the most recent log lines, and journalctl -u myservice will
show the full log history.