OpenVZ Forum


Home » General » Support » VE mutual dependence
Re: VE mutual dependence [message #34488 is a reply to message #34464] Mon, 12 January 2009 06:56 Go to previous message
curx
Messages: 739
Registered: February 2006
Location: Nürnberg, Germany
Senior Member

you can use the OpenVZ Action script for a single dependecy mechanism, here using a mount script.

Checks if a container is running, if not, mount script exit with error code greater than 0 and vzctl start is aborted.

#!/bin/bash

#  Copyright (C) 2006-2008 :
#	Thorsten Schifferdecker <tsd@debian.systs.org>
#  	All rights reserved.
#
#  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 2 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, write to the Free Software
#  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
#

#  /usr/share/vzctl/scripts/vps.mount-10-ct-dependency.sh 

# include main vz.conf
VZCONF=/etc/vz/vz.conf
[ -f ${VZCONF} ] || exit 0
. ${VZCONF}

# debug mode in main vz.conf set ?
[ "$DEBUG" == "yes" ] && set -x

# single dependency container id 
CT_DEPEND="`awk -F '"' '/^CT_DEPEND/ { print $2 }' /etc/vz/conf/$VEID.conf`"
[ -f /etc/vz/conf/${CT_DEPEND}.conf ] || exit 0
[ $VEID -ne $CT_DEPEND ] || exit 0

# cycles to check
CHECK_CYCLE=10

# sleep time
SLEEP_TIME=5

LOG_MESSAGE="Container dependency"
__OK="is solved"
__FAILED="has failed"

#
# main
#
for i in ${CHECK_CYCLE} ; do

	# started and running container has beancounters to avoid vzlist
	if [ -d /proc/bc/${CT_DEPEND} ] ; then
		[ $LOGGING == 'yes' ] && echo "`/bin/date +%FT%H:%M:%S%z` vzctl : CT ${VEID} : $LOG_MESSAGE to CT ${VEID} $__OK" >> $LOGFILE
		printf "$LOG_MESSAGE to CT ${VEID} $__OK\n"

		# add checking services, too
		# include service checks

		exit 0
	fi

sleep $SLEEP_TIME
done  

[ ${VERBOSE} -ne 0 ] && printf " to CT ${VEID} $__FAILED\n"
[ $LOGGING == 'yes' ] && printf "`/bin/date +%FT%H:%M:%S%z` vzctl : CT ${VEID} : Error $LOG_MESSAGE to CT ${VEID} $__FAILED\n" >> $LOGFILE
printf "$LOG_MESSAGE $__FAILED\n"

exit 1


save this script to /usr/share/vzctl/scripts/vps.mount-10-ct-dependency.sh and create a symbolic link :

global:
$ ln -s /usr/share/vzctl/scripts/vps.mount-10-ct-dependency.sh /etc/vz/conf/vps.mount

or for single container,m only:
$ ln -s /usr/share/vzctl/scripts/vps.mount-10-ct-dependency.sh /etc/vz/conf/<CTID>.mount

and activate check:

$ echo "CT_DEPEND=\"<CTID_DEPENDS_ON>\"" >> /etc/vz/conf/<CTID>.conf

Bye,
Thorsten
 
Read Message
Read Message
Read Message
Read Message
Previous Topic: Lenny linux-image-2.6.26-1-openvz-amd64 2.6.26-12 does not boot on dual Quadcore
Next Topic: df: `/': No such device
Goto Forum:
  


Current Time: Sun Sep 08 05:13:56 GMT 2024

Total time taken to generate the page: 0.05428 seconds