~ubuntu-branches/ubuntu/lucid/vzctl/lucid

« back to all changes in this revision

Viewing changes to scripts/vpsnetclean.in

  • Committer: Bazaar Package Importer
  • Author(s): Ola Lundqvist
  • Date: 2007-04-10 18:08:16 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20070410180816-0uuzj9fnna7gmzxv
Tags: 3.0.16-4
Etch has been released which means that this version can be uploaded
to unstable.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/bin/bash
 
2
#  Copyright (C) 2000-2007 SWsoft. All rights reserved.
 
3
#
 
4
#  This program is free software; you can redistribute it and/or modify
 
5
#  it under the terms of the GNU General Public License as published by
 
6
#  the Free Software Foundation; either version 2 of the License, or
 
7
#  (at your option) any later version.
 
8
#
 
9
#  This program is distributed in the hope that it will be useful,
 
10
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
11
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
12
#  GNU General Public License for more details.
 
13
#
 
14
#  You should have received a copy of the GNU General Public License
 
15
#  along with this program; if not, write to the Free Software
 
16
#  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
17
#
 
18
#
 
19
 
 
20
VZCONF=@PKGCONFDIR@/vz.conf
 
21
VEINFO=/proc/vz/veinfo
 
22
PROC_PROXY_TR=/proc/proxy/targets
 
23
VES_INFO=
 
24
VE_RUN=
 
25
VE_PREV=
 
26
 
 
27
test -f ${VZCONF} || exit 1
 
28
test -f @PKGLIBDIR@/scripts/vps-functions || exit 1
 
29
 
 
30
. @PKGLIBDIR@/scripts/vps-functions
 
31
. ${VZCONF}
 
32
 
 
33
#
 
34
# Get currently running VEs list
 
35
#
 
36
function get_run_ve()
 
37
{
 
38
        VE_RUN=`echo "${VES_INFO}" | awk '{if ($1 != 0) print $1}'` 
 
39
}
 
40
 
 
41
#
 
42
# Get list of started VEs by vzctl
 
43
#
 
44
function get_prev_ve()
 
45
{
 
46
        [ -d "${VE_STATE_DIR}" ] || return
 
47
        VE_PREV=`ls ${VE_STATE_DIR} | grep -w -e "[0-9]*" 2>/dev/null`
 
48
}
 
49
 
 
50
 
 
51
#
 
52
# Get list of stopped VEs
 
53
#
 
54
function get_stopped_ve()
 
55
{
 
56
        get_run_ve
 
57
        get_prev_ve
 
58
 
 
59
        if [ -z "${VE_RUN}" ]; then
 
60
                VE_STOPPED="${VE_PREV}"
 
61
        else
 
62
                VE_STOPPED=`echo -e "${VE_PREV}" | grep -w -v "${VE_RUN}"`
 
63
        fi
 
64
}
 
65
 
 
66
function get_ip_list()
 
67
{
 
68
        local veid=$1
 
69
 
 
70
        IP_ADDR=
 
71
        [ -z "${veid}" ] && return
 
72
        [ -f "${VE_STATE_DIR}/${veid}" ] || return
 
73
        IP_ADDR=`cat ${VE_STATE_DIR}/${veid}`
 
74
}
 
75
 
 
76
function clear_ve_net()
 
77
{
 
78
        local ip
 
79
        VEID="$1"
 
80
 
 
81
        [ -z "${VEID}" ] && return
 
82
        get_ip_list ${VEID}
 
83
        vzgetnetdev
 
84
        [ -z "${LOGFILE}" ] || echo "`date --iso-8601=seconds`  venetclean : VE $VEID : VE died, clear IPs: ${IP_ADDR}" >> ${LOGFILE}
 
85
        for ip in ${IP_ADDR}; do
 
86
                # clear IP if not used
 
87
                if ! echo -e "${VES_INFO}" | grep -w "${ip}" >/dev/null 2>&1;
 
88
                then
 
89
                        vzdelrouting $ip
 
90
                        vzarp del $ip
 
91
                fi
 
92
        done
 
93
}
 
94
 
 
95
# If VZ is not running -- do nothing
 
96
# Fix for OpenVZ bug #107
 
97
test -f ${VEINFO} || exit 0
 
98
 
 
99
VES_INFO=`cat ${VEINFO} 2>/dev/null` || exit
 
100
get_stopped_ve
 
101
for ve in ${VE_STOPPED}
 
102
{
 
103
        clear_ve_net ${ve}
 
104
        rm -f ${VE_STATE_DIR}/${ve} >/dev/null 2>&1
 
105
}
 
106