#!/bin/bash
#
# Copyright (c) 2009 Michael Schwartzkopff
#
# 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, either version 3 of the License, or
# (at your option) any later version.
#
# 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 <http://www.gnu.org/licenses/>.
#
#######################################################################
#
# TODO:
#	More resources!
# 	Parameter validation
#	Detect dependent resources and configure them also:
#	Something like: reswiz Filesystem adds resFS and resDRBD
#
######################################################################

SCRIPTNAME=reswiz

configure_apache()
{
  APACHECONFIG=`apache2 -V | awk -F'\"' '/SERVER_CONFIG_FILE/ { print $2 }'`
  echo $APACHECONFIG

  APACHEBIN=`ps x  | awk '/httpd|apache/ { print $5 }' | grep -v bash`
  echo $APACHEBIN

  crm<<EOF
    configure
      primitive resApache ocf:heartbeat:apache \
      params configfile=$APACHECONFIG httpd=$APACHEBIN \
      meta target-role=stopped \
      op monitor interval=30s
    commit
    exit
EOF
}

case "$1" in
  apache)
    configure_apache
    ;;
  *)
    echo "This script will configure your running (!) resource"
    echo "automagically as a resource of your cluster."
    echo ""
    echo "Usage: $SCRIPTNAME {apache}" >&2
    echo ""
    echo "Sorry. Up to now only a apache resource as technical"
    echo "demostration is configured."
    exit 3
    ;;
esac
