Skip to content

Instantly share code, notes, and snippets.

@kanazux
Last active August 29, 2015 14:05
Show Gist options
  • Save kanazux/d3c04c1a96ca5f172c4d to your computer and use it in GitHub Desktop.
Save kanazux/d3c04c1a96ca5f172c4d to your computer and use it in GitHub Desktop.
path shutdown carp
#!/bin/sh
if [ ! -f /usr/local/bin/shutdown_interface_vip.php ]; then
cat <<EOF >/usr/local/bin/shutdown_interface_vip.php
<?php
require_once('interfaces.inc');
require_once('config.inc');
\$ifaces = \$config['virtualip']['vip'];
if(is_array(\$ifaces)){
foreach(\$ifaces as \$iface){
if(\$iface['mode'] == 'carp')
exec("/sbin/ifconfig vip{\$iface['vhid']} down");
}
}
?>
EOF
chmod +x /usr/local/bin/shutdown_interface_vip.php
fi
if [ -f /etc/rc.halt ]; then
sed -i.bak 's/\/sbin\/shutdown -p now//g' /etc/rc.halt
cat <<EOF >>/etc/rc.halt
if [ `/sbin/ifconfig | egrep '^vip[0-9]' | egrep -ic 'carp.*master` -gt 0 ] && [ -f /usr/local/bin/shutdown_interface_vip.php ]; then
/usr/local/bin/php -f shutdown_interface_vip.php
fi
/sbin/shutdown -p now
EOF
fi
#!/bin/sh
# $Id$
if ! /usr/bin/lockf -s -t 30 /tmp/config.lock /usr/bin/true; then
echo "Cannot halt at this moment, a config write operation is in progress and 30 seconds have passed."
exit -1
fi
sleep 1
if [ `/sbin/ifconfig | egrep '^vip[0-9]' | egrep -ic 'carp.*master` -gt 0 ] && [ -f /usr/local/bin/shutdown_interface_vip.php ]; then
/usr/local/bin/php -f shutdown_interface_vip.php
fi
/sbin/shutdown -p now
<?php
require_once('interfaces.inc');
require_once('config.inc');
$ifaces = $config['virtualip']['vip'];
if(is_array($ifaces)){
foreach($ifaces as $iface){
if($iface['mode'] == 'carp')
exec("/sbin/ifconfig vip{$iface['vhid']} down");
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment