Statistics
| Branch: | Tag: | Revision:

root / doc / examples / ganeti-master-role.ocf.in @ aa75500a

History | View | Annotate | Download (2.9 kB)

1 aa75500a Guido Trotter
#!/bin/bash
2 aa75500a Guido Trotter
# ganeti master role OCF resource
3 aa75500a Guido Trotter
# See http://linux-ha.org/wiki/OCF_Resource_Agents
4 aa75500a Guido Trotter
5 aa75500a Guido Trotter
set -e -u
6 aa75500a Guido Trotter
7 aa75500a Guido Trotter
@SHELL_ENV_INIT@
8 aa75500a Guido Trotter
9 aa75500a Guido Trotter
PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin
10 aa75500a Guido Trotter
11 aa75500a Guido Trotter
SCRIPTNAME="@LIBDIR@/ocf/resource.d/ganeti/ganeti-master-role"
12 aa75500a Guido Trotter
13 aa75500a Guido Trotter
# Master candidates list file
14 aa75500a Guido Trotter
MCFILE="$DATA_DIR/ssconf_master_candidates"
15 aa75500a Guido Trotter
16 aa75500a Guido Trotter
# We'll need the hostname in a few places, so we'll get it once, now.
17 aa75500a Guido Trotter
MYHOSTNAME=$(hostname --fqdn)
18 aa75500a Guido Trotter
19 aa75500a Guido Trotter
is_master() {
20 aa75500a Guido Trotter
  local -r master=$(gnt-cluster getmaster)
21 aa75500a Guido Trotter
  [[ "$MYHOSTNAME" == "$master" ]]
22 aa75500a Guido Trotter
}
23 aa75500a Guido Trotter
24 aa75500a Guido Trotter
is_candidate() {
25 aa75500a Guido Trotter
  grep -Fx $MYHOSTNAME $MCFILE
26 aa75500a Guido Trotter
}
27 aa75500a Guido Trotter
28 aa75500a Guido Trotter
start_action() {
29 aa75500a Guido Trotter
  if is_master; then
30 aa75500a Guido Trotter
    exit 0
31 aa75500a Guido Trotter
  elif is_candidate; then
32 aa75500a Guido Trotter
    gnt-cluster master-failover || exit 1 # OCF_ERR_GENERIC
33 aa75500a Guido Trotter
  else
34 aa75500a Guido Trotter
    exit 5 # OCF_ERR_INSTALLED (vital component missing)
35 aa75500a Guido Trotter
  fi
36 aa75500a Guido Trotter
}
37 aa75500a Guido Trotter
38 aa75500a Guido Trotter
stop_action() {
39 aa75500a Guido Trotter
  # We can't really "stop" being a master.
40 aa75500a Guido Trotter
  # TODO: investigate whether a fake approach will do.
41 aa75500a Guido Trotter
  exit 1 # OCF_ERR_GENERIC
42 aa75500a Guido Trotter
}
43 aa75500a Guido Trotter
44 aa75500a Guido Trotter
recover_action() {
45 aa75500a Guido Trotter
  if is_master; then
46 aa75500a Guido Trotter
    gnt-cluster redist-conf || exit 1 # OCF_ERR_GENERIC
47 aa75500a Guido Trotter
  elif is_candidate; then
48 aa75500a Guido Trotter
    gnt-cluster master-failover || exit 1 # OCF_ERR_GENERIC
49 aa75500a Guido Trotter
  else
50 aa75500a Guido Trotter
    exit 5 # OCF_ERR_INSTALLED (vital component missing)
51 aa75500a Guido Trotter
  fi
52 aa75500a Guido Trotter
}
53 aa75500a Guido Trotter
54 aa75500a Guido Trotter
monitor_action() {
55 aa75500a Guido Trotter
  # monitor should exit:
56 aa75500a Guido Trotter
  #    7 if the resource is not running
57 aa75500a Guido Trotter
  #    1 if it failed
58 aa75500a Guido Trotter
  #    0 if it's running
59 aa75500a Guido Trotter
  if is_master; then
60 aa75500a Guido Trotter
    exit 0
61 aa75500a Guido Trotter
  elif is_candidate; then
62 aa75500a Guido Trotter
    exit 7 # OCF_NOT_RUNNING
63 aa75500a Guido Trotter
  else
64 aa75500a Guido Trotter
    exit 5 # OCF_ERR_INSTALLED (vital component missing)
65 aa75500a Guido Trotter
  fi
66 aa75500a Guido Trotter
}
67 aa75500a Guido Trotter
68 aa75500a Guido Trotter
return_meta() {
69 aa75500a Guido Trotter
cat <<END
70 aa75500a Guido Trotter
<?xml version="1.0"?>
71 aa75500a Guido Trotter
<!DOCTYPE resource-agent SYSTEM "ra-api-1.dtd">
72 aa75500a Guido Trotter
<resource-agent name="ganeti-master-role" version="0.1">
73 aa75500a Guido Trotter
<version>0.1</version>
74 aa75500a Guido Trotter
<longdesc lang="en">
75 aa75500a Guido Trotter
OCF script to manage the ganeti master role in a cluster.
76 aa75500a Guido Trotter
77 aa75500a Guido Trotter
Can be used to failover the ganeti master between master candidate nodes.
78 aa75500a Guido Trotter
</longdesc>
79 aa75500a Guido Trotter
<shortdesc lang="en">Manages the ganeti cluster master</shortdesc>
80 aa75500a Guido Trotter
81 aa75500a Guido Trotter
<parameters/>
82 aa75500a Guido Trotter
<actions>
83 aa75500a Guido Trotter
<action name="start" timeout="300s" />
84 aa75500a Guido Trotter
<action name="stop" timeout="50s" />
85 aa75500a Guido Trotter
<action name="monitor" depth="0" timeout="10s" interval="30s" />
86 aa75500a Guido Trotter
<action name="meta-data" timeout="5s" />
87 aa75500a Guido Trotter
<action name="recover" timeout="20s" />
88 aa75500a Guido Trotter
<action name="reload" timeout="5s" />
89 aa75500a Guido Trotter
</actions>
90 aa75500a Guido Trotter
</resource-agent>
91 aa75500a Guido Trotter
END
92 aa75500a Guido Trotter
exit 0
93 aa75500a Guido Trotter
}
94 aa75500a Guido Trotter
95 aa75500a Guido Trotter
case "$1" in
96 aa75500a Guido Trotter
  # Mandatory OCF commands
97 aa75500a Guido Trotter
  start)
98 aa75500a Guido Trotter
    start_action
99 aa75500a Guido Trotter
    ;;
100 aa75500a Guido Trotter
  stop)
101 aa75500a Guido Trotter
    stop_action
102 aa75500a Guido Trotter
    ;;
103 aa75500a Guido Trotter
  monitor)
104 aa75500a Guido Trotter
    monitor_action
105 aa75500a Guido Trotter
    ;;
106 aa75500a Guido Trotter
  meta-data)
107 aa75500a Guido Trotter
    return_meta
108 aa75500a Guido Trotter
    ;;
109 aa75500a Guido Trotter
  # Optional OCF commands
110 aa75500a Guido Trotter
  recover)
111 aa75500a Guido Trotter
    recover_action
112 aa75500a Guido Trotter
    ;;
113 aa75500a Guido Trotter
  reload)
114 aa75500a Guido Trotter
    # The ganeti master role has no "configuration" that is reloadable on
115 aa75500a Guido Trotter
    # the pacemaker side. We declare the operation anyway to make sure
116 aa75500a Guido Trotter
    # pacemaker doesn't decide to stop and start the service needlessly.
117 aa75500a Guido Trotter
    exit 0
118 aa75500a Guido Trotter
    ;;
119 aa75500a Guido Trotter
  promote|demote|migrate_to|migrate_from|validate-all)
120 aa75500a Guido Trotter
    # Not implemented (nor declared by meta-data)
121 aa75500a Guido Trotter
    exit 3 # OCF_ERR_UNIMPLEMENTED
122 aa75500a Guido Trotter
    ;;
123 aa75500a Guido Trotter
  *)
124 aa75500a Guido Trotter
    log_success_msg "Usage: $SCRIPTNAME {start|stop|monitor|meta-data|recover|reload}"
125 aa75500a Guido Trotter
    exit 1
126 aa75500a Guido Trotter
    ;;
127 aa75500a Guido Trotter
esac
128 aa75500a Guido Trotter
129 aa75500a Guido Trotter
exit 0