1

I have 2 servers started as independent systemd units. They are listening on port 3001 and 3002 respectively.

I want to achieve a rolling restart (also known as rolling update or ramped update, more info on this deployment strategy).

Here is the sequence of event I am looking for when running 'systemctl restart app':

  1. app-unit1 running && app-unit2 running
  2. app-unit1 stopped
  3. app-unit1 started
  4. app-unit2 stopped
  5. app-unit2 started

By doing so, with my loadbalancer in front of these servers, I can reload these servers without interrupting the global service.

I implemented the configuration described in this article:

/etc/systemd/system/app.service

[Unit]
Description=app
After=network-online.target

[Service]
Type=oneshot
ExecStart=/bin/true
RemainAfterExit=yes

[Install]
WantedBy=multi-user.target

/etc/systemd/system/app-unit1.service

[Unit]
Description=app-unit1
PartOf=app.service
After=app.service

[Service]
Type=notify

Environment=PORT=3001
ExecStart=/usr/bin/start-server.sh
Restart=on-failure

[Install]
WantedBy=app.service

/etc/systemd/system/app-unit2.service

[Unit]
Description=app-unit2
PartOf=app.service
After=app.service
After=app-unit1.service

[Service]
Type=notify

Environment=PORT=3002
ExecStart=/usr/bin/start-server.sh
Restart=on-failure

[Install]
WantedBy=app.service

The resulting sequence of event when running 'systemctl restart app':

  1. app-unit1 running && app-unit2 running
  2. app-unit2 stopped && app-unit1 stopped (not sure which one is stopped first)
  3. app-unit1 started
  4. app-unit2 started

So, I have an interruption of service between 1 and 2.

The question is: how to achieve rolling restart with systemd ?

Your Answer

By clicking "Post Your Answer", you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.