puppet-openstack_extras/templates/ocf_handler.erb
Bogdan Dobrelya d5b4999b8c Add pacemaker provider for HA services
* Add pacemaker service provider and unit tests
* Add generic OCF handler script for RA scripts
* Add service class and docs for pacemaker primitives creation with
  default OCF type = pacemaker
* Add specs for pacemaker service define

Implements step 1 of blueprint pacemaker-provider-for-openstack

Change-Id: I5d98d8f9494bb7df4466022b3d49ac6392deb1a5
Co-Author: Dmitry Ilyin (idv1985 <dilyin@mirantis.com>)
Signed-off-by: Bogdan Dobrelya <bdobrelia@mirantis.com>
2014-12-23 10:08:49 +01:00

119 lines
2.0 KiB
Plaintext

#!/bin/sh
export PATH='/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin'
export OCF_ROOT='<%= @ocf_root_path %>'
export OCF_RA_VERSION_MAJOR='1'
export OCF_RA_VERSION_MINOR='0'
export OCF_RESOURCE_INSTANCE='<%= @primitive_name %>'
# OCF Parameters
<% if @parameters.is_a? Hash -%>
<% @parameters.each do |k,v| -%>
<% v = v.to_s -%>
<% v = v + "'" unless v.end_with? "'" -%>
<% v = "'" + v unless v.start_with? "'" -%>
<%= "export OCF_RESKEY_#{k}=#{v}" %>
<% end -%>
<% end -%>
help() {
cat<<EOF
OCF wrapper for <%= @service_name %> Pacemaker primitive
Usage: <%= @ocf_handler_name %> [-dh] (action)
Options:
-d - Use set -x to debug the shell script
-h - Show this help
Main actions:
* start
* stop
* monitor
* meta-data
* validate-all
Multistate:
* promote
* demote
* notify
Migration:
* migrate_to
* migrate_from
Optional and unused:
* usage
* help
* status
* reload
* restart
* recover
EOF
}
red() {
echo -e "\033[31m${1}\033[0m"
}
green() {
echo -e "\033[32m${1}\033[0m"
}
blue() {
echo -e "\033[34m${1}\033[0m"
}
ec2error() {
case "${1}" in
0) green 'Success' ;;
1) red 'Error: Generic' ;;
2) red 'Error: Arguments' ;;
3) red 'Error: Unimplemented' ;;
4) red 'Error: Permissions' ;;
5) red 'Error: Installation' ;;
6) red 'Error: Configuration' ;;
7) blue 'Not Running' ;;
8) green 'Master Running' ;;
9) red 'Master Failed' ;;
*) red "Unknown" ;;
esac
}
DEBUG='0'
while getopts ':dh' opt; do
case $opt in
d)
DEBUG='1'
;;
h)
help
exit 0
;;
\?)
echo "Invalid option: -${OPTARG}" >&2
help
exit 1
;;
esac
done
shift "$((OPTIND - 1))"
ACTION="${1}"
# set default action to monitor
if [ "${ACTION}" = '' ]; then
ACTION='monitor'
fi
if [ "${DEBUG}" = '1' ]; then
bash -x <%= @ocf_script_path %> "${ACTION}"
else
<%= @ocf_script_path %> "${ACTION}"
fi
ec="${?}"
message="$(ec2error ${ec})"
echo "Exit status: ${message} (${ec})"
exit "${ec}"