File: openstack-cluster-installer.init

package info (click to toggle)
openstack-cluster-installer 21
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 1,212 kB
  • sloc: php: 9,235; sh: 2,936; makefile: 14
file content (88 lines) | stat: -rw-r--r-- 2,814 bytes parent folder | download | duplicates (5)
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
#!/bin/sh

### BEGIN INIT INFO
# Provides:          openstack-cluster-installer
# Required-Start:    $network $remote_fs
# Required-Stop:     $network $remote_fs
# Should-Start:      $local_fs
# Should-Stop:       $local_fs
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: A small script to initialise iptables to allow forwarding and masquerading.
# Description:       A small script to initialise iptables to allow forwarding and masquerading.
### END INIT INFO

MODPROBE=/sbin/modprobe
IPTABLES=/sbin/iptables
EXTIF=`awk '{ if ( $2 == "00000000" ) print $1 }' /proc/net/route | head -n 1`

if ! [ -r /etc/openstack-cluster-installer/openstack-cluster-installer.conf ] ; then
	exit 0
else
	TMPFILE=$(mktemp -t openstack-cluster-installer.XXXXXX)
	cat /etc/openstack-cluster-installer/openstack-cluster-installer.conf | grep -v '^\[' >${TMPFILE}
	. ${TMPFILE}
	rm ${TMPFILE}
fi

if ! [ -x /usr/bin/openstack-cluster-installer-functions ] ; then
	exit 0
else
	. /usr/bin/openstack-cluster-installer-functions
fi

# Find configuration options from config file and some ipcalc foo
MGMT_NET_CIDR=${OPENSTACK_CLUSTER_NETWORK}
os_cluster_installer_calc_cluster_ips ${OPENSTACK_CLUSTER_NETWORK}
OTCI_PXE_SERVER_IP=${DOSCI_HOSTMIN}
OTCI_PXE_NETMASK=${DOSCI_NETMASK}


. /lib/lsb/init-functions

case "$1" in
start|systemd-start)
	echo 1 >/proc/sys/net/ipv4/ip_forward

	$MODPROBE ip_tables
	$MODPROBE ip_conntrack
	$MODPROBE iptable_nat
	$MODPROBE ip_nat_ftp

	$MODPROBE dummy
	ip link add ${PXE_NIC_NAME} type dummy || true
	ifconfig ${PXE_NIC_NAME} hw ether 00:22:22:ff:ff:fe

	# Create a bridge and bridge that interface to it
	ip tuntap add dev ${PXE_VM_VIRTAP_NAME} mode tap user ${PXE_VM_NIC_USER} || true
	brctl addbr ${PXE_BRIDGE_NAME} || true
	brctl addif ${PXE_BRIDGE_NAME} ${PXE_NIC_NAME} || true
	brctl addif ${PXE_BRIDGE_NAME} ${PXE_VM_VIRTAP_NAME} || true
	ifconfig ${PXE_BRIDGE_NAME} ${OTCI_PXE_SERVER_IP} netmask ${OTCI_PXE_NETMASK} up
	ip link set ${PXE_BRIDGE_NAME} up
	ip link set ${PXE_NIC_NAME} up
	ip link set ${PXE_VM_VIRTAP_NAME} up

	# Allow all connections OUT and only existing and related ones IN
	$IPTABLES -I FORWARD -i ${EXTIF} -o ${PXE_BRIDGE_NAME} -m state --state ESTABLISHED,RELATED -j ACCEPT
	$IPTABLES -I FORWARD -i ${PXE_BRIDGE_NAME} -s ${MGMT_NET_CIDR} -o ${EXTIF} -j ACCEPT

	#$IPTABLES -t nat -A POSTROUTING -o $EXTIF -j MASQUERADE
	$IPTABLES -t nat -I POSTROUTING -s ${MGMT_NET_CIDR} -o ${EXTIF} -j MASQUERADE
;;
stop)
	brctl delif ${PXE_BRIDGE_NAME} ${PXE_NIC_NAME} || true
	brctl delif ${PXE_BRIDGE_NAME} ${PXE_VM_VIRTAP_NAME} || true
	brctl delbr ${PXE_BRIDGE_NAME} || true
	ip link delete ${PXE_VM_VIRTAP_NAME} || true
;;
restart|reload|force-reload)
	$0 stop
	sleep 1
	$0 start
;;
*)
	echo 'Usage: $0 {start|stop|restart|reload}'
	exit 1
;;
esac