/etc/vz/dists/scripts/gentoo-add_ip.sh is in vzctl 4.9.4-5.
This file is owned by root:root, with mode 0o755.
The actual contents of the file can be viewed below.
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 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 | #!/bin/bash
# Copyright (C) 2000-2012, Parallels, Inc. 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
#
#
# This script configures IP alias(es) inside Gentoo based CT with
# baselayout-1/openrc used as services/startup/shutdown system.
VENET_DEV=venet0
IFCFG=/etc/conf.d/net
SCRIPT=/etc/runlevels/default/net.${VENET_DEV}
HOSTFILE=/etc/hosts
# Return true if we have old baselayout-1.x based CT and false if not.
# Note: /etc/gentoo-release has nothing to do with init system
function is_baselayout1()
{
[ -f /sbin/functions.sh ]
}
function comment_line_regex()
{
cp -pf ${IFCFG} ${IFCFG}.$$ ||
error "Failed to comment ${1}: unable to copy ${IFCFG}" ${VZ_FS_NO_DISK_SPACE}
sed -e "s/${1}/#${1}/" < ${IFCFG} > ${IFCFG}.$$ &&
mv -f ${IFCFG}.$$ ${IFCFG} 2>/dev/null
if [ $? -ne 0 ]; then
rm -f ${IFCFG}.$$ 2>/dev/null
error "Failed to comment ${1}: unable to create ${IFCFG}."
fi
}
function set_config()
{
if ! grep -qe "^config_eth" ${IFCFG} 2>/dev/null; then
comment_line_regex "^config_eth"
comment_line_regex "^routes_eth"
fi
if ! is_baselayout1 ; then
put_param ${IFCFG} "config_${VENET_DEV}" ""
put_param ${IFCFG} "routes_${VENET_DEV}" "default"
else
put_param3 ${IFCFG} "config_${VENET_DEV}" ""
add_param3 ${IFCFG} "routes_${VENET_DEV}" "default"
fi
}
function set_rc()
{
[ -f "${SCRIPT}" ] && return 0
rc-update del net.eth0 &>/dev/null
rc-update add net.lo boot &>/dev/null
ln -sf /etc/init.d/net.lo /etc/init.d/net.${VENET_DEV}
rc-update add net.${VENET_DEV} default &>/dev/null
}
function init_netconfig()
{
set_rc
set_config
# Set up /etc/hosts
if [ ! -f ${HOSTFILE} ]; then
echo "127.0.0.1 localhost.localdomain localhost" > $HOSTFILE
fi
}
function have_ips()
{
[ -n "${IP_ADDR}" ]
}
function venet_configured()
{
grep -q "^routes_${VENET_DEV}" ${IFCFG} >/dev/null 2>&1
}
function add_ip()
{
local ipm
if [ "x${VE_STATE}" = "xstarting" -o "x${IPDELALL}" = "xyes" ]; then
have_ips && init_netconfig
if [ "x${IPDELALL}" = "xyes" ]; then
/etc/init.d/net.${VENET_DEV} stop >/dev/null 2>&1
return 0
fi
else
have_ips && venet_configured || set_config
fi
for ipm in ${IP_ADDR}; do
ip_conv $ipm
if ! grep -qw "config_${VENET_DEV}=\(.*\"${_IP}[\"\/].*\)" ${IFCFG}; then
if ! is_baselayout1 ; then
add_param "${IFCFG}" "config_${VENET_DEV}" "${_IP}/${_MASK}"
else
add_param3 "${IFCFG}" "config_${VENET_DEV}" "${_IP}/${_MASK}"
fi
fi
done
if [ "x${VE_STATE}" = "xrunning" ]; then
# synchronyze config files & interfaces
/etc/init.d/net.${VENET_DEV} restart >/dev/null 2>&1
fi
}
add_ip
exit 0
# end of script
|