Skip to content

Instantly share code, notes, and snippets.

@drmalex07
Created September 30, 2020 11:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save drmalex07/66e541a037945e44297d75dfb20799e5 to your computer and use it in GitHub Desktop.
Save drmalex07/66e541a037945e44297d75dfb20799e5 to your computer and use it in GitHub Desktop.
An oneshot systemd service for loading IPVS table. #ipvs #ipvsadm #virtual-servers #linux-virtual-servers #systemd

README - Restore IPVS table (systemd service)

Lets assume our IPVS table is saved under /usr/local/etc/ipvs-table (e.g. as the output of ipvsadm -S).

Create the service file at /etc/systemd/system/restore-ipvs-table.service:

[Unit]
Description=Restore IPVS table from file
After=network.target

[Service]
Type=oneshot
# The dump file is the output of: ipvsadm -S
Environment=DUMP_FILE=/usr/local/etc/ipvs-table
ExecStart=/usr/local/bin/restore-ipvs-table.sh
StandardOutput=journal

[Install]
WantedBy=multi-user.target

Create the oneshot script at /usr/local/bin/restore-ipvs-table.sh:

#!/bin/bash
set -e

test -n "${DUMP_FILE}"
test -f "${DUMP_FILE}"

ipvsadm -C
cat ${DUMP_FILE} | ipvsadm -R
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment