diff --git a/heartbeat/lxc b/heartbeat/lxc index cdeb82a13..ae7572863 100755 --- a/heartbeat/lxc +++ b/heartbeat/lxc @@ -1,315 +1,297 @@ #!/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_LXC_CNAME # OCF_RESKEY_LXC_BCP # OCF_RESKEY_LXC_BRP # OCF_RESKEY_LXC_CF_FILENAME # # Whilst testing, fix these values so that the OCF can run from command line # This does not conform to the guidlines, so each line should be prefixed with "#" in production # # OCF_RESKEY_LXC_CNAME_default="test1" # OCF_RESKEY_LXC_BCP_default="/etc/lxc" # OCF_RESKEY_LXC_BRP_default="/srv/lxc" # OCF_RESKEY_LXC_CF_FILENAME="config" # : ${OCF_RESKEY_LXC_CNAME=${OCF_RESKEY_LXC_CNAME_default}} # : ${OCF_RESKEY_LXC_BCP=${OCF_RESKEY_LXC_BCP_default}} # : ${OCF_RESKEY_LXC_BRP=${OCF_RESKEY_LXC_BRP_default}} # : ${OCF_RESKEY_LXC_CF_FILENAME=${OCF_RESKEY_LXC_CF_FILENAME}} # OCF_ROOT="/usr/lib/ocf" # OCF_RESKEY_CRM_meta_globally_unique="true" # OCF_RESKEY_stop_timeout=30000 # # Initialization: : ${OCF_FUNCTIONS_DIR=${OCF_ROOT}/lib/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}/LXC_${OCF_RESKEY_LXC_CNAME}-${OCF_RESOURCE_INSTANCE}.state" # It would be "Bad" if the container were to be run on more than one node, using lock file in shared configration directory to prevent it. LOCKFILE="${OCF_RESKEY_LXC_BCP}/${OCF_RESKEY_LXC_CNAME}/${OCF_RESKEY_LXC_CNAME}.lock" ## ocf_release_lock_on_exit $LOCKFILE # does not work as I would expect ti too :-( # # put this here as it's so long it gets messy later!!! STARTCMD="screen -dmS ${OCF_RESKEY_LXC_CNAME} lxc-start -f ${OCF_RESKEY_LXC_CF_FILENAME} -n ${OCF_RESKEY_LXC_CNAME}" # confirm cgroup_mounted # 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 # don't exit on TERM, the lrmd should handle that #trap sigterm_handler TERM #sigterm_handler() { # ocf_log info "Cluster resource detected TERM signal, Please use cluster resource manager to control resources" # return #} meta_data() { cat < 0.1 This is derived from the generic OCF RA, to manage LXC containers. It allow LXC continers to be managed by the cluster Manages LXC containers The unique name for this 'Container Instance' e.g. 'test1'. Container Name The path to the directories holding each containers configuration files e.g. '/etc/lxc'. Full path to the config root The path to the directories holding each containers "root" filesystem e.g. '/srv/lxc'. Full path to the parent containers "root" filesystems The file holding the specific configuration for this container e.g. 'config'. The LXC config file. END } LXC_usage() { cat <