amkartashov / restarter

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Restarter

Restarter executes specified binary and restarts it in case it fails.

Useful in Kubernetes environment if you want your app restart fast without waiting for orchestrator to recreate container for you.

Overview

Inspired by this PR for tini and this article Implementing pid1 with Rust and async/await

The goal of this tool is to restart the service quickly in k8s environment, skipping default restart delay of 10 seconds.

Note: restarter does not serve as Pid 1 service, f.e. it does not reap all zombies as tini does. If you want this functionality, use pid1 -> restarter -> service, where pid1 may be tini or kubernetes pause. Or just make sure that service takes care of its child processes.

Restarter forwards unix signal it receives to a service. So if k8s sends SIGTERM to container, you can be sure the service will get it. If service is killed with one of the termination signals (SIGTERM, SIGINT, SIGQUIT), restarter won't retry.

If restarter exits, it uses service exit code, or 128 + signal number which terminated the service.

Usage and configuration

Restarter takes binary path and args from command line, f.e. restarter /bin/cat /tmp/text.txt.

Restarter tries to execute binary to completion, this means it will stop retrying as soon as the child process finishes with success.

By default, restarter will try to execute binary 3 times. This is controlled by the value of environment variable RESTARTER_RETRIES. Set it to 0 to retry indefinitely.

Restarter resets retries counter if running process lasts more than 1 hour. You can change this value with RESTARTER_RESET_RETRIES_SECONDS and disable resetting with RESTARTER_RESET_RETRIES_SECONDS=0.

Also, restarter will stop trying if the process fails to fast. By default, if process fails less than in 1 second, restarter will exit. You can change this behavior with environment variable RESTARTER_FAST_FAIL_SECONDS. If you set it to 0, restarter will not check for fast failures.


To sum up, restater will stop in below cases:

  1. number of retries is over;
  2. service fails too fast;
  3. service is killed with termination signal;
  4. service finished successfully.

Logging

Logging is configured via env variables RESTARTER_LOG and RESTARTER_LOG_ENCODER.

Possible values for RESTARTER_LOG can be checked in env_logger docs, you can think that it is warn by default. You can disable restarter log messages with RESTARTER_LOG=off and enable debug with RESTARTER_LOG=debug.

RESTARTER_LOG_ENCODER allows to set log formatting, by default it is console (single line messages). To emit Json messages suitable for Google Cloud Logging, set it to json.

About


Languages

Language:Starlark 58.9%Language:Rust 41.1%