bandsintown / docker-alpine

Base Docker images based on Alpine Linux
BSD 2-Clause "Simplified" License
0 stars 3 forks source link

Locking mechanism to safely reload or restart service #4

Open nhuray opened 7 years ago

nhuray commented 7 years ago

Context

We are using Consul Template to manage dynamically the configuration of our apps.

Depending of the application we might have 3 behaviours:

For the 2 last cases, we want to reload / restart services one by one in order to prevent service interruption.

See this issue: https://github.com/hashicorp/consul-template/issues/340

Implementation

Consul already provides a lock mechanism to create a distributed semaphore based on Consul Key: https://www.consul.io/docs/commands/lock.html

We want to implement this mechanism wrapping the complexity to configure consul-template and consul lock command in a script ct-supervise :

ct-supervise -n 1  'nginx -s reload'

Options

These options might be passed to the ct-supervise script

--n: Optional, limit of lock holders. Defaults to 1. The underlying implementation switches from a lock to a semaphore when increased past one. All locks on the same prefix must use the same value.

--name: Optional name to associate with the underlying session. If not provided, one is generated based on the child command.

--pass-stdin: Pass stdin to child process.

The only required argument is the command to run:

ct-supervise  'nginx -s reload'
ritxos commented 7 years ago

Hi @nhuray,

anything on this, I'm curiously looking out for rolling restarts?

nhuray commented 6 years ago

Hi @ritxos,

I didn't start working on this I just discussed it long time ago: https://github.com/hashicorp/consul-template/issues/340

We are using a workaround incrementing the splay setting in Consul Template to be sure the processes are not restarting at the same time. For sure it's not really deterministic and a locking strategy for rolling restarts is better. I might have time to work on it after Xmas.