2 # ganeti node role OCF resource
3 # See http://linux-ha.org/wiki/OCF_Resource_Agents
9 PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin
11 SCRIPTNAME="@LIBDIR@/ocf/resource.d/ganeti/ganeti-node-role"
13 # If this file exists don't act on notifications, thus allowing them to happen
14 # during the service configuration.
15 NORUNFILE="$DATA_DIR/ha_node_role_config"
17 # Where to grep for tags
18 TAGSFILE="$DATA_DIR/ssconf_cluster_tags"
20 # If this tag is set we won't try to powercycle nodes
21 POWERCYCLETAG="ocf:node-offline:use-powercycle"
23 # If this tag is set will use IPMI to power off an offline node
24 POWEROFFTAG="ocf:node-offline:use-poweroff"
26 # We'll need the hostname in a few places, so we'll get it once, now.
27 MYHOSTNAME=$(hostname --fqdn)
30 local -r master=$(gnt-cluster getmaster)
31 [[ "$MYHOSTNAME" == "$master" ]]
35 # If we're alive we consider ourselves a node, without starting anything.
36 # TODO: improve on this
41 # We can't "really" stop the service locally.
42 # TODO: investigate whether a "fake" stop will work.
47 # Nothing to recover, as long as we're alive.
52 # If we're alive we consider ourselves a working node.
53 # TODO: improve on this
59 grep -Fx $POWERCYCLETAG $TAGSFILE && gnt-node powercycle $node
60 grep -Fx $POWEROFFTAG $TAGSFILE && gnt-node power off $node
61 # TODO: do better than just --auto-promote
62 # (or make sure auto-promote gets better in Ganeti)
63 gnt-node modify -O yes --auto-promote $node
68 # TODO: do better than just --auto-promote
69 # (or make sure auto-promote gets better in Ganeti)
70 gnt-node modify -D yes --auto-promote $node || return 1
75 [[ -f $NORUNFILE ]] && exit 0
76 # TODO: also implement the "start" operation for readding a node
77 [[ $OCF_RESKEY_CRM_meta_notify_operation == "stop" ]] || exit 0
78 [[ $OCF_RESKEY_CRM_meta_notify_type == "post" ]] || exit 0
79 local -r target=$OCF_RESKEY_CRM_meta_notify_stop_uname
80 local -r node=$(gnt-node list --no-headers -o name $target)
81 # TODO: use drain_node when we can
89 <!DOCTYPE resource-agent SYSTEM "ra-api-1.dtd">
90 <resource-agent name="ganeti-node-role" version="0.1">
91 <version>0.1</version>
93 OCF script to manage the ganeti node role in a cluster.
95 Can be used to online and offline nodes. Should be cloned on all nodes of the
96 cluster, with notification enabled.
99 <shortdesc lang="en">Manages the ganeti cluster nodes</shortdesc>
103 <action name="start" timeout="10s" />
104 <action name="stop" timeout="10s" />
105 <action name="monitor" depth="0" timeout="10s" interval="30s" />
106 <action name="meta-data" timeout="5s" />
107 <action name="recover" timeout="20s" />
108 <action name="reload" timeout="5s" />
109 <action name="notify" timeout="1000s" />
117 # Mandatory OCF commands
130 # Optional OCF commands
135 # The ganeti node role has no "configuration" that is reloadable on
136 # the pacemaker side. We declare the operation anyway to make sure
137 # pacemaker doesn't decide to stop and start the service needlessly.
141 # Notification of a change to the ganeti node role
145 promote|demote|migrate_to|migrate_from|validate-all)
146 # Not implemented (nor declared by meta-data)
147 exit 3 # OCF_ERR_UNIMPLEMENTED
150 log_success_msg "Usage: $SCRIPTNAME {start|stop|monitor|meta-data|recover|reload}"