Skip to content

A service is a long-running program on your VM, such as a web server or a database. It comes back after every wake, unless you stopped it, and it starts again when it ends.

The examples use a VM named api and a service named web. Set VM to the VM’s id and SI_API_KEY to a key from API keys:

Terminal window
export VM=6f1c0f0e8a
export SI_API_KEY=si_...

si svm svc add writes a definition to /etc/slashinfra/services/web.json on the VM’s disk and starts the program as user. The definition stays on the disk across a sleep, so the service comes back after a wake.

Inside the VM, the same subcommands are on svc; si svm svc sends them from your laptop. The VM comes before the command, as in si svm svc api add web .... Without it, si uses the VM set with si use.

Terminal window
si svm svc api add web --port 3000 --dir /home/user --env PYTHONUNBUFFERED=1 -- python3 -m http.server 3000
Output
web

The words after -- are the program and its arguments, run without a shell. For a pipeline, a variable or a redirection, use /bin/bash -c '...'. The program must stay in the foreground. When its leader ends, the VM ends the rest of its processes and starts it again. A program that should run once belongs in a job.

A new service starts within a second.

--port names the TCP port the program listens on. A preview at https://3000-<id>.slashinfra.dev waits up to 10 seconds while the service is starting. A request made during a start can reach the program. The program must listen on 0.0.0.0 or localhost.

The port also decides what a sleep keeps. A running service that declares a port is saved in memory and its process resumes after the wake. A service without a port stops for a sleep on disk and starts again after the wake. A service you stopped stays stopped.

To share the address through a link or make it public, open the port. See Web addresses.

The list has one row per definition, by name. STATE is the state of the service and PID is the process id of the program. RESTARTS counts the restarts after a crash, and PORT is the declared port or -. A service with no process shows - in PID.

  1. Open SVMs and select api.

  2. Select Terminal. A terminal to the VM opens in a new tab.

  3. Run the command below. svc manages the services of the VM.

    Terminal window
    svc ls
    Output
    NAME STATE PID RESTARTS PORT
    web running 1234 0 3000

svc logs prints the whole log of a service, standard output and standard error together. The log is /var/log/services/web.log on the VM’s disk. It survives a sleep and the deletion of the service. --follow keeps printing new lines until you stop it.

Terminal window
si svm svc api logs web
Output
Serving HTTP on 0.0.0.0 port 3000 (http://0.0.0.0:3000/) ...

Stop ends the program and every process it started, then records the stop on the definition. The service stays stopped across a sleep and a wake. The command waits up to 15 seconds for stopped; a program that does not end answers with its state.

Terminal window
si svm svc api stop web
Output
web stopped

Start clears the stop, starts the program now and starts it again after every wake. A service that already runs keeps its process. The command waits up to 15 seconds for running. A service with a port is running when the port accepts a connection.

Terminal window
si svm svc api start web
Output
web running

Restart stops the program and starts it again, and resets RESTARTS to 0. Use it after you change the program or its files; the definition keeps its flags. The command waits up to 15 seconds for running.

Terminal window
si svm svc api restart web
Output
web running

Delete removes the definition and stops the program. The log stays at /var/log/services/web.log, and the command waits up to 10 seconds for stopped. A service that another definition needs cannot be deleted until you delete that definition.

Terminal window
si svm svc api rm web
Output
web removed
Field Type Default Allowed values What it changes
name (argument) string Required 1 to 64 letters, digits, - and _, starting with a letter or digit; daemon and units are reserved The service name and its definition file. It is unique on the VM.
port (--port) integer None 1 to 65535 The TCP port the program listens on. A preview waits while the service is starting.
needs (--needs) string None Names of services of the same VM, as A,B The services that must be running before this one starts.
dir (--dir) string /home/user An absolute path The working directory of the program.
env (--env) string None KEY=VALUE, repeated; the key has letters, digits and _, and does not start with SVM_ A variable of the service’s process.
program (after --) array Required A program and its arguments; the first word is searched in PATH when it has no / The program to run, without a shell.
ref (<SVM>) string The VM set with si use A VM name, or its id The VM whose services these are.
project (--project) string default A project name, or its proj_ id The project of the VM. SI_PROJECT applies when the flag is absent.

Scroll horizontally to see all columns.

--needs accepts only names of services on the same VM. An unknown name, or a cycle, keeps svc from applying any change until you add the missing service or delete the definition that names it.

When a program ends without a stop, the VM starts it again after 1 second. The wait then grows to 2, 4, 8, 16 and at most 30 seconds. RESTARTS counts the restarts, and the state is backoff while the VM waits.

State What it means for you What you can do
running The program runs. With a declared port, the port accepts a connection. Read the log, stop, restart or delete the service.
starting The program runs but its declared port does not accept a connection yet. Wait; read the log if it stays. A preview waits up to 10 seconds.
backoff The program ended and the VM waits to start it again. RESTARTS counts the restarts. Read the log to find why it ends; fix the program, or stop the service.
stopped No process runs. The definition is stopped, or a service it needs is not running. Start it, or delete it.

Scroll horizontally to see all columns.

Code When Fix
svm_not_found The VM name or id names no VM of your organization or key scope. Check the name, the id and the project.
svm_unreachable The node of the VM did not answer. Wait for Retry-After and retry.
not_ready A preview of the declared port waits on a wake and the VM’s readiness port does not answer in its timeout. Check the log with si svm svc api logs web, then retry.

Scroll horizontally to see all columns.

The VM’s svc reports a refused command in the reply. The HTTP status is 200, X-Exit-Code is 1, and si exits 1. The message names the fix, for example svc: no service web; svc ls shows the services, svc: service web already exists; use svc restart web, or svc: web is needed by db; remove it first.

Errors that any request can return are in the error catalog.

Every operation on this page goes to the VM’s own host. A key reaches it when it belongs to the VM’s organization and includes the VM’s project. The VM host checks that scope and does not check a key action. A grant reaches only the methods, paths and arguments it names; see Grants.

Operation Who can Key action
Add a service Any member with a key that includes the VM’s project None
List services Any member with a key that includes the VM’s project None
Read the log of a service Any member with a key that includes the VM’s project None
Stop a service Any member with a key that includes the VM’s project None
Start a service Any member with a key that includes the VM’s project None
Restart a service Any member with a key that includes the VM’s project None
Delete a service Any member with a key that includes the VM’s project None

Scroll horizontally to see all columns.

  • A VM has no count limit on services: svc starts every definition in /etc/slashinfra/services that is not stopped, each in its own cgroup and with its own log.
  • A service name has 1 to 64 letters, digits, - and _, and starts with a letter or digit. daemon and units are reserved.
  • --port is 1 to 65535.
  • A crash restarts the service after 1 second, then 2, 4, 8, 16 and at most 30 seconds.
  • A stop sends the service’s first signal (SIGTERM by default; the guest svc add --stop-signal INT selects SIGINT). It gives the program and its processes 10 seconds, then stops what is left.
  • A preview of a declared port waits up to 10 seconds while the service is starting.
  • A running service that declares a port is saved in memory at the memory deadline and resumes after the wake. A service without a port stops for a sleep on disk and starts again after the wake, unless you stopped it.
  • A log rotates when the service starts and the file is at least 10 MiB. It becomes <name>.log.1, replacing the previous rotation.
  • A service does not keep the VM awake. A timer or cron job inside the VM does not fire on a sleeping VM. Use a schedule for work at a set time.

The full list is in Limits.