Horust

Logo

Horust is a supervisor / init system written in rust and designed to run inside containers.

View the Project on GitHub FedericoPonzi/Horust

Documentation

Table of contents:

When starting horust, you can optionally specify where it should look for services and uses /etc/horust/services by default.

Service configuration

This section describes all the possible options you can put in a service.toml file. You should create one different service.toml for each command you want to run. Apart from the user parameter, everything should work even with an unprivileged user.

Service templating

Services can, but not have to, be templated. Currently, this feature works only via environment variables. The templating engine uses bash expansion mechanism. Each part of the service configuration can be used in tandem with the templating. Additionally, multiple variables can be safely used if needed. The engine does not support processing the shell queries, for example $(cat /proc/config.gz) will not be processed and will be used on face value.

Before loading the service file, Horust will internally search and replace every value with environment variable if it exists. In this case, the ${USER} block is replaced by the environment’s USER variable. Alternatively $USER without braces is also accepted, although heavily discouraged. Variable names must follow rules of the operating system, which means that, in case of bash, variables are case-sensitive, and usage of special characters is somewhat restricted. You can use any variable your system provides, or you also can set and/or export those before running Horust.

Below are some simple strings that will be properly templated. Simple feature usage in configuration is showcased in the provided sample service.

...
user = "${USER}"
stderr = "${HOME}${HORUST_LOGDIR}/stderr"
...

Main section

# name = "myname"
command = "/bin/bash -c 'echo hello world'"
start-delay = "2s"
start-after = ["database", "backend.toml"]
stdout = "STDOUT"
stderr = "/var/logs/hello_world_svc/stderr.log"
stdout-rotate-size = "100MB"
stdout-should-append-timestamp-to-filename = false
user = "${USER}"
working-directory = "/tmp/"

Restart section

[restart]
strategy = "never"
backoff = "0s"
attempts = 0

The delay between attempts is calculated as: backoff * attempts_made + start-delay. For instance, using:

Will wait 1 second and then start the service. If it doesn’t start:

If the attempts are over, then the service will be considered FailedFinished and won’t be restarted. The attempt count is reset as soon as the service’s state changes to running. This state change is driven by the health-check component, and a service with no health-check will be considered as Healthy and it will immediately pass to the running state.

Healthiness Check

[healthiness]
http-endpoint = "http://localhost:8080/healthcheck"
file-path = "/var/myservice/up"
max-failed = 3

Failure section

[failure]
successful-exit-code = [0, 1, 255]
strategy = "ignore"

Environment section

[environment]
keep-env = false
re-export = ["PATH", "DB_PASS"]
additional = { key = "value" } 

Termination section

[termination]
signal = "TERM"
wait = "10s"
die-if-failed = ["db.toml"]

State machine

State machine

You can compile this on https://state-machine-cat.js.org/

initial => Initial : "Will eventually be run";
Initial => Starting : "All dependencies are running, a thread has spawned and will run the fork/exec the process";
Initial => Finished : "System shutdown before service had a chance to run (Kill Event)"; 
Starting => Started : "The service has a pid";
Started => Running : "The service has met healthiness policy";
Started => Failed : "Service cannot be started";
Started => Success : "Service finished very quickly";
Failed => FinishedFailed : "Restart policy";
Started => InKilling : "Received a Kill event";
InKilling => Finished : "Successfully killed";
InKilling => FinishedFailed : "Forcefully killed (SIGKILL)";
Running => Failed  : "Exit status is not successful";
Running => Success  : "Exit status == 0";
Running => InKilling: "Received a Kill event";
Success => Initial : "Restart policy applied";
Success => Finished : "Based on restart policy";
Failed => Initial : "restart = always|on-failure";

Horust’s configuration

Horust can be configured by using the following parameters:

# Default time to wait after sending a `sigterm` to a process before sending a SIGKILL.
unsuccessful-exit-finished-failed = true

All the parameters can be passed via the cli (use horust --help) or via a config file. The default path for the config file is /etc/horust/horust.toml.

Running a single command

You can wrap a single command with horust by running:

./horust -- bash /tmp/myscript.sh

This is equivalent to running a single service defined as:

command= "bash /tmp/myscript.sh"

This will run the specified command as a one shot service, so it won’t be restarted after exiting.

Commands have precedence over services, so if you specify both a command and a services-path, the command will be executed and the --services-path is ignored.

Multiple service directories

You can you use the --services-path parameter to specify either a directory containing .toml services to run, or point it to a .toml service file to run.

You can specify multiple service directories by passing more than one --services-path arguments.

horust --services-path ./services/core --services-path ./services/extra --services-path ./my-service.toml

These directories are loaded at once and treated just like all *.toml files were in single shared directory. It means that for example service from ./services/extra can depend on service from ./services/core. The last parameter is used to load a single service file instead of a directory.

Plugins (WIP)

Horust works via message passing, it should be fairly easy to plug additional components connected to its bus. At this time is unclear if there is the need for this. Please raise an issue if you’re interested in seeing this feature.

Checking system status (WIP)

WIP: https://github.com/FedericoPonzi/Horust/issues/31 The idea is to create another binary, which will somehow report the system status. A systemctl for Horust.