summaryrefslogblamecommitdiffstats
path: root/core/modules/vmware-common/data/opt/openslx/scripts/systemd-vmware_env
blob: 751c321125af67b39d0f4a4bb028c5d411a87f89 (plain) (tree)
1
2
3
4
5
6
7
8
9

                                                                               
 
                                                 
 



                                                                         
                                              

                                                                            
 


                                                                                
                                                   




                                                                                

                     

                       





                                                                          


                                                                                                  

                                             

 









                                                                     
                                                                                                             




                                                                                                    
            
                            

                                                                    


                                                                                                     



                                     
            
                                                                                                 
                                                                          
                                                                                                 
                              
                               
                               
                                                          
                                                     
                                                                                          
                                                                            
                        





                                                                                       

                                                                   
                                                

                    

                                                               

 
            


                                                                                              






                                                                   












                                                                              
                       










                                                                 

    

      
#!/bin/ash
# -----------------------------------------------------------------------------
#
# Copyright (c) 2013..2018 bwLehrpool-Projektteam
#
# This program/file is free software distributed under the GPL version 2.
# See https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
#
# If you have any feedback please consult https://bwlehrpool.de and
# send your feedback to support@bwlehrpool.de.
#
# General information about bwLehrpool can be found at https://bwlehrpool.de
#
# -----------------------------------------------------------------------------
# systemd-vmware_env
#    - This is the systemd configuration and provisioning script for the various
#			VMware modules and services
################################################################################

VMWARE_CONF_DIR=/opt/openslx/vmchooser/vmware
VMCHOOSER_CONF_DIR=/opt/openslx/vmchooser/config

. /opt/openslx/config

load_modules () {
	local FAILED=""
	# module stuff
	insmod /lib/modules/vmware/vmmon.ko || FAILED="$FAILED vmmon"
	insmod /lib/modules/vmware/vmnet.ko || FAILED="$FAILED vmnet"
	#insmod /lib/modules/vmware/vmci.ko || FAILED="$FAILED vmci"
	#insmod /lib/modules/vmware/vmblock.ko || FAILED="$FAILED vmblock"
	#insmod /lib/modules/vmware/vsock.ko || FAILED="$FAILED vsock"
	[ -n "$FAILED" ] && slxlog "vmware-insmod" "Error loading vmware kernel module(s) $FAILED"
}

unload_modules () {
	rmmod vmnet vmmon #vsock vmci vmblock
}

vmnet_create() {
	vmnet="$1"
	# first, create device node
	dev="/dev/vmnet${vmnet}"
	if ! [ -c "$dev" ] && ! mknod "${dev}" c 119 "${vmnet}"; then
		slxlog "vmware-node-vmnet" "Could not create ${dev}"
		return 1
	fi
	chmod 0700 "${dev}"
	# now bring it up
	if ! /usr/bin/vmnet-netifup -d "/run/vmnet-netifup-vmnet${vmnet}.pid" "${dev}" "vmnet${vmnet}" ; then
		slxlog "vmware-netifup" "Launching /usr/bin/vmnet-netifup for vmnet${vmnet} failed."
	fi
	ip link set dev "vmnet${vmnet}" up
}

vmnetif () {
	local vmnet nic NICS
	# create the needed devices which effects all vmware options
	# they are not created automatically via module load
	if ! [ -e /dev/vmmon ]; then
		mknod /dev/vmmon c 10 165 || slxlog "vmware-node-vmmon" "Could not create /dev/vmmon"
	fi
	# network interfaces
	# 1) default ones
	for vmnet in 0 1 2; do
		vmnet_create "$vmnet"
	done
	# Set the vmware interface to 9000 too, as br0 will use the smallest of all slave devices
	[ "$SLX_JUMBO_FRAMES" = "yes" ] && ip link set dev vmnet0 mtu 9000
	# setup bridge (vmnet0), nat (vmnet1) and software defined networking (vmnet2) interfaces
	brctl addif br0 vmnet0
	brctl addif nat1 vmnet1
	brctl addif vsw2 vmnet2
	# 2) see if we should bridge additional interfaces
	if [ "$SLX_BRIDGE_OTHER_NICS" = "yes" ]; then
		# These will have been set up in our init, or by bridge-other-nics.service
		NICS=$( ls -1 /sys/class/net | grep '^br-nic-' | cut -c 8- )
		vmnet=10
		for nic in $NICS; do
			if ! [ "$nic" -gt 0 ] && ! [ "$nic" -eq 0 ]; then
				slxlog "vmware-other-nics" "NaN: br-nic-X has X='$nic'"
				continue
			fi
			# create vmnet10 - vmnetN for these
			vmnet_create "$vmnet"
			brctl addif "br-nic-${nic}" "vmnet${vmnet}"
			vmnet="$(( vmnet + 1 ))"
		done
	fi
	# trigger reload of iptables stuff (it's using inotify)
	touch /opt/openslx/iptables/rules.d/empty
}

vmblock () {
	# It's got to be *somewhere* right?
	if ! /usr/lib/vmware/bin/vmware-usbarbitrator && ! /usr/bin/vmware-usbarbitrator; then
		slxlog "vmware-usbarb" "Launching vmware-usbarbitrator failed."
	fi
}

# create required standard directories
mkdir -p "/tmp/virt/vmware" "/dev/shm/vmware" "/run/vmware" -m 1777

# FixMe: Should be rewritten for proper systemd operation
case "$1" in
	start)
		# hack to access the first serial/parallel port
		[ -c /dev/ttyS0 ] && chmod a+rw /dev/ttyS0
		[ -c /dev/parport0 ] && chmod a+rw /dev/parport0
		load_modules
		vmnetif
		vmblock
	;;
	stop)
		#stop: defines stop function for initscript
		killall vmnet-netifup vmnet-bridge vmware vmplayer vmware-tray
		# might take a while until all services are shut down
		sleep 1
		unload_modules

	;;
	restart)
		#restart: defines restart function for initscript
		$0 stop && $0 start
	;;
	status)
		#status: defines status function for initscript
		vmstatus
	;;
esac

exit 0