[prev in list] [next in list] [prev in thread] [next in thread] 

List:       linux-ha-dev
Subject:    Re: [Linux-ha-dev] Linux-HA-Dev Digest, Vol 90, Issue 6
From:       Darren Thompson <darrent () akurit ! com ! au>
Date:       2011-05-05 2:58:32
Message-ID: 1304563592.6845.7.camel () darrensPC ! akurit ! com ! au
[Download RAW message or body]

[Attachment #2 (multipart/alternative)]


Florian/Team

There was an error in the GIT-Hub version that was causing my re-base
attempts to fail, so I was forced to try to bring my "last known good"
version to the same configuration (mostly successful).

I have since found the error in the GIT-Hub version (the initialisation
section was wrong, the meta-data error was a 'red herring') so have been
found and resolved so I have done an actual re-base now based on the
GIT-Hub version. 

Changes:

1. Corrected error in utilisation causing ocf to fail in HB_GUI.
2. Added "information"  to stop  section, to provide more feedback on
container shutdown/stop (and to assist with future development of
"containers using alternate 'init' systems").

Regards
Darren


On Wed, 2011-05-04 at 12:00 -0600,
linux-ha-dev-request@lists.linux-ha.org wrote:

> > Florian/Team
> > 
> > I have now updated my "re-based" ocf file to include the
> "experimental"
> > support for upstart and systemd using containers.
> > 
> > I can confirm that this is still working correctly for containers
> > running 'sysv init' and "in theory" should now also work for
> containers
> > using 'upstart' and 'systemd'.
> > 
> > I'm currently doing a "crash course' in installing containers to use
> > these 'init replacments' but have not yet succedded in testing
> either
> > 'upstart' or 'systemd' containers yet.
> > 
> > If there is anyone with a better understanding of LXC containers and
> > one/both of these other 'init systems', please contact me as your
> > information/assistance would be invaluable.
> 
> OK, updated my git branch. You really want to double check your
> "rebasing" method; you're constantly re-introducing things that I've
> removed or fixed in earlier commits.
> 
> Florian
> 

[Attachment #5 (text/html)]

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 TRANSITIONAL//EN">
<HTML>
<HEAD>
  <META HTTP-EQUIV="Content-Type" CONTENT="text/html; CHARSET=UTF-8">
  <META NAME="GENERATOR" CONTENT="GtkHTML/3.28.2">
</HEAD>
<BODY>
Florian/Team<BR>
<BR>
There was an error in the GIT-Hub version that was causing my re-base attempts to \
fail, so I was forced to try to bring my &quot;last known good&quot; version to the \
same configuration (mostly successful).<BR> <BR>
I have since found the error in the GIT-Hub version (the initialisation section was \
wrong, the meta-data error was a 'red herring') so have been found and resolved so I \
have done an actual re-base now based on the GIT-Hub version. <BR> <BR>
Changes:<BR>
<BR>
1. Corrected error in utilisation causing ocf to fail in HB_GUI.<BR>
2. Added &quot;information&quot;&nbsp; to stop&nbsp; section, to provide more \
feedback on container shutdown/stop (and to assist with future development of \
&quot;containers using alternate 'init' systems&quot;).<BR> <BR>
Regards<BR>
Darren<BR>
<BR>
<BR>
On Wed, 2011-05-04 at 12:00 -0600, linux-ha-dev-request@lists.linux-ha.org wrote:<BR>
<BLOCKQUOTE TYPE=CITE>
    <TT><FONT COLOR="#737373">&gt; Florian/Team</FONT></TT><BR>
    <TT><FONT COLOR="#737373">&gt; </FONT></TT><BR>
    <TT><FONT COLOR="#737373">&gt; I have now updated my &quot;re-based&quot; ocf \
file to include the &quot;experimental&quot;</FONT></TT><BR>  <TT><FONT \
COLOR="#737373">&gt; support for upstart and systemd using \
containers.</FONT></TT><BR>  <TT><FONT COLOR="#737373">&gt; </FONT></TT><BR>
    <TT><FONT COLOR="#737373">&gt; I can confirm that this is still working correctly \
for containers</FONT></TT><BR>  <TT><FONT COLOR="#737373">&gt; running 'sysv init' \
and &quot;in theory&quot; should now also work for containers</FONT></TT><BR>  \
<TT><FONT COLOR="#737373">&gt; using 'upstart' and 'systemd'.</FONT></TT><BR>  \
<TT><FONT COLOR="#737373">&gt; </FONT></TT><BR>  <TT><FONT COLOR="#737373">&gt; I'm \
currently doing a &quot;crash course' in installing containers to use</FONT></TT><BR> \
<TT><FONT COLOR="#737373">&gt; these 'init replacments' but have not yet succedded in \
testing either</FONT></TT><BR>  <TT><FONT COLOR="#737373">&gt; 'upstart' or 'systemd' \
containers yet.</FONT></TT><BR>  <TT><FONT COLOR="#737373">&gt; </FONT></TT><BR>
    <TT><FONT COLOR="#737373">&gt; If there is anyone with a better understanding of \
LXC containers and</FONT></TT><BR>  <TT><FONT COLOR="#737373">&gt; one/both of these \
other 'init systems', please contact me as your</FONT></TT><BR>  <TT><FONT \
COLOR="#737373">&gt; information/assistance would be invaluable.</FONT></TT><BR>  \
<BR>  <TT><FONT COLOR="#000000">OK, updated my git branch. You really want to double \
check your</FONT></TT><BR>  <TT><FONT COLOR="#000000">&quot;rebasing&quot; method; \
you're constantly re-introducing things that I've</FONT></TT><BR>  <TT><FONT \
COLOR="#000000">removed or fixed in earlier commits.</FONT></TT><BR>  <BR>
    <TT><FONT COLOR="#000000">Florian</FONT></TT><BR>
    <BR>
</BLOCKQUOTE>
</BODY>
</HTML>


["lxc" (application/x-shellscript)]

#!/bin/bash
# Should now conform to guidlines: \
http://www.linux-ha.org/doc/dev-guides/ra-dev-guide.html #
#	LXC (Linux Containers) OCF RA. 
#	Used to cluster enable the start, stop and monitoring of a LXC container.
#
# Copyright (c) 2011 AkurIT.com.au, Darren Thompson
#                    All Rights Reserved.
#
# Without limiting the rights of the original copyright holders
# This resource is licensed under GPL version 2
#
# 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.

# OCF instance parameters
#       OCF_RESKEY_container
#       OCF_RESKEY_config

# Initialization:
> ${OCF_FUNCTIONS_DIR=${OCF_ROOT}/resource.d/heartbeat}
. ${OCF_FUNCTIONS_DIR}/.ocf-shellfuncs

# Set default TRANS_RES_STATE (temporary file to "flag" if resource was stated but \
not stopped) TRANS_RES_STATE="${HA_RSCTMP}/${OCF_RESOURCE_INSTANCE}.state"

meta_data() {
cat <<END
<?xml version="1.0"?>
<!DOCTYPE resource-agent SYSTEM "ra-api-1.dtd">
<resource-agent name="lxc" version="0.1">
<version>0.1</version>
<longdesc lang="en">Allows LXC containers to be managed by the cluster.
If the container is running "init" it will also perform an orderly shutdown.
It is 'assumed' that the 'init' system will do an orderly shudown if presented with a \
'kill -PWR' signal. On a 'sysvinit' this would require the container to have an \
inittab file containing "p0::powerfail:/sbin/init 0" I have absolutly no idea how \
this is done with 'upstart' or 'systemd', YMMV if your container is using one of \
them.</longdesc> <shortdesc lang="en">Manages LXC containers</shortdesc>

<parameters>
<parameter name="container" required="1" unique="1">
<longdesc lang="en">The unique name for this 'Container Instance' e.g. \
'test1'.</longdesc> <shortdesc lang="en">Container Name</shortdesc>
<content type="string" default=""/>
</parameter>

<parameter name="config" required="1" unique="0">
<longdesc lang="en">Absolute path to the file holding the specific configuration for \
this container e.g. '/etc/lxc/test1/config'.</longdesc> <shortdesc lang="en">The LXC \
config file.</shortdesc> <content type="string" default=""/>
</parameter>

</parameters>

<actions>
<action name="start"        timeout="10" />
<action name="stop"         timeout="30" />
<action name="monitor"      timeout="20" interval="60" start-delay="10" depth="0"/>
<action name="reload"       timeout="20" />
<action name="validate-all" timeout="20" />
<action name="meta-data"    timeout="5" />
</actions>
</resource-agent>
END
}


LXC_usage() {
	cat <<END
	usage: $0 {start|stop|monitor|reload|validate-all|meta-data}

	Expects to have a fully populated OCF RA-compliant environment set.
END
}

cgroup_mounted() {
# test cgroup_mounted, mount if required
	# Various possible overrides to cgroup mount point.
	# If kernel supplies cgroup mount point, prefer it.
	CGROUP_MOUNT_POINT=/var/run/lxc/cgroup
	CGROUP_MOUNT_NAME=lxc
	CGROUP_MOUNTED=false
	[[ -d /sys/fs/cgroup ]] && CGROUP_MOUNT_POINT=/sys/fs/cgroup \
CGROUP_MOUNT_NAME=cgroup  # If cgroup already mounted, use it no matter where it is.
	# If multiple cgroup mounts, prefer the one named lxc if any.
	eval `awk 'BEGIN{P="";N=""}END{print("cgmp="P" \
cgmn="N)}($3=="cgroup"){N=$1;P=$2;if($1="lxc")exit}' /proc/mounts`  [[ "$cgmn" && \
"$cgmp" && -d "$cgmp" ]] && CGROUP_MOUNT_POINT=$cgmp CGROUP_MOUNT_NAME=$cgmn \
CGROUP_MOUNTED=true  CGROUP_RELEASE_AGENT="/usr/sbin/lxc_cgroup_release_agent"
	$CGROUP_MOUNTED || {
		[[ -d $CGROUP_MOUNT_POINT ]] || mkdir -p $CGROUP_MOUNT_POINT
		mount -t cgroup $CGROUP_MOUNT_NAME $CGROUP_MOUNT_POINT
	}
	echo 1 >${CGROUP_MOUNT_POINT}/notify_on_release
	return 0
}

LXC_start() {
	# put this here as it's so long it gets messy later!!!
	STARTCMD="screen -dmS ${OCF_RESKEY_container} lxc-start -f ${OCF_RESKEY_config} -n \
${OCF_RESKEY_container}"  cgroup_mounted
	ret=$?
	if [ $ret ]; then
		if LXC_validate ; then
			if ! LXC_monitor ; then
		   	    touch $TRANS_RES_STATE
			    ocf_log info "Starting" ${OCF_RESKEY_container} 
		            ocf_run ${STARTCMD} || exit $OCF_ERR_GENERIC 
			else
				# If already running, consider start successful
				ocf_log debug ${OCF_RESOURCE_INSTANCE}: ${OCF_RESKEY_container} "is already \
running"  return $OCF_SUCCESS
			fi
			return $OCF_SUCCESS
		else
			ret=$?
			return $ret
		fi
	else
		return $OCF_ERR_GENERIC
	fi
}



LXC_stop() {
	cgroup_mounted
	ret=$?
	if [ $ret ]; then
		# If the container is running "init" and is able to perform and orderly shutdown, \
then it should be done.  # It is 'assumed' that the 'init' system will do an orderly \
shudown if presented with a 'kill -PWR' signal.  # On a 'sysvinit' this would require \
the container to have an inittab file containing "p0::powerfail:/sbin/init 0"  # I \
have absolutly no idea how this is done with 'upstart' or 'systemd', YMMV if your \
container is using one of them.  typeset -i PID=0
		# This should work for traditional 'sysvinit' and 'upstart'
		lxc-ps -C init -opid |while read CN PID ;do
			[[ $PID -gt 1 ]] || continue
			[[ "$CN" = "${OCF_RESKEY_container}" ]] || continue
			ocf_log info "Sending \"OS shut down\" instruction to" ${OCF_RESKEY_container} "as \
it was found to be using \"sysV init\" or \"upstart\""  kill -PWR $PID
		done
		# This should work for containers using 'systemd' instead of 'init'
		lxc-ps -C systemd -opid |while read CN PID ;do
			[[ $PID -gt 1 ]] || continue
			[[ "$CN" = "${OCF_RESKEY_container}" ]] || continue
			ocf_log info "Sending \"OS shut down\" instruction to" ${OCF_RESKEY_container} "as \
it was found to be using \"systemd\""  kill -PWR $PID
		done
	        if [ -n "$OCF_RESKEY_stop_timeout" ]
	        then
	                # Allow 2/3 of the stop timeout for the orderly shutdown
	                # (The origin unit is ms, hence the conversion)
	                stop_timeout=$((OCF_RESKEY_stop_timeout/1500))
	        elif [ -n "$OCF_RESKEY_CRM_meta_timeout" ]; then
	                # Allow 2/3 of the action timeout for the orderly shutdown
	                # (The origin unit is ms, hence the conversion)
	                stop_timeout=$((OCF_RESKEY_CRM_meta_timeout/1500))
	        else
	                stop_timeout=10
	        fi
		sleep $stop_timeout 
		# If the container is still running, it will be stopped now. regardless of state!
		lxc-stop -n ${OCF_RESKEY_container}
		ocf_log info "Container" ${OCF_RESKEY_container} "stopped"
		if [ -f $TRANS_RES_STATE ]; then	
			rm $TRANS_RES_STATE
		else
			ocf_log err "Dolt!" ${OCF_RESKEY_container} "does not seem to be started!"
			return ${OCF_ERR_GENERIC}
		fi
		return $OCF_SUCCESS
	else
		return $OCF_ERR_GENERIC
	fi
}

LXC_monitor() {
        S=`lxc-info -n ${OCF_RESKEY_container}`
	ocf_log info "$S"
	if [[ "${S##* }" = "RUNNING" ]] ; then 
		if [ -f $TRANS_RES_STATE ]; then
			return $OCF_SUCCESS
		else
			return $OCF_ERR_GENERIC
		fi
	else
		if [ -f $TRANS_RES_STATE ]; then
			ocf_log err "Dolt!" ${OCF_RESKEY_container} "should be running!"
			return $OCF_ERR_GENERIC
		fi
			return $OCF_NOT_RUNNING
	fi
}


LXC_validate() {
	# Quick check that all required attributes are set
	if [ -z "${OCF_RESKEY_container}" ]; then
		ocf_log err "LXC container name not set!"
		exit $OCF_ERR_CONFIGURED
	fi
	if [ -z "${OCF_RESKEY_config}" ]; then
		ocf_log err "LXC configuration filename name not set!"
		exit $OCF_ERR_CONFIGURED
	else
		if ! [ -f "${OCF_RESKEY_config}" ]; then
			ocf_log err "LXC configuration file \"${OCF_RESKEY_config}\" missing or not \
found!"  exit $OCF_ERR_INSTALLED
		fi
	fi
	# Quick check that CGROUPS are corrrectly mounted
 	if ! [ -f ${CGROUP_MOUNT_POINT}/notify_on_release ]; then
		exit $OCF_ERR_INSTALLED
	fi
	# Quick check that required executables are present
 	check_binary lxc-start
 	check_binary lxc-stop
	check_binary lxc-ps
	check_binary lxc-info
	check_binary screen
	return $OCF_SUCCESS
}

case $__OCF_ACTION in
meta-data)	meta_data
		exit $OCF_SUCCESS
		;;
start)		LXC_start;;
stop)		LXC_stop;;
monitor)	LXC_monitor;;
reload)		ocf_log err "Reloading..."
		LXC_stop	        
		LXC_start
		;;
validate-all)	LXC_validate;;
usage|help)	LXC_usage
		exit $OCF_SUCCESS
		;;
*)		LXC_usage
		ocf_log err "$0 was called with unsupported arguments: $*"
		exit $OCF_ERR_UNIMPLEMENTED
		;;
esac
rc=$?
ocf_log debug "${OCF_RESOURCE_INSTANCE} $__OCF_ACTION : $rc"
exit $rc



_______________________________________________________
Linux-HA-Dev: Linux-HA-Dev@lists.linux-ha.org
http://lists.linux-ha.org/mailman/listinfo/linux-ha-dev
Home Page: http://linux-ha.org/


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic