[DRBD-user] DRBH/HeartBeat and CROND

Poyner, Brandon bpoyner at ccac.edu
Wed Aug 22 17:28:23 CEST 2007

Note: "permalinks" may not be as permanent as we would like,
direct links of old sources may well be a few messages off.


> assume you have a cronjob
> /etc/cron.d/who-is-primary
> which contains
> * * * * * /usr/local/bin/do-something.sh
> where
> --- /usr/local/bin/do-something.sh contains ---
> #!/bin/bash
> source /usr/local/bin/only-on-primary.sh
> 
> # do something...
> echo $HOSTNAME is primary...
> -----------------------------------------------
> and
> ------ only-on-primary.sh ---------------------
> # only an example, you may want to change to grep only for
> # grep -q '^ 0: .* st:Primary'
> if ! grep -q '^ 0: cs:Connected st:Primary/Secondary 
> ld:Consistent' /proc/drbd;
> then
> 	exit 0
> fi
> -----------------------------------------------
> 
> similarly, if you have something that you want to be executed only on
> the secondary, and only if it is a _consistent_ _uptodate_ copy
> (e.g. when you want to snapshot and drive a backup from the 
> secondary),
> grep for '^0 : cs:Connected st:Secondary/Primary ld:Consistent'

Another example using a different approach, assuming that you're
actually mounting the drbd device:

#!/bin/sh

MOUNT_POINT="/mnt/drbd0"

DRBD_MOUNTED=$(/bin/mount | awk -v mnt=$MOUNT_POINT '{if ( $3 == mnt )
print 1}')
if [ "${DRBD_MOUNTED}" == 1 ]; then
        echo "yes"
else
        echo "no"
fi

Brandon Poyner
Network Engineer III
CCAC - College Office
412-237-3086



More information about the drbd-user mailing list