Services: svc#
svc (also systemctl) starts, stops and restarts long-running apps, restarts them when they fail, starts enabled ones at boot and keeps their logs.
Services are system-wide and run as root, so starting, stopping, enabling, creating and editing them takes sudo. Anyone can list them, see their status and read their logs.
svc # every service: state, PID, uptime
sudo svc start hello # an example service that ships with Lepton
svc status hello # state, PID, restarts and the last log lines
svc logs hello -f # follow its output (also: journalctl -u hello -f)
sudo svc stop hello # stops it and every process it started
sudo svc new clock 'while true; do date; sleep 60; done'
sudo svc enable --now clock # start now and at every boot
Commands#
| Command | What it does |
|---|---|
svc / svc list | every service with its state, PID and uptime |
svc status NAME | details and the last 10 log lines |
svc start / stop / restart NAME… | control services |
svc enable / disable [--now] NAME | start at boot (--now also starts or stops it) |
svc logs NAME [-n N] [-f] | the log; -f follows it until C-c |
svc cat NAME | show the unit file |
svc new NAME COMMAND… | create ~/.config/lepton/services/NAME.service (root's: /root/.config/…) |
svc edit NAME | edit a unit in le; editing a shipped unit makes your own copy |
svc is-active / is-enabled NAME | for scripts: exit status 0 means yes |
journalctl -u NAME [-n N] [-f] | the same log, systemd-style |
Unit files#
A service is a unit file in systemd syntax, named NAME.service, in ~/.config/lepton/services/ (yours; it persists on an installed system) or /etc/lepton/services/ (shipped with Lepton). Yours override a shipped unit with the same name. ExecStart is any lsh command line.
[Unit]
Description=Static web server for ~/public (port 8080)
[Service]
ExecStart=mkdir -p ~/public && httpd -p 8080 ~/public
Restart=on-failure # no (default) | on-failure | always
RestartSec=2 # seconds before a restart (default 1)
Environment=GREETING=hi "NAME=a b"
WorkingDirectory=~ # default: your home
TimeoutStopSec=5 # wait this long before killing on stop
Other keys are ignored, and svc status lists them.
How services behave#
- Each run is a Lepton process tree under PID 1, so it shows in
ps. Stopping a service ends the whole tree (a terminate signal, then a kill afterTimeoutStopSec). - A clean exit leaves the service
inactive; a non-zero exit or a kill marks itfailed, andRestart=decides whether it comes back. The restarts stop after 5 starts in 10 seconds, as in systemd; a manualsvc startresets that. - Output goes to
/var/lib/lepton/log/NAME.log(rotated at 1 MiB), so on an installed system the log survives reboots. - Enabled services start at boot, once the data partition is mounted; the list is kept in
/var/lib/lepton/services. Every service is stopped cleanly before power-off and reboot.
Shipped services#
- hello: says hello every two seconds. The tutorial uses it.
- httpd: serves
~/publicon port 8080 withhttpd.
httpd#
httpd [-p PORT] [DIR] serves a directory over HTTP (static files only), using the web server built into Erlang/OTP. It makes a good first service:
sudo mkdir -p /root/public && echo 'hello' | sudo tee /root/public/index.html
sudo svc start httpd
curl http://localhost:8080/
Limits#
Only simple services: no dependencies between services (After=, Requires=), timers, socket activation or resource limits. Everything runs as root.
Commands on this page#
| Command | What it does | Usage |
|---|---|---|
svc | start, stop and restart long-running services (like systemctl) | svc [list|status|start|stop|restart|enable|disable|logs|cat|new|edit] ... |
journalctl | show service logs (journalctl -u NAME [-n N] [-f]) | journalctl -u NAME [-n N] [-f] |
httpd | serve a directory over HTTP (static files) | httpd [-p PORT] [DIR] |