#!/bin/sh # # # DnsUpdater OCF RA. Does nothing but wait a few seconds, can be # configured to fail occassionally. # # Copyright (c) 2004 SUSE LINUX AG, Lars Marowsky-Brée # All Rights Reserved. # # This program is free software; you can redistribute it and/or modify # it under the terms of version 2 of the GNU General Public License as # published by the Free Software Foundation. # # This program is distributed in the hope that it would be useful, but # WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. # # Further, this software is distributed without any warranty that it is # free of the rightful claim of any third person regarding infringement # or the like. Any license provided herein, whether implied or # otherwise, applies only to this software file. Patent licenses, if # any, provided herein do not apply to combinations of this program with # other software, or any other product whatsoever. # # You should have received a copy of the GNU General Public License # along with this program; if not, write the Free Software Foundation, # Inc., 59 Temple Place - Suite 330, Boston MA 02111-1307, USA. # ####################################################################### # Initialization: : ${OCF_FUNCTIONS_DIR=${OCF_ROOT}/lib/heartbeat} . ${OCF_FUNCTIONS_DIR}/ocf-shellfuncs : ${OCF_FUEL_FUNCTIONS_DIR=${OCF_ROOT}/resource.d/fuel} . ${OCF_FUEL_FUNCTIONS_DIR}/ocf-fuel-funcs ####################################################################### # Fill in some defaults if no values are specified OCF_RESKEY_binary_default="openstack-dns-updater.py" #OCF_RESKEY_config_default="/etc/aodh/aodh.conf" #OCF_RESKEY_user_default="aodh" OCF_RESKEY_pid_default="${HA_RSCTMP}/${__SCRIPT_NAME}/${__SCRIPT_NAME}.pid" : ${HA_LOGTAG="ocf-dns-updater"} : ${HA_LOGFACILITY="daemon"} : ${OCF_RESKEY_binary=${OCF_RESKEY_binary_default}} #: ${OCF_RESKEY_config=${OCF_RESKEY_config_default}} #: ${OCF_RESKEY_user=${OCF_RESKEY_user_default}} : ${OCF_RESKEY_pid=${OCF_RESKEY_pid_default}} ####################################################################### usage() { cat < 1.0 sample dnsupdater resource Example stateless resource agent The pid file to use for this OpenStack Aodh Evaluator Service (aodh-evaluator) instance OpenStack Aodh Evaluator Service (aodh-evaluator) pid file END } ####################################################################### dnsupdater_validate() { local rc return ${OCF_SUCCESS} } dnsupdater_status() { local pid local rc # check and make PID file dir local PID_DIR="$( dirname ${OCF_RESKEY_pid} )" if [ ! -d "${PID_DIR}" ] ; then ocf_log debug "Create pid file dir: ${PID_DIR}" mkdir -p "${PID_DIR}" chmod 755 "${PID_DIR}" fi if [ ! -f $OCF_RESKEY_pid ]; then ocf_log info "DnsUpdater is not running" return $OCF_NOT_RUNNING else pid=`cat $OCF_RESKEY_pid` fi if [ -n "${pid}" ]; then ocf_run -warn kill -s 0 $pid rc=$? else ocf_log err "PID file ${OCF_RESKEY_pid} is empty!" return $OCF_ERR_GENERIC fi if [ $rc -eq 0 ]; then return $OCF_SUCCESS else ocf_log info "Old PID file found, but DnsUpdater not running" return $OCF_NOT_RUNNING fi } dnsupdater_monitor() { local rc local pid dnsupdater_status rc=$? # If status returned anything but success, return that immediately if [ $rc -ne $OCF_SUCCESS ]; then return $rc fi ocf_log debug "OpenStack DnsUpdater monitor succeeded" return $OCF_SUCCESS } dnsupdater_start() { dnsupdater_status rc=$? if [ $rc -eq $OCF_SUCCESS ]; then ocf_log info "OpenStack DnsUpdater is already running" return $OCF_SUCCESS fi /usr/bin/python /usr/lib/python2.7/dist-packages/os_dns_updater/openstack-dns-updater.py >> /dev/null 2>&1 & echo $! > $OCF_RESKEY_pid ocf_log debug "Create pid file: ${OCF_RESKEY_pid} with content $(cat ${OCF_RESKEY_pid})" # Spin waiting for the server to come up. while true; do dnsupdater_monitor rc=$? [ $rc -eq $OCF_SUCCESS ] && break if [ $rc -ne $OCF_NOT_RUNNING ]; then ocf_log err "OpenStack DnsUpdater start failed" exit $OCF_ERR_GENERIC fi sleep 1 done ocf_log info "OpenStack DnsUpdater started" return $OCF_SUCCESS } dnsupdater_stop() { local rc local shutdown_timeout=15 if [ -n "$OCF_RESKEY_CRM_meta_timeout" ]; then shutdown_timeout=$(( ($OCF_RESKEY_CRM_meta_timeout/1000) )) fi dnsupdater_status rc="${?}" if [ "${rc}" -eq "${OCF_NOT_RUNNING}" ]; then ocf_log info "OpenStack DnsUpdater (${OCF_RESKEY_binary}) already stopped" return "${OCF_SUCCESS}" fi proc_stop "${OCF_RESKEY_pid}" "${OCF_RESKEY_binary}" $shutdown_timeout return "${?}" } ####################################################################### case "$1" in meta-data) meta_data exit $OCF_SUCCESS;; usage|help) usage exit $OCF_SUCCESS;; esac # Anything except meta-data and help must pass validation dnsupdater_validate || exit $? # What kind of method was invoked? case "$1" in start) dnsupdater_start;; stop) dnsupdater_stop;; status) dnsupdater_status;; monitor) dnsupdater_monitor;; validate-all) ;; *) usage exit $OCF_ERR_UNIMPLEMENTED;; esac