File: vpsnetclean

package info (click to toggle)
vzctl 3.0.11-13
  • links: PTS
  • area: main
  • in suites: etch-m68k
  • size: 1,164 kB
  • ctags: 1,894
  • sloc: ansic: 14,655; sh: 2,744; makefile: 419
file content (106 lines) | stat: -rwxr-xr-x 2,360 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#!/bin/bash
#  Copyright (C) 2000-2006 SWsoft. 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
#
#

VZCONF=/etc/vz/vz.conf
VEINFO=/proc/vz/veinfo
PROC_PROXY_TR=/proc/proxy/targets
VES_INFO=
VE_RUN=
VE_PREV=

test -f ${VZCONF} || exit 1
test -f /usr/lib/vzctl/scripts/vps-functions || exit 1

. /usr/lib/vzctl/scripts/vps-functions
. ${VZCONF}

#
# 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
}

# If VZ is not running -- do nothing
# Fix for OpenVZ bug #107
test -f ${VEINFO} || exit 0

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
}