vboxnet.init.tmpl revision 6be66de4257f4f564e35f7b8ee57a282e3cf3e96
#
# innotek VirtualBox
# Linux static host networking interface initialization
#
#
# Copyright (C) 2007 innotek GmbH
#
# This file is part of VirtualBox Open Source Edition (OSE), as
# available from http://www.virtualbox.org. This file is free software;
# General Public License as published by the Free Software Foundation,
# in version 2 as it comes in the "COPYING" file of the VirtualBox OSE
# distribution. VirtualBox OSE is distributed in the hope that it will
# be useful, but WITHOUT ANY WARRANTY of any kind.
#
# If you received this file as part of a commercial VirtualBox
# distribution, then only the terms of your commercial VirtualBox
# license agreement apply instead of the previous paragraph.
#
# chkconfig: 35 30 60
# description: VirtualBox permanent host networking setup
#
### BEGIN INIT INFO
# Provides: vboxnet
# Required-Start: $network
# Required-Stop:
# Default-Start: 3 5
# Default-Stop:
# Description: VirtualBox permanent host networking setup
### END INIT INFO
CONFIG="/etc/vbox/interfaces"
VARDIR="/var/run/VirtualBox"
else
{
echo -n "$@..."
}
{
if [ -z "${2:-}" ]; then
end="."
else
end=" ($2)."
fi
if [ $1 -eq 0 ]; then
echo "done${end}"
else
echo "failed${end}"
fi
}
{
echo "$@"
}
{
echo "$@"
}
fi
failure()
{
log_action_end_msg 1 "$1"
exit 0
}
running()
{
test -f "$VARFILE"
}
{
return 0
else
return 1
fi
}
# Create all permanent TAP devices registered on the system, add them to a
# bridge if required and keep a record of proceedings in the file
# /var/run/VirtualBox/vboxnet. If this file already exists, assume that the
# script has already been started and do nothing.
log_action_begin_msg "Starting VirtualBox host networking"
# If there is no configuration file or if the service is already running,
# assume that we have successfully started.
return 0
fi
# Fail if we can't create our runtime record file
fi
fi
fi
# Fail if we can't read our configuration
fi
# Fail if we don't have tunctl
if ! VBoxTunctl -h 2>&1 | grep -q VBoxTunctl > /dev/null; then
failure "VBoxTunctl not found"
fi
# Read the configuration file entries line by line and create the
# interfaces
while read line; do
# If the line is a comment then ignore it
# Check that the line is correctly formed (an interface name plus one
# or two non-comment entries, possibly followed by a comment).
then
# Try to create the interface
then
# Add the interface to a bridge if one was specified
if [ ! -z "$3" ]; then
else
echo "Warning - failed to add interface $1 to the bridge $3"
fi
else
fi
else
echo
echo "Warning - invalid line in $CONFIG:"
echo " $line"
fi
else
echo
echo "Warning - invalid line in $CONFIG:"
echo " $line"
fi
fi
done < "$CONFIG"
# yet belong to a group.
fi
return 0
}
# Shut down VirtualBox host networking and remove all permanent TAP
# interfaces. This action will fail if some interfaces could not be removed.
log_action_begin_msg "Shutting down VirtualBox host networking"
# If there is no runtime record file, assume that the service is not
# running.
return 0
fi
# Fail if we can't read our runtime record file or write to the
# folder it is located in
fi
# Fail if we don't have tunctl
if ! VBoxTunctl -h 2>&1 | grep -q VBoxTunctl > /dev/null; then
failure "VBoxTunctl not found"
fi
# Read the runtime record file entries line by line and delete the
# interfaces. The format of the runtime record file is not checked for
# errors.
while read line; do
# Remove the interface from a bridge if it is part of one
if [ ! -z "$3" ]; then
fi
# Remove the interface. Roll back everything and fail if this is not
# possible
then
while read line; do
if [ ! -z "$3" ]; then
fi
done < "$VARFILE"
failure "Removing of interface failed"
fi
done < "$VARFILE"
return 0
}
# Shut down VirtualBox host networking and remove all permanent TAP
# interfaces. This action will succeed even if not all interfaces could be
# removed. It is only intended for exceptional circumstances such as
# uninstalling VirtualBox.
log_action_begin_msg "Shutting down VirtualBox host networking"
# If there is no runtime record file, assume that the service is not
# running.
return 0
fi
# Fail if we can't read our runtime record file or write to the
# folder it is located in
fi
# Fail if we don't have tunctl
if ! VBoxTunctl -h 2>&1 | grep -q VBoxTunctl > /dev/null; then
failure "VBoxTunctl not found"
fi
# Read the runtime record file entries line by line and delete the
# interfaces. The format of the runtime record file is not checked for
# errors.
while read line; do
# Remove the interface from a bridge if it is part of one
if [ ! -z "$3" ]; then
fi
# Remove the interface.
done < "$VARFILE"
return 0
}
case "$1" in
;;
stop)
;;
;;
force-stop)
;;
if running; then
log_success_msg "VirtualBox host networking is loaded."
else
log_failure_msg "VirtualBox host networking is not loaded."
fi
;;
*)
exit 1
esac
exit