blob: 8d265fa56ea4ca212569c59fb59f9f7dd43b3e8a [file] [log] [blame] [raw]
#!/bin/bash
# Copyright (C) 2000-2005 SWsoft. All rights reserved.
#
# This file may be distributed under the terms of the Q Public License
# as defined by Trolltech AS of Norway and appearing in the file
# LICENSE.QPL included in the packaging of this file.
#
# This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
# WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
#
. /usr/lib/vzctl/scripts/vps-functions
VEINFO=/proc/vz/veinfo
PROC_PROXY_TR=/proc/proxy/targets
VES_INFO=
VE_RUN=
VE_PREV=
. /etc/sysconfig/vz
#
# Get currently running VEs list
#
function get_run_ve()
{
VE_RUN=`echo "${VES_INFO}" | awk '{if ($1 != 0) print $1}'`
}
#
# Get list of started VEs by vzctl
#
function get_prev_ve()
{
[ -d "${VE_STATE_DIR}" ] || return
VE_PREV=`ls ${VE_STATE_DIR} | grep -w -e "[0-9]*" 2>/dev/null`
}
#
# Get list of stopped VEs
#
function get_stopped_ve()
{
get_run_ve
get_prev_ve
if [ -z "${VE_RUN}" ]; then
VE_STOPPED="${VE_PREV}"
else
VE_STOPPED=`echo -e "${VE_PREV}" | grep -w -v "${VE_RUN}"`
fi
}
function get_ip_list()
{
local veid=$1
IP_ADDR=
[ -z "${veid}" ] && return
[ -f "${VE_STATE_DIR}/${veid}" ] || return
IP_ADDR=`cat ${VE_STATE_DIR}/${veid}`
}
function clear_ve_net()
{
local ip
VEID="$1"
[ -z "${VEID}" ] && return
get_ip_list ${VEID}
vzgetnetdev
[ -z "${LOGFILE}" ] || echo "`date --iso-8601=seconds` venetclean : VPS $VEID : VPS died, clear ips: ${IP_ADDR}" >> ${LOGFILE}
for ip in ${IP_ADDR}; do
# clear ip if not used
if ! echo -e "${VES_INFO}" | grep -w "${ip}" >/dev/null 2>&1;
then
vzdelrouting $ip
vzarp del $ip
fi
done
}
VES_INFO=`cat ${VEINFO} 2>/dev/null` || exit
get_stopped_ve
for ve in ${VE_STOPPED}
{
clear_ve_net ${ve}
rm -f ${VE_STATE_DIR}/${ve} >/dev/null 2>&1
}