Giter VIP home page Giter VIP logo

restarter's Introduction

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.

restarter's People

Contributors

amkartashov avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.