Statistics
| Branch: | Tag: | Revision:

root / tools / master-ip-setup @ 1a732a74

History | View | Annotate | Download (2.2 kB)

1 d9eefcfa Andrea Spadaccini
#!/bin/bash
2 d9eefcfa Andrea Spadaccini
#
3 d9eefcfa Andrea Spadaccini
4 d9eefcfa Andrea Spadaccini
# Copyright (C) 2011 Google Inc.
5 d9eefcfa Andrea Spadaccini
#
6 d9eefcfa Andrea Spadaccini
# This program is free software; you can redistribute it and/or modify
7 d9eefcfa Andrea Spadaccini
# it under the terms of the GNU General Public License as published by
8 d9eefcfa Andrea Spadaccini
# the Free Software Foundation; either version 2 of the License, or
9 d9eefcfa Andrea Spadaccini
# (at your option) any later version.
10 d9eefcfa Andrea Spadaccini
#
11 d9eefcfa Andrea Spadaccini
# This program is distributed in the hope that it will be useful, but
12 d9eefcfa Andrea Spadaccini
# WITHOUT ANY WARRANTY; without even the implied warranty of
13 d9eefcfa Andrea Spadaccini
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 d9eefcfa Andrea Spadaccini
# General Public License for more details.
15 d9eefcfa Andrea Spadaccini
#
16 d9eefcfa Andrea Spadaccini
# You should have received a copy of the GNU General Public License
17 d9eefcfa Andrea Spadaccini
# along with this program; if not, write to the Free Software
18 d9eefcfa Andrea Spadaccini
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19 d9eefcfa Andrea Spadaccini
# 02110-1301, USA.
20 d9eefcfa Andrea Spadaccini
21 d9eefcfa Andrea Spadaccini
set -e -u
22 d9eefcfa Andrea Spadaccini
23 d9eefcfa Andrea Spadaccini
USAGE_MSG="Usage: $0 {start|stop}"
24 d9eefcfa Andrea Spadaccini
PATH=$PATH:/sbin:/usr/sbin:/usr/local/sbin
25 d9eefcfa Andrea Spadaccini
26 d9eefcfa Andrea Spadaccini
# Start the master IP
27 d9eefcfa Andrea Spadaccini
start() {
28 d9eefcfa Andrea Spadaccini
  case $CLUSTER_IP_VERSION in
29 d9eefcfa Andrea Spadaccini
    4)
30 d9eefcfa Andrea Spadaccini
      ARP_COMMAND="arping -q -U -c 3 -I $MASTER_NETDEV -s $MASTER_IP $MASTER_IP"
31 d9eefcfa Andrea Spadaccini
      ;;
32 d9eefcfa Andrea Spadaccini
    6)
33 d9eefcfa Andrea Spadaccini
      ARP_COMMAND="ndisc6 -q r 3 $MASTER_IP $MASTER_NETDEV"
34 d9eefcfa Andrea Spadaccini
      ;;
35 d9eefcfa Andrea Spadaccini
    *)
36 d9eefcfa Andrea Spadaccini
      echo "Invalid cluster IP version specified: $CLUSTER_IP_VERSION" >&2
37 d9eefcfa Andrea Spadaccini
      exit 1
38 d9eefcfa Andrea Spadaccini
      ;;
39 d9eefcfa Andrea Spadaccini
  esac
40 d9eefcfa Andrea Spadaccini
41 d9eefcfa Andrea Spadaccini
  # Check if the master IP address is already configured on this machine
42 d9eefcfa Andrea Spadaccini
  if fping -S 127.0.0.1 $MASTER_IP >/dev/null 2>&1; then
43 d9eefcfa Andrea Spadaccini
    echo "Master IP address already configured on this machine. Doing nothing."
44 d9eefcfa Andrea Spadaccini
    exit 0
45 d9eefcfa Andrea Spadaccini
  fi
46 d9eefcfa Andrea Spadaccini
47 d9eefcfa Andrea Spadaccini
  # Check if the master IP address is already configured on another machine
48 d9eefcfa Andrea Spadaccini
  if fping $MASTER_IP >/dev/null 2>&1; then
49 d9eefcfa Andrea Spadaccini
    echo "Error: master IP address configured on another machine." >&2
50 d9eefcfa Andrea Spadaccini
    exit 1
51 d9eefcfa Andrea Spadaccini
  fi
52 d9eefcfa Andrea Spadaccini
53 d9eefcfa Andrea Spadaccini
  if ! ip addr add $MASTER_IP/$MASTER_NETMASK \
54 d9eefcfa Andrea Spadaccini
     dev $MASTER_NETDEV label $MASTER_NETDEV:0; then
55 d9eefcfa Andrea Spadaccini
    echo "Error during the activation of the master IP address" >&2
56 d9eefcfa Andrea Spadaccini
    exit 1
57 d9eefcfa Andrea Spadaccini
  fi
58 d9eefcfa Andrea Spadaccini
59 d9eefcfa Andrea Spadaccini
  # Send gratuituous ARP to update neighbours' ARP cache
60 d9eefcfa Andrea Spadaccini
  $ARP_COMMAND || :
61 d9eefcfa Andrea Spadaccini
}
62 d9eefcfa Andrea Spadaccini
63 d9eefcfa Andrea Spadaccini
# Stop the master IP
64 d9eefcfa Andrea Spadaccini
stop() {
65 d9eefcfa Andrea Spadaccini
  if ! ip addr del $MASTER_IP/$MASTER_NETMASK dev $MASTER_NETDEV; then
66 d9eefcfa Andrea Spadaccini
    echo "Error during the deactivation of the master IP address" >&2
67 d9eefcfa Andrea Spadaccini
    exit 1
68 d9eefcfa Andrea Spadaccini
  fi
69 d9eefcfa Andrea Spadaccini
}
70 d9eefcfa Andrea Spadaccini
71 d9eefcfa Andrea Spadaccini
if (( $# < 1 )); then
72 d9eefcfa Andrea Spadaccini
  echo $USAGE_MSG >&2
73 d9eefcfa Andrea Spadaccini
  exit 1
74 d9eefcfa Andrea Spadaccini
fi
75 d9eefcfa Andrea Spadaccini
76 d9eefcfa Andrea Spadaccini
case "$1" in
77 d9eefcfa Andrea Spadaccini
  start)
78 d9eefcfa Andrea Spadaccini
    start
79 d9eefcfa Andrea Spadaccini
    ;;
80 d9eefcfa Andrea Spadaccini
  stop)
81 d9eefcfa Andrea Spadaccini
    stop
82 d9eefcfa Andrea Spadaccini
    ;;
83 d9eefcfa Andrea Spadaccini
  *)
84 d9eefcfa Andrea Spadaccini
    echo $USAGE_MSG >&2
85 d9eefcfa Andrea Spadaccini
    exit 1
86 d9eefcfa Andrea Spadaccini
    ;;
87 d9eefcfa Andrea Spadaccini
esac
88 d9eefcfa Andrea Spadaccini
89 d9eefcfa Andrea Spadaccini
exit 0