Skip to content

Services

A service is a program the machine keeps running: started at every boot (also after a suspend, which is a reboot), restarted when it exits, with its output in a log file. Use it for anything that should outlive your SSH session or your agent’s turn: a dev server, a worker, the agent itself.

space-env services create notes --restart on-failure -- sh -c "while sleep 60; do date; done"
space-env services list
space-env services logs notes --lines 20
space-env services stop notes
space-env services start notes
space-env services delete notes
  • --restart: always (the default), on-failure (only after a non-zero exit) or never. Restarts back off from 1 to 30 seconds.
  • stop is sticky: the service stays stopped, also after a reboot, until start.
  • Stopping is a SIGTERM to the service’s program, then up to 10 seconds to end, then a SIGKILL. A suspend stops every service this way before the machine powers off, so a program that writes its state when asked to stop (a database, a browser) has it on disk.
  • --needs other starts other first at boot.
  • --env KEY=VALUE and --cwd DIR set its environment and working directory.
  • Logs are in /var/log/space-env/<name>.log, rotated at 10 MiB; tail -f follows one.
  • A service that dies (a non-zero exit or a signal, not a stop) is reported as a machine event, which owners and admins see in the portal’s Audit log (when the agent dies).
  • A definition with "on_demand": true isn’t started at boot: it waits for its first start, and after a reboot waits again. The agent’s browser is one.
  • Services are handled by the machine itself, so they work without the platform being reachable. Definitions are files in /etc/vmagent/services.d/ (one JSON file each), and editing those by hand takes effect at the next boot.

Don’t start long-lived programs in the background of a shell (nohup … &) instead: they die with the shell or the next suspend, and nothing restarts them. The guide a service that survives a suspend shows the whole setup.

Last updated on