Revision aa75500a

b/.gitignore
66 66
/doc/examples/ganeti.cron
67 67
/doc/examples/ganeti.initd
68 68
/doc/examples/ganeti-kvm-poweroff.initd
69
/doc/examples/ganeti-master-role.ocf
69 70
/doc/examples/gnt-config-backup
70 71
/doc/examples/hooks/ipsec
71 72

  
b/Makefile.am
208 208
	doc/examples/ganeti-kvm-poweroff.initd \
209 209
	doc/examples/ganeti.cron \
210 210
	doc/examples/ganeti.initd \
211
	doc/examples/ganeti-master-role.ocf \
211 212
	doc/examples/gnt-config-backup \
212 213
	doc/examples/hooks/ipsec
213 214

  
b/devel/upload
99 99
install -D --mode=0755 doc/examples/ganeti.initd \
100 100
  "$TXD/$SYSCONFDIR/init.d/ganeti"
101 101

  
102
[ -f doc/examples/ganeti-master-role.ocf ] && \
103
install -D --mode=0755 doc/examples/ganeti-master-role.ocf \
104
  "$TXD/$LIBDIR/ocf/resource.d/ganeti/ganeti-master-role"
105

  
102 106
[ -f doc/examples/ganeti.default-debug -a -z "$NO_DEBUG" ] && \
103 107
install -D --mode=0644 doc/examples/ganeti.default-debug \
104 108
  "$TXD/$SYSCONFDIR/default/ganeti"
b/doc/examples/ganeti-master-role.ocf.in
1
#!/bin/bash
2
# ganeti master role OCF resource
3
# See http://linux-ha.org/wiki/OCF_Resource_Agents
4

  
5
set -e -u
6

  
7
@SHELL_ENV_INIT@
8

  
9
PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin
10

  
11
SCRIPTNAME="@LIBDIR@/ocf/resource.d/ganeti/ganeti-master-role"
12

  
13
# Master candidates list file
14
MCFILE="$DATA_DIR/ssconf_master_candidates"
15

  
16
# We'll need the hostname in a few places, so we'll get it once, now.
17
MYHOSTNAME=$(hostname --fqdn)
18

  
19
is_master() {
20
  local -r master=$(gnt-cluster getmaster)
21
  [[ "$MYHOSTNAME" == "$master" ]]
22
}
23

  
24
is_candidate() {
25
  grep -Fx $MYHOSTNAME $MCFILE
26
}
27

  
28
start_action() {
29
  if is_master; then
30
    exit 0
31
  elif is_candidate; then
32
    gnt-cluster master-failover || exit 1 # OCF_ERR_GENERIC
33
  else
34
    exit 5 # OCF_ERR_INSTALLED (vital component missing)
35
  fi
36
}
37

  
38
stop_action() {
39
  # We can't really "stop" being a master.
40
  # TODO: investigate whether a fake approach will do.
41
  exit 1 # OCF_ERR_GENERIC
42
}
43

  
44
recover_action() {
45
  if is_master; then
46
    gnt-cluster redist-conf || exit 1 # OCF_ERR_GENERIC
47
  elif is_candidate; then
48
    gnt-cluster master-failover || exit 1 # OCF_ERR_GENERIC
49
  else
50
    exit 5 # OCF_ERR_INSTALLED (vital component missing)
51
  fi
52
}
53

  
54
monitor_action() {
55
  # monitor should exit:
56
  #    7 if the resource is not running
57
  #    1 if it failed
58
  #    0 if it's running
59
  if is_master; then
60
    exit 0
61
  elif is_candidate; then
62
    exit 7 # OCF_NOT_RUNNING
63
  else
64
    exit 5 # OCF_ERR_INSTALLED (vital component missing)
65
  fi
66
}
67

  
68
return_meta() {
69
cat <<END
70
<?xml version="1.0"?>
71
<!DOCTYPE resource-agent SYSTEM "ra-api-1.dtd">
72
<resource-agent name="ganeti-master-role" version="0.1">
73
<version>0.1</version>
74
<longdesc lang="en">
75
OCF script to manage the ganeti master role in a cluster.
76

  
77
Can be used to failover the ganeti master between master candidate nodes.
78
</longdesc>
79
<shortdesc lang="en">Manages the ganeti cluster master</shortdesc>
80

  
81
<parameters/>
82
<actions>
83
<action name="start" timeout="300s" />
84
<action name="stop" timeout="50s" />
85
<action name="monitor" depth="0" timeout="10s" interval="30s" />
86
<action name="meta-data" timeout="5s" />
87
<action name="recover" timeout="20s" />
88
<action name="reload" timeout="5s" />
89
</actions>
90
</resource-agent>
91
END
92
exit 0
93
}
94

  
95
case "$1" in
96
  # Mandatory OCF commands
97
  start)
98
    start_action
99
    ;;
100
  stop)
101
    stop_action
102
    ;;
103
  monitor)
104
    monitor_action
105
    ;;
106
  meta-data)
107
    return_meta
108
    ;;
109
  # Optional OCF commands
110
  recover)
111
    recover_action
112
    ;;
113
  reload)
114
    # The ganeti master role has no "configuration" that is reloadable on
115
    # the pacemaker side. We declare the operation anyway to make sure
116
    # pacemaker doesn't decide to stop and start the service needlessly.
117
    exit 0
118
    ;;
119
  promote|demote|migrate_to|migrate_from|validate-all)
120
    # Not implemented (nor declared by meta-data)
121
    exit 3 # OCF_ERR_UNIMPLEMENTED
122
    ;;
123
  *)
124
    log_success_msg "Usage: $SCRIPTNAME {start|stop|monitor|meta-data|recover|reload}"
125
    exit 1
126
    ;;
127
esac
128

  
129
exit 0

Also available in: Unified diff