Skip to content

aerospike/tini

 
 

Repository files navigation

Aerospike Tini - A fork of tini init

Aerospike tini is a fork of tini init with the additional features. The modified version of tini binary is called as-tinifor disambiguation.

Child process restart

This fork allows the child process to be restarted on a configurable signal that is sent to tini. This allows databases like Aerospike to restart without terminating the container. This is useful for applying configuration changes. The Aerospike server can restart without terminating the container. This has the effect of allowing Aerospike to restart and reuse the database indices build and stored in shared memory segments, which would be otherwise lost on a container restart. This considerably reduces the Aerospike server startup time as the indices do not need to be rebuilt.

Using as-tini

In Docker, you will want to use an entrypoint, so you don't have to remember to manually invoke Tini:

# Add Tini
ENV TINI_VERSION v1.0.1
ADD https://github.com/aerospike/tini/releases/download/${TINI_VERSION}/as-tini /as-tini
RUN chmod +x /as-tini
ENTRYPOINT ["/as-tini", "--"]

# Run your program under Tini
CMD ["/your/program", "-and", "-its", "arguments"]
# or docker run your-image /your/program ...

Verifying binaries via checksum

The as-tini and as-tini-static binaries have generated checksums (SHA1 and SHA256).

You can verify their checksums using sha1sum and sha256sum (which you may install using your package manager):

ENV TINI_VERSION v1.0.1
RUN wget --no-check-certificate --no-cookies --quiet https://github.com/aerospike/tini/releases/download/${TINI_VERSION}/as-tini \
    && wget --no-check-certificate --no-cookies --quiet https://github.com/aerospike/tini/releases/download/${TINI_VERSION}/as-tini.sha256sum \
    && echo "$(cat as-tini.sha256sum)" | sha256sum -c

Options

Verbosity

The -v argument can be used for extra verbose output (you can pass it up to 3 times, e.g. -vvv).

Subreaping

By default, Tini needs to run as PID 1 so that it can reap zombies (by running as PID 1, zombies get re-parented to Tini).

If for some reason, you cannot run Tini as PID 1, you should register Tini as a process subreaper instead (only in Linux >= 3.4), by either:

  • Passing the -s argument to Tini (as-tini -s -- ...)
  • Setting the environment variable TINI_SUBREAPER (e.g. export TINI_SUBREAPER=).

This will ensure that zombies get re-parented to Tini despite Tini not running as PID 1.

NOTE: Tini will issue a warning if it detects that it isn't running as PID 1 and isn't registered as a subreaper. If you don't see a warning, you're fine.

Remapping exit codes

Tini will reuse the child's exit code when exiting, but occasionally, this may not be exactly what you want (e.g. if your child exits with 143 after receiving SIGTERM). Notably, this can be an issue with Java apps.

In this case, you can use the -e flag to remap an arbitrary exit code to 0. You can pass the flag multiple times if needed.

For example:

as-tini -e 143 -- ...

Parent Death Signal

Tini can set its parent death signal, which is the signal Tini should receive when its parent exits. To set the parent death signal, use the -p flag with the name of the signal Tini should receive when its parent exits:

as-tini -p SIGTERM -- ...

NOTE: See [this PR discussion][12] to learn more about the parent death signal and use cases.

More

Existing Entrypoint

Tini can also be used with an existing entrypoint in your container!

Assuming your entrypoint was /docker-entrypoint.sh, then you would use:

ENTRYPOINT ["/as-tini", "--", "/docker-entrypoint.sh"]

Statically-Linked Version

Tini has very few dependencies (it only depends on libc), but if your container fails to start, you might want to consider using the statically-built version instead:

ADD https://github.com/aerospike/tini/releases/download/${TINI_VERSION}/as-tini-static /as-tini

Size Considerations

Tini is a very small file (in the 10KB range), so it doesn't add much weight to your container.

The statically-linked version is bigger, but still < 1M.

Building Tini

If you'd rather not download the binary, you can build Tini by running cmake . && make.

Before building, you probably also want to run:

export CFLAGS="-DPR_SET_CHILD_SUBREAPER=36 -DPR_GET_CHILD_SUBREAPER=37"

This ensure that even if you're building on a system that has old Linux Kernel headers (< 3.4), Tini will be built with child subreaper support. This is usually what you want if you're going to use Tini with Docker (if your host Kernel supports Docker, it should also support child subreapers).

Understanding Tini

After spawning your process, Tini will wait for signals and forward those to the child process, and periodically reap zombie processes that may be created within your container.

When the "first" child process exits (/your/program in the examples above), Tini exits as well, with the exit code of the child process (so you can check your container's exit code to know whether the child exited successfully).

Debugging

If something isn't working just like you expect, consider increasing the verbosity level (up to 3):

as-tini -v    -- bash -c 'exit 1'
as-tini -vv   -- true
as-tini -vvv  -- pwd

Authors

Refer to tini for details. This fork is maintained by Aerospike, Inc.

About

A tiny but valid `init` for containers

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • C 43.9%
  • Python 33.4%
  • Shell 16.8%
  • CMake 5.2%
  • Dockerfile 0.7%