#!/bin/sh # # eucaclc - Eucalyptus Cloud Controll Resource Agent # # Copyright (C) 2011 Canonical Ltd. # # Authors: Andres Rodriguez # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, version 3 of the License. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see . # Initialization: : ${OCF_FUNCTIONS_DIR=${OCF_ROOT}/resource.d/heartbeat} . ${OCF_FUNCTIONS_DIR}/.ocf-shellfuncs # Defaults OCF_RESKEY_binary_default="/usr/sbin/eucalyptus-cloud" OCF_RESKEY_user_default="eucalyptus" OCF_RESKEY_group_default="eucalyptus" OCF_RESKEY_homedir_default="/" OCF_RESKEY_loglevel_default="DEBUG" OCF_RESKEY_pid_default="/var/run/eucalyptus/eucalyptus.pid" OCF_RESKEY_walrus_default="false" OCF_RESKEY_storage_default="false" OCF_RESKEY_jvmargs_default="mx512m" : ${OCF_RESKEY_binary=${OCF_RESKEY_binary_default}} : ${OCF_RESKEY_user=${OCF_RESKEY_user_default}} : ${OCF_RESKEY_group=${OCF_RESKEY_group_defaultt}} : ${OCF_RESKEY_homedir=${OCF_RESKEY_homedir_defaultt}} : ${OCF_RESKEY_loglevel=${OCF_RESKEY_loglevel_default}} : ${OCF_RESKEY_pid=${OCF_RESKEY_pid_default}} : ${OCF_RESKEY_walrus=${OCF_RESKEY_walrus_default}} : ${OCF_RESKEY_storage=${OCF_RESKEY_storage_default}} : ${OCF_RESKEY_jvmargs=${OCF_RESKEY_jvmargs_default}} # Obtaining additional args WALRUS="" if ! ocf_is_true $OCF_RESKEY_walrus; then WALRUS="--disable-walrus" fi STORAGE="" if ! ocf_is_true $OCF_RESKEY_storage; then STORAGE="--disable-storage" fi # Obtain IP of CLC. Used by euca_clc_monitor default_route=$(ip route show to exact 0/0) default_interface=$(echo $default_route | sed -e 's/^.*dev \([^ ]*\).*$/\1/') addr_withprefix=$(ip addr show label $default_interface scope global | awk '$1 == "inet" { print $2 }') IPADDR=${addr_withprefix%%/*} usage() { cat < 1.0 Resource script for Eucalyptus Cloud Controller. It manages an Eucalyptus Cloud Controller instance as a HA resource. Manages an Eucalyptus Cloud Controller Location of the Cloud Controller binary CLC binary User running the Cloud Controller daemon CLC user User group running the Cloud Controller daemon CLC group Eucalyptus Home Directory Eucalyptus home Eucalyptus Cloud Controller PID file CLC pid file Enable Eucalyptus Cloud Walrus Controller locally Enable Walrus Controller locally Enable Eucalyptus Storage Storage Controller locally Enable Storage Controller locally Eucalyptus Cloud Controller JVM arguments CLC JVM args END } euca_cloud_status() { if [ ! -e $OCF_RESKEY_pid ]; then ocf_log debug "Eucalyptus Cloud Controller is not running" return $OCF_NOT_RUNNING; fi pid=`cat $OCF_RESKEY_pid`; if [ -d /proc -a -d /proc/1 ]; then [ "u$pid" != "u" -a -d /proc/$pid ] else kill -0 $pid >/dev/null 2>&1 fi if [ $? -eq 0 ]; then return $OCF_SUCCESS; else ocf_log debug "Eucalyptus Cloud Controller not running. Removing old PID file" rm -f $OCF_RESKEY_pid return $OCF_NOT_RUNNING; fi } euca_cloud_monitor() { euca_cloud_status rc=$? if [ $OCF_CHECK_LEVEL = 0 -o $rc != 0 ]; then return $rc fi if wget -q -T10 -t1 -O- --no-check-certificate https://$IPADDR:8443/register | grep CloudVersion > /dev/null; then ocf_log info "Eucalyptus Cloud Monitor succeded"; return $OCF_SUCCESS else ocf_log err "Eucalyptus Cloud Monitor failed"; return $OCF_ERR_GENERIC fi } euca_cloud_start() { euca_cloud_status if [ $? = $OCF_SUCCESS ]; then ocf_log info "Eucalyptus Cloud is already running" return $OCF_SUCCESS fi # Ensure iptables are loaded iptables -t nat -L -n >/dev/null iptables -L -n > /dev/null # Create necessary file/dirs pid_dir=`dirname $OCF_RESKEY_pid` if ! su -s /bin/sh - $OCF_RESKEY_user -c "test -w $pid_dir"; then ocf_log err "Directory $pid_dir for pidfile $OCF_RESKEY_pid is not writable by $OCF_RESKEY_user" chown $OCF_RESKEY_user:$OCF_RESKEY_group $pid_dir #return $OCF_ERR_PERM; fi if [ ! -d $pid_dir ] ; then ocf_log info "Creating PID dir: $pid_dir" mkdir -p $pid_dir chown $OCF_RESKEY_user:$OCF_RESKEY_group $pid_dir fi net_dir=`dirname $OCF_RESKEY_pid`/net if [ ! -d $net_dir ]; then ocf_log info "Creating PID dir: $net_dir" mkdir -p $net_dir chown $OCF_RESKEY_user:$OCF_RESKEY_group $net_dir fi ${OCF_RESKEY_binary} --home=$OCF_RESKEY_homedir --user=$OCF_RESKEY_user --pidfile=$OCF_RESKEY_pid --log-level=$OCF_RESKEY_loglevel \ --log-appender="console-log" --jvm-args=$OCF_RESKEY_jvmargs $WALRUS $STORAGE --remote-dns --fork #While loop waiting for cloud controller to come up start_wait=1 while [ $start_wait = 1 ]; do euca_cloud_status rc=$? if [ $rc = $OCF_SUCCESS ]; then start_wait=0 elif [ $rc != $OCF_NOT_RUNNING ]; then ocf_log info "Eucalyptus Cloud Controller start failed: $rc" return $rc fi sleep 2 done ocf_log info "Eucalyptus Cloud Controller started" return $OCF_SUCCESS } euca_cloud_stop() { if [ ! -f $OCF_RESKEY_pid ]; then ocf_log info "Eucalyptus Cloud Controller is not running" return $OCF_SUCCESS fi pid=`cat $OCF_RESKEY_pid 2> /dev/null ` /bin/kill $pid > /dev/null rc=$? if [ $rc != 0 ]; then ocf_log err "Eucalyptus Cloud Controller couldn't be stopped" return $OCF_ERR_GENERIC fi # stop waiting if [ -n "$OCF_RESKEY_stop_timeout" ]; then shutdown_timeout=$OCF_RESKEY_stop_timeout elif [ -n "$OCF_RESKEY_CRM_meta_timeout" ]; then shutdown_timeout=$((($OCF_RESKEY_CRM_meta_timeout/1000)-5)) else shutdown_timeout=10 fi count=0 while [ $count -lt $shutdown_timeout ] do euca_cloud_status rc=$? if [ $rc = $OCF_NOT_RUNNING ]; then break fi count=`expr $count + 1` sleep 1 ocf_log debug "Eucalyptus Cloud Controller hasn't yet stopped. Waiting..." done euca_cloud_status if [ $? != $OCF_NOT_RUNNING ]; then ocf_log info "Eucalyptus Cloud Controller failed to stop after ${shutdown_timeout}s using SIGTERM. Trying SIGKILL..." /bin/kill -KILL $pid > /dev/null fi } euca_cloud_validate() { if [ ! -x $OCF_RESKEY_binary ]; then ocf_log err "eucalyptus-cloud binary $OCF_RESKEY_binary does not exist or is not executable"; return $OCF_ERR_INSTALLED; fi getent passwd $OCF_RESKEY_user >/dev/null 2>&1 if [ ! $? -eq 0 ]; then ocf_log err "User $OCF_RESKEY_user doesn't exit"; return $OCF_ERR_INSTALLED; fi getent group $OCF_RESKEY_group >/dev/null 2>&1 if [ ! $? -eq 0 ]; then ocf_log err "Group $OCF_RESKEY_group doesn't exist"; return $OCF_ERR_INSTALLED; fi true } case $__OCF_ACTION in meta-data) meta_data exit $OCF_SUCCESS ;; usage|help) usage exit $OCF_SUCCESS ;; esac # Anything other than meta-data and usage must pass validation euca_cloud_validate || exit $? case $__OCF_ACTION in start) euca_cloud_start;; stop) euca_cloud_stop;; status|monitor) euca_cloud_monitor;; reload) ocf_log info "Reloading..." euca_cloud_start;; validate-all) ;; *) usage exit $OCF_ERR_UNIMPLEMENTED;; esac rc=$? ocf_log debug "${OCF_RESOURCE_INSTANCE} $__OCF_ACTION returned $rc" exit $rc