Execute script when failover happens?



  • Is it somehow possible to execute a script when a slave node "promotes" to master? This would be great because right now if one machine fails, there's the possibility nobody notices it.


  • Rebel Alliance Developer Netgate

    Sure, this is possible on 1.2.3 and 2.0

    2.0 already has the code in /etc/devd.conf to do this, but you can edit it into the end of /etc/devd.conf (and either restart devd or reboot, rebooting is probably easier):

    # CARP notify hooks. This will call carpup/carpdown with the
    # interface (carp0, carp1) as the first parameter.
    notify 100 {
        match "system"          "IFNET";
        match "type"            "LINK_UP";
        match "subsystem"           "carp";
        action "/etc/rc.carpmaster $subsystem";
    };
    
    notify 100 {
        match "system"          "IFNET";
        match "type"            "LINK_DOWN";
        match "subsystem"           "carp";
        action "/etc/rc.carpbackup $subsystem";
    };
    
    

    And then it will exec /etc/rc.carpmaster when it becomes a master, and /etc/rc.carpbackup when it becomes a backup. You can change the script names if you want.

    2.0 can notify by e-mail or growl when such a switch happens.



  • Thank you, that seems to do the trick!


Log in to reply