< index

Rolling unit restart with fleetctl

· 1 minute read

I’ve been experimenting with CoreOS recently: an OS designed for large-scale deployments where docker containers are 1st class citizens. Maybe Kubernetes and the recent proliferation of “container engines” (Google & Amazon) are a better abstraction layer for container deployment, but it’s been fun to use etcd (CoreOS’s zookeeper-like distributed config manager) and fleet (a wrapper for service deployment around systemd).

In my CoreOS cluster I achieve HA for a stateless dockerised applications by load balancing across multiple running instances of a single service template, specifying the instances must run on separate VMs. When restarting such a service (for example to update it) a rolling restart across the CoreOS cluster is required for zero downtime: a feature fleet doesn’t support natively.

Voilà! A crude bash script to handle a rolling restart:


Given you’ve already loaded a template file myapp@.service and launched 2 containers:

fleetctl submit myapp@.service
fleetctl start myapp@1
fleetctl start myapp@2	

You can perform a rolling restart with:

./unit-restart.sh myapp

The script won’t take care of sidekicks like discovery services, but if you’re using these it should be relatively trivial to extend the script to include them.