Netgate Discussion Forum
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Search
    • Register
    • Login

    Execute script when failover happens?

    Scheduled Pinned Locked Moved HA/CARP/VIPs
    3 Posts 2 Posters 3.5k Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • B
      bmaster
      last edited by

      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.

      1 Reply Last reply Reply Quote 0
      • jimpJ
        jimp Rebel Alliance Developer Netgate
        last edited by

        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.

        Remember: Upvote with the 👍 button for any user/post you find to be helpful, informative, or deserving of recognition!

        Need help fast? Netgate Global Support!

        Do not Chat/PM for help!

        1 Reply Last reply Reply Quote 0
        • B
          bmaster
          last edited by

          Thank you, that seems to do the trick!

          1 Reply Last reply Reply Quote 0
          • First post
            Last post
          Copyright 2025 Rubicon Communications LLC (Netgate). All rights reserved.