# CARP interface up/down at reboot



## danbi (Aug 22, 2011)

I am playing with a setup of 'hosting' environment with redundant storage based on HAST. Monitoring and availability are managed by CARP.

CARP is configured as:


```
ifconfig_carp0="vhid 1 pass password advskew 20 a.b.c.d/24"
```

on both hosts. Upon reboot of any of the servers what happens is:

- the remaining running server switches role to MASTER.
- when the rebooting server comes up, it first becomes MASTER, then BACKUP:


```
carp0: link state changed to UP
carp0: MASTER -> BACKUP (more frequent advertisement received)
carp0: link state changed to DOWN
```

Trouble is, HAST and application startup/teardown are in response to devd events and immediately after boot at the "up" event the storage is activated and application started. Shortly after that, it is stopped again.

Is there way to avoid CARP putting the interface UP at boot? Or perhaps delay it until it is confirmed no other hosts on the network is MASTER.

Ideally, I would prefer to have the host that became MASTER for whatever reason, stay MASTER for as long as it is alive.


----------



## pbd (Aug 23, 2011)

danbi said:
			
		

> CARP is configured as:
> 
> 
> ```
> ...



Try greater advskew (e.g. 100) for one of the nodes.



			
				danbi said:
			
		

> Ideally, I would prefer to have the host that became MASTER for whatever reason, stay MASTER for as long as it is alive.



Make sure you have CARP preemtion turned off:


```
% sysctl net.inet.carp.preempt
net.inet.carp.preempt: 0
```


----------



## danbi (Aug 24, 2011)

If I put different advskew on different nodes, upon reboot of the node with lower advskew it will become MASTER, something I do not want to happen. CARP preemption is turned off by default.


----------



## Sylhouette (Aug 26, 2011)

Hello 

I want to do something the same.
I also found out that using the devd and the link up and down signal start the master slave script.

With hast, it is not very handy.
Could it be an idea to check against the mac adres in the script called by devd to make sure the server is master.
The slave does not become master as far as i know, devd just notice the link up and link down.

The arp table should have the mac adres of the master if you do a ping to the carp adres.

If the arp address is not the same as the mac address of the local interface, then exit the script.
In other words, we are not master, because we only signald an iface up down event, and the master does not know about that, and is still running. 
If they match, the arp lookup matches the local mac address, we are master, and we can run the hast failover script.

arp -a shows all the mac addresses, arp -da clears the arp table.

The order to do things should be something like this

clear apr table
Ping the carp address.
do the arp lookup and check the mac adres.

I do not know if it works, just an idea.


regards,
Johan


----------



## plamaiziere (Aug 26, 2011)

danbi said:
			
		

> If I put different advskew on different nodes, upon reboot of the node with lower advskew it will become MASTER, something I do not want to happen. CARP preemption is turned off by default.



You may enable carp latter (with a human intervention by example). This is just a ifconfig.

At work, for a carp dual-firewall, we use a NORMAL/RESCUE. When all is ok host1 is master and host2 is backup. If a failure occurs on host1, carp switches to host2. But we never switch from host2 to host1 without the intervention of a system administrator.

We use ifstated (in ports) to monitor the states, it's easy to issue the good commands when state change (but we use OpenBSD). For the boot problem, do not configure carp at boot time.


----------



## Sylhouette (Aug 27, 2011)

> At work, for a carp dual-firewall, we use a NORMAL/RESCUE. When all is ok host1 is master and host2 is backup. If a failure occurs on host1, carp switches to host2. But we never switch from host2 to host1 without the intervention of a system administrator.



And what happens when the master comes alive again on its own.
How does it prevent itself to become master.

is that done with net.inet.carp.preempt: 0 ?

I can imagine that it advertise itself as master again when it comes up.

If you use ifstated, then as far as i know there is no need to configure carp at boot eg in /etc/rc.conf? 

All i need to do then is let ifstated bring up the carp0 interface?

I am tring to use this on a mailserver.
But am fairly new to the whole carp thing.

I will open a new topic to prevent topic hyjacking.


regards,
Johan


----------



## plamaiziere (Aug 27, 2011)

Sylhouette said:
			
		

> And what happens when the master comes alive again on its own.
> How does it prevent itself to become master.



Just use ifconfig to bring the carp interface up or down.
(On OpenBSD you can use the carp demote counter which is not on FreeBSD)


```
ifconfig carp0 down // stop carp
ifconfig carp0 up   // up carp
```



> If you use ifstated, then as far as i know there is no need to configure carp at boot eg in /etc/rc.conf?
> 
> All i need to do then is let ifstated bring up the carp0 interface?



The question is WHEN do you want that the normally master becomes the master again? Ifstated is useful to check the states of the interfaces (it can run your own tests too) and to take actions, but that's all.

Regards.


----------

