runsvinit/README.md

48 lines
1.8 KiB
Markdown
Raw Normal View History

2015-09-28 21:52:53 +00:00
# runsvinit [![Circle CI](https://circleci.com/gh/peterbourgon/runsvinit.svg?style=svg)](https://circleci.com/gh/peterbourgon/runsvinit)
2015-09-25 10:30:24 +00:00
2015-10-07 13:39:45 +00:00
If you have a Docker container that's a collection of runit-supervised daemons, this process is suitable for use as the ENTRYPOINT.
2015-09-25 12:40:31 +00:00
See [the example](https://github.com/peterbourgon/runsvinit/tree/master/example).
2015-09-25 10:30:24 +00:00
2015-10-07 13:39:45 +00:00
**Why not use runit(8) directly?**
2015-09-25 10:30:24 +00:00
2015-10-07 13:39:45 +00:00
[runit(8)](http://smarden.org/runit/runit.8.html) is designed to be used as process 1.
And, if you provide an `/etc/service/ctrlaltdel` script, it will be executed when runit receives the INT signal.
So, we could use that hook to gracefully terminate our services.
But Docker only sends TERM on `docker stop`.
2015-09-25 10:30:24 +00:00
2015-10-07 13:39:45 +00:00
Note that the container stop signal [will become configurable](https://github.com/docker/docker/pull/15307) in Docker 1.9.
Once Docker 1.9 ships, this utility will be obsolete.
2015-09-25 10:30:24 +00:00
2015-10-07 13:39:45 +00:00
**Why not just exec runsvdir(8) directly?**
If [runsvdir(8)](http://smarden.org/runit/runsvdir.8.html) receives a signal, it doesn't wait for its supervised processes to exit before returning.
**Why not wrap runsvdir(8) in a simple shell script?**
Process 1 has the additional responsibility of [reaping orphaned child processes](https://blog.phusion.nl/2015/01/20/docker-and-the-pid-1-zombie-reaping-problem/).
To the best of my knowledge, there is no sane way to do this with a shell script.
Otherwise, indeed, this would work great:
2015-09-25 10:30:24 +00:00
```sh
#!/bin/sh
sv_stop() {
for s in $(ls -d /etc/service/*)
do
/sbin/sv stop $s
done
}
trap "sv_stop; exit" SIGTERM
/sbin/runsvdir /etc/service &
wait
```
2015-09-25 12:43:06 +00:00
**Why not use my_init from [phusion/baseimage-docker](https://github.com/phusion/baseimage-docker)?**
2015-09-25 10:30:24 +00:00
2015-10-07 13:39:45 +00:00
my_init depends on Python 3, which might be a big dependency for such a small responsibility.
2015-09-25 10:30:24 +00:00
**So this is just a stripped-down my_init in Go?**
Basically, yes.