We can use the ExeStartPre and ExeStopPost commands from the fleetctl unit file to add and delete a virtual IP when our service is started and stopped.
[Unit] Description=Example After=docker.service Requires=docker.service [Service] Restart=always ExecStartPre=/usr/bin/sudo /usr/bin/ip addr add 172.17.8.100/24 dev enp0s8 ExecStart=/usr/bin/docker run --rm=true --name webapp -p 80:80 coreos/apache /usr/sbin/apache2ctl -D FOREGROUND ExecStop=/usr/bin/docker stop webapp ExecStopPost=/usr/bin/sudo /usr/bin/ip addr del 172.17.8.100/24 dev enp0s8 [Install] WantedBy=multi-user.target
No comments:
Post a Comment