config can be in /etc/default/ instead of /etc/sysconfig/
[Samba.git] / ctdb / config / ctdb-crash-cleanup.sh
blobf7ccfc8b732eec1bf37f71d0f869f21f95b4d8ff
1 #!/bin/sh
3 # This script can be called from a cronjob to automatically drop/release
4 # all public ip addresses if CTDBD has crashed or stopped running.
7 [ -z "$CTDB_BASE" ] && {
8 CTDB_BASE=/etc/ctdb
11 [ -z "$CTDB_PUBLIC_ADDRESSES" ] && {
12 CTDB_PUBLIC_ADDRESSES=$CTDB_BASE/public_addresses
15 [ ! -f "$CTDB_PUBLIC_ADDRESSES" ] && {
16 echo "No public addresses file found. Cant cleanup."
17 exit 1
20 # if ctdb is running, just return
21 ctdb status 2>/dev/null && {
22 exit 0
25 (cat /etc/{sysconfig,default}/ctdb | egrep "^CTDB_NATGW_PUBLIC_IP" | sed -e "s/.*=//" -e "s/\/.*//";cat "$CTDB_PUBLIC_ADDRESSES" | cut -d/ -f1) | while read _IP; do
26 _IP_HELD=`/sbin/ip addr show | grep "inet $_IP/"`
27 [ -z "$_IP_HELD" ] || {
28 _IFACE=`echo $_IP_HELD | sed -e "s/.*\s//"`
29 _NM=`echo $_IP_HELD | sed -e "s/.*$_IP\///" -e "s/\s.*//"`
30 logger "Removing public address $_IP/$_NM from device $_IFACE"
31 /sbin/ip addr del $_IP/$_NM dev $_IFACE
33 done