Gracefully shutdown services in Docker container
The problem is `docker stop` only sends SIGTERM to the PID 1 inside the
container, and the PID 1 (`/bin/sh -c ...`) does not take care of
signals. Hence the services (e.g., postgresql, redis, sidekiq, etc)
never have chances to graceful shutdown. Docker just kills the container
after its 10 seconds timeout by default.
What this commit does:
1) Add a wrapper as the default executable of Docker container. Which
starts services through `runit`, reconfigure Gitlab by `gitlab-ctl`
and gracefully shutdown all services when a SIGTERM is received.
2) Create an `assets` directory for assets.
3) Add `.dockerignore` file.
Now you'll see the following log messages after `docker stop`:
```
SIGTERM signal received, try to gracefully shutdown all services...
ok: down: logrotate: 1s, normally up
ok: down: nginx: 0s, normally up
ok: down: postgresql: 1s, normally up
ok: down: redis: 0s, normally up
ok: down: sidekiq: 0s, normally up
ok: down: unicorn: 0s, normally up
```
Signed-off-by: kfei <kfei@kfei.net>
2014-12-17 03:53:17 -05:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
function sigterm_handler() {
|
|
|
|
echo "SIGTERM signal received, try to gracefully shutdown all services..."
|
|
|
|
gitlab-ctl stop
|
|
|
|
}
|
|
|
|
|
|
|
|
trap "sigterm_handler; exit" TERM
|
|
|
|
|
|
|
|
function entrypoint() {
|
|
|
|
/opt/gitlab/embedded/bin/runsvdir-start &
|
2015-05-06 09:32:29 -04:00
|
|
|
gitlab-ctl reconfigure # will also start everything
|
|
|
|
gitlab-ctl tail # tail all logs
|
Gracefully shutdown services in Docker container
The problem is `docker stop` only sends SIGTERM to the PID 1 inside the
container, and the PID 1 (`/bin/sh -c ...`) does not take care of
signals. Hence the services (e.g., postgresql, redis, sidekiq, etc)
never have chances to graceful shutdown. Docker just kills the container
after its 10 seconds timeout by default.
What this commit does:
1) Add a wrapper as the default executable of Docker container. Which
starts services through `runit`, reconfigure Gitlab by `gitlab-ctl`
and gracefully shutdown all services when a SIGTERM is received.
2) Create an `assets` directory for assets.
3) Add `.dockerignore` file.
Now you'll see the following log messages after `docker stop`:
```
SIGTERM signal received, try to gracefully shutdown all services...
ok: down: logrotate: 1s, normally up
ok: down: nginx: 0s, normally up
ok: down: postgresql: 1s, normally up
ok: down: redis: 0s, normally up
ok: down: sidekiq: 0s, normally up
ok: down: unicorn: 0s, normally up
```
Signed-off-by: kfei <kfei@kfei.net>
2014-12-17 03:53:17 -05:00
|
|
|
}
|
|
|
|
|
2015-07-14 13:46:51 -04:00
|
|
|
if [[ ! -e /etc/gitlab/gitlab.rb ]]; then
|
|
|
|
cp /assets/gitlab.rb /etc/gitlab/gitlab.rb
|
|
|
|
chmod 0600 /etc/gitlab/gitlab.rb
|
|
|
|
fi
|
|
|
|
|
Gracefully shutdown services in Docker container
The problem is `docker stop` only sends SIGTERM to the PID 1 inside the
container, and the PID 1 (`/bin/sh -c ...`) does not take care of
signals. Hence the services (e.g., postgresql, redis, sidekiq, etc)
never have chances to graceful shutdown. Docker just kills the container
after its 10 seconds timeout by default.
What this commit does:
1) Add a wrapper as the default executable of Docker container. Which
starts services through `runit`, reconfigure Gitlab by `gitlab-ctl`
and gracefully shutdown all services when a SIGTERM is received.
2) Create an `assets` directory for assets.
3) Add `.dockerignore` file.
Now you'll see the following log messages after `docker stop`:
```
SIGTERM signal received, try to gracefully shutdown all services...
ok: down: logrotate: 1s, normally up
ok: down: nginx: 0s, normally up
ok: down: postgresql: 1s, normally up
ok: down: redis: 0s, normally up
ok: down: sidekiq: 0s, normally up
ok: down: unicorn: 0s, normally up
```
Signed-off-by: kfei <kfei@kfei.net>
2014-12-17 03:53:17 -05:00
|
|
|
entrypoint
|