]> git.pld-linux.org Git - packages/VMware-workstation.git/blame - VMware-workstation.init
- drop obsolete and outdated manual inclusion of rpm macros
[packages/VMware-workstation.git] / VMware-workstation.init
CommitLineData
29328d5b 1#!/bin/sh
36b33dd9 2
29328d5b 3#
4# Copyright 1998 VMware, Inc. All rights reserved.
5#
6
d18baea8 7# vmnet: Manages the services needed to run VMware networking
29328d5b 8#
d18baea8 9# description: Manages the services needed to run VMware networking
a2c5e0b7 10#
ffbf41f5 11# chkconfig: 235 90 8
a2c5e0b7 12#
13# probe: true
14# hide: true
15
a19ca04e 16subsys=vmnet
345c7964 17driver=vmmon
18vnet=vmnet
19bridge=vmnet-bridge
20dhcpd=vmnet-dhcpd
21netifup=vmnet-netifup
22natd=vmnet-natd
23ping=vmware-ping
24smbd=vmware-smbd
25nmbd=vmware-nmbd
29328d5b 26
efe88284 27# Source config files
36b33dd9 28vmware_etc_dir=/etc/vmware
efe88284 29vmware_locations="$vmware_etc_dir"/locations
2e3c2f73 30vmnet_cfg="$vmware_etc_dir"/vmnet.conf
efe88284 31
32for f in $vmware_locations $vmnet_cfg; do
33 if [ -r $f ]; then
34 . $f
83ae92eb 35 else
efe88284 36 echo "FATAL: Unable to read $f"
37 exit 1
38 fi
83ae92eb 39done
36b33dd9 40
41# System wide functions
42. /etc/rc.d/init.d/functions
43
347c4848 44# Create /dev/vmnetXX device
45vmware_create_vmnet() {
46 local vHubNr="$1" # IN
47 local vDevice="/dev/vmnet$vHubNr"
48
49 if [ ! -e "$vDevice" ]; then
50 mknod -m 600 "$vDevice" c 119 "$vHubNr"
51 fi
52}
83ae92eb 53
29328d5b 54#
345c7964 55# Create a temporary directory
29328d5b 56#
57
345c7964 58# They are a lot of small utility programs to create temporary files in a
59# secure way, but none of them is standard. So I wrote this --hpreg
60make_tmp_dir() {
61 local dirname="$1" # OUT
62 local prefix="$2" # IN
63 local tmp
64 local serial
65 local loop
66
67 tmp="${TMPDIR:-/tmp}"
345c7964 68 # Don't overwrite existing user data
69 # -> Create a directory with a name that didn't exist before
70 #
71 # This may never succeed (if we are racing with a malicious process), but at
72 # least it is secure
73 serial=0
74 loop='yes'
75 while [ "$loop" = 'yes' ]; do
76 # Check the validity of the temporary directory. We do this in the loop
77 # because it can change over time
78 if [ ! -d "$tmp" ]; then
3e0d5b52 79 echo 'Error: "'"$tmp"'" is not a directory.'
80 echo
81 exit 1
345c7964 82 fi
83 if [ ! -w "$tmp" -o ! -x "$tmp" ]; then
3e0d5b52 84 echo 'Error: "'"$tmp"'" should be writable and executable.'
85 echo
86 exit 1
345c7964 87 fi
88 # Be secure
89 # -> Don't give write access to other users (so that they can not use this
90 # directory to launch a symlink attack)
91 if mkdir -m 0755 "$tmp"'/'"$prefix$serial" >/dev/null 2>&1; then
3e0d5b52 92 loop='no'
345c7964 93 else
3e0d5b52 94 serial=`expr "$serial" + 1`
95 if [ "`expr "$serial" % 200`" = '0' ]; then
96 echo 'Warning: The "'"$tmp"'" directory may be under attack.'
97 echo
98 fi
345c7964 99 fi
100 done
101 eval "$dirname"'="$tmp"'"'"'/'"'"'"$prefix$serial"'
102}
29328d5b 103
29328d5b 104#
36b33dd9 105# Utilities
29328d5b 106#
345c7964 107
29328d5b 108# Compute the subnet address associated to a couple IP/netmask
109ipv4_subnet() {
345c7964 110 local ip="$1"
111 local netmask="$2"
29328d5b 112
345c7964 113 # Split quad-dotted addresses into bytes
114 # There is no double quote around the back-quoted expression on purpose
115 # There is no double quote around $ip and $netmask on purpose
116 set -- `IFS='.'; echo $ip $netmask`
117 echo $(($1 & $5)).$(($2 & $6)).$(($3 & $7)).$(($4 & $8))
29328d5b 118}
119
120# Compute the broadcast address associated to a couple IP/netmask
121ipv4_broadcast() {
345c7964 122 local ip="$1"
123 local netmask="$2"
29328d5b 124
345c7964 125 # Split quad-dotted addresses into bytes
126 # There is no double quote around the back-quoted expression on purpose
127 # There is no double quote around $ip and $netmask on purpose
128 set -- `IFS='.'; echo $ip $netmask`
129 echo $(($1 | (255 - $5))).$(($2 | (255 - $6))).$(($3 | (255 - $7))).$(($4 | (255 - $8)))
29328d5b 130}
131
36b33dd9 132# Count the number of running virtual machines by looking at the number of references
133# to the $driver module.
29328d5b 134countVMs() {
345c7964 135 # Beware of module dependancies here. An exact match is important
136 /sbin/lsmod | awk 'BEGIN {n = 0;} {if ($1 == "'"$driver"'") n = $3;} END {print n;}'
29328d5b 137}
138
29328d5b 139# Check if there is an IP route for a given subnet via a given interface
140# Return true if there is _NO_ such route
141noRoutePresent() {
345c7964 142 local subnet="$1" # IN
143 local intf="$2" # IN
29328d5b 144
345c7964 145 # Beware, there may be several identical routes
146 [ "`/sbin/route -n | grep '^'"$subnet"'.*'"$intf"'$'`" = '' ]
29328d5b 147}
148
29328d5b 149
29328d5b 150# Macro definitions
151#
152# Note:
153# . Each daemon must be started from its own directory to avoid busy devices
154# . Each PID file doesn't need to be added to the installer database, because
155# it is going to be automatically removed when it becomes stale (after a
156# reboot). It must go directly under /var/run, or some distributions
157# (RedHat 6.0) won't clean it
158#
159
160# Terminate a process synchronously
161vmware_synchrone_kill() {
345c7964 162 local pid="$1" # IN
163 local signal="$2" # IN
164 local second
165
166 kill -"$signal" "$pid"
167 # Wait a bit to see if the dirty job has really been done
168 for second in 0 1 2 3 4 5 6 7 8 9 10; do
169 if [ ! -d /proc/"$pid" ]; then
3e0d5b52 170 # Success
171 return 0
345c7964 172 fi
173 sleep 1
174 done
3e0d5b52 175 # Timeout
345c7964 176 return 1
29328d5b 177}
178
179# Kill the process associated to a pidfile
180vmware_stop_pidfile() {
345c7964 181 local pidfile="$1" # IN
182 local pid
29328d5b 183
345c7964 184 pid=`cat "$pidfile" 2>/dev/null`
185 if [ "$pid" = '' ]; then
186 # The file probably does not exist or is empty. Success
187 return 0
188 fi
189 # Keep only the first number we find, because some Samba pid files are really
190 # trashy: they end with NUL characters
191 # There is no double quote around $pid on purpose
192 set -- $pid
193 pid="$1"
194 # First try a nice SIGTERM
195 if vmware_synchrone_kill "$pid" 15; then
196 return 0
197 fi
198 # Then send a strong SIGKILL
199 if vmware_synchrone_kill "$pid" 9; then
200 return 0
201 fi
202 return 1
29328d5b 203}
204
29328d5b 205# Start the host-only network user service
206vmware_start_hostonly() {
345c7964 207 local vHubNr="$1" # IN
208 local vHostIf="$2" # IN
209 local ifIp="$3" # IN
210 local ifMask="$4" # IN
211 local run_dhcpd="$5" # IN
212 local run_samba="$6" # IN
213 local ifNet
214
215 # Do a cursory check to see if the host-only network
216 # configuration is still ok. We do this so that mobile
217 # hosts don't get setup at install time and then moved to
218 # a new locale where the host-only network config is no
219 # longer valid.
220 #
221 # NB: This really needs to be done at power-on time when
222 # VM is configured to use host-only networking so that
223 # we aren't fooled by dynamic changes in the network.
224 #
225 # XXX ping takes 10 seconds to timeout if nobody answers
226 # that slows boot too much so we do this bit in the
227 # background.
efe88284 228 if "$VM_BINDIR"/"$ping" -q "$ifIp"; then
345c7964 229 echo 'Host-only networking disabled because '"$ifIp"
230 echo 'appears to be a real, physical, existing address.'
36b33dd9 231 echo 'Please modify your host-only network configuration.'
345c7964 232 exit 1
233 fi
efe88284 234 cd "$VM_BINDIR" && "$VM_BINDIR"/"$netifup" \
3e0d5b52 235 -d /var/run/"$netifup"-"$vHostIf".pid /dev/vmnet"$vHubNr" "$vHostIf"
345c7964 236 [ "$?" -eq 0 ] || exit 1
237 # Configure the virtual host ethernet interface and define the private IP
238 # network
239 #
240 # . We provide the broadcast address explicitly because versions of ifconfig
241 # prior to 1.39 (1999-03-18) seem to miscompute it
242 # . 2.0.x kernels don't install a route when the interface is marked up, but
243 # 2.2.x kernel do. Since we want to see any errors from route we don't
244 # just discard messages from route, but instead check if the route got
245 # installed before manually adding one.
246 ifNet=`ipv4_subnet "$ifIp" "$ifMask"`
3e0d5b52 247 if ifconfig "$vHostIf" inet "$ifIp" netmask "$ifMask" \
248 broadcast "`ipv4_broadcast "$ifIp" "$ifMask"`" up \
249 && noRoutePresent "$ifNet" "$vHostIf"; then
250 route add -net "$ifNet" netmask "$ifMask" "$vHostIf"
251 fi
252 if [ "$run_dhcpd" = 'yes' ]; then
253 # Start a DHCP server on a private IP network
254 # The daemon already logs its output in the system log, so we can safely
255 # trash it
256 cd "$VM_BINDIR" && "$VM_BINDIR"/"$dhcpd" \
257 -cf "$vmware_etc_dir"/"$vHostIf"/dhcpd/dhcpd.conf \
258 -lf "$vmware_etc_dir"/"$vHostIf"/dhcpd/dhcpd.leases \
259 -pf /var/run/"$dhcpd"-"$vHostIf".pid "$vHostIf" >/dev/null 2>&1 || exit 1
260 fi
261 if [ "$run_samba" = 'yes' ]; then
262 # Start a SMB name server on a private IP network
263 # Disable logging to avoid the uncontrolled creation of unmanaged files
264 cd "$VM_BINDIR" && "$VM_BINDIR"/"$nmbd" -D -l /dev/null \
265 -s "$vmware_etc_dir"/"$vHostIf"/smb/smb.conf \
266 -f /var/run/"$nmbd"-"$vHostIf".pid || exit 1
267 # Start a SMB share server on a private IP network
268 # Disable logging to avoid the uncontrolled creation of unmanaged files
269 cd "$VM_BINDIR" && "$VM_BINDIR"/"$smbd" -D -l /dev/null \
270 -s "$vmware_etc_dir"/"$vHostIf"/smb/smb.conf \
271 -f /var/run/"$smbd"-"$vHostIf".pid || exit 1
272 fi
29328d5b 273}
274
275# Stop the host-only network user service
276vmware_stop_hostonly() {
345c7964 277 local vHostIf="$1" # IN
278 local ifIp="$2" # IN
279 local ifMask="$3" # IN
280 local ifNet
281
282 # Terminate the private network
283 ifNet=`ipv4_subnet "$ifIp" "$ifMask"`
3e0d5b52 284 noRoutePresent "$ifNet" "$vHostIf" || route del -net "$ifNet" netmask "$ifMask" || exit 1
345c7964 285 # To test if the interface exists, we can not just look at the exitcode
286 # because old versions of ifconfig don't exit with 1 when invoked with a
287 # non-existing interface
288 if [ "`ifconfig "$vHostIf" 2>/dev/null`" != '' ]; then
289 ifconfig "$vHostIf" down || exit 1
290 fi
291 vmware_stop_pidfile /var/run/"$netifup"-"$vHostIf".pid || exit 1
29328d5b 292}
293
29328d5b 294# See how we were called.
295case "$1" in
296 start)
2e3c2f73 297 if [ -f /var/lock/subsys/"$subsys" ]; then
298 msg_already_running "VMware Workstation networking"
83ae92eb 299 fi
3e0d5b52 300 # Try to load parport_pc. Failure is allowed as it does not exist
301 # on kernels 2.0
302 /sbin/modprobe parport_pc >/dev/null 2>&1
d7b09803
JR
303 msg_starting 'Virtual machine monitor'
304 busy
305 /sbin/modprobe $driver
306 [ "$?" -eq "0" ] && ok || fail
2e3c2f73 307 if [ "$VM_NETWORKING" = 'yes' ]; then
a5a25ae1 308 msg_starting 'Virtual ethernet'
309 busy
345c7964 310 /sbin/modprobe $vnet
a5a25ae1 311 [ "$?" -eq 0 ] && ok || fail
a5a25ae1 312 vHubNr=0
bea3b8f8 313 while [ $vHubNr -lt 9 ]; do
3e0d5b52 314 eval 'interface="$VNET_'"$vHubNr"'_INTERFACE"'
315 eval 'hostaddr="$VNET_'"$vHubNr"'_HOSTONLY_HOSTADDR"'
316 eval 'netmask="$VNET_'"$vHubNr"'_HOSTONLY_NETMASK"'
a5a25ae1 317 if [ -n "$interface" ]; then
347c4848 318 vmware_create_vmnet "$vHubNr"
345c7964 319 # Connect a physical host ethernet interface to a virtual ethernet hub
3e0d5b52 320 msg_starting 'Bridged networking on /dev/vmnet'"$vHubNr"
a5a25ae1 321 busy
efe88284 322 cd "$VM_BINDIR" && "$VM_BINDIR"/"$bridge" \
3e0d5b52 323 -d /var/run/"$bridge"-"$vHubNr".pid /dev/vmnet"$vHubNr" "$interface"
a5a25ae1 324 [ "$?" -eq 0 ] && ok || fail
a5a25ae1 325 elif [ -n "$hostaddr" -a -n "$netmask" ]; then
347c4848 326 vmware_create_vmnet "$vHubNr"
2e3c2f73 327 eval 'samba="$VNET_'"$vHubNr"'_SAMBA"'
3e0d5b52 328 msg_starting 'Host-only networking on /dev/vmnet'"$vHubNr"
345c7964 329 busy
0e5e01f1 330 vmware_start_hostonly "$vHubNr" 'vmnet'"$vHubNr" "$hostaddr" \
3e0d5b52 331 "$netmask" 'yes' "$samba"
345c7964 332 [ "$?" -eq 0 ] && ok || fail
2e3c2f73 333 eval 'nat="$VNET_'"$vHubNr"'_NAT"'
3e0d5b52 334 if [ "$nat" = 'yes' ]; then
36b33dd9 335 # Start the NAT network user service
345c7964 336 msg_starting 'NAT networking on /dev/vmnet'"$vHubNr"
337 busy
efe88284 338 cd "$VM_BINDIR" && "$VM_BINDIR"/"$natd" \
3e0d5b52 339 -d /var/run/"$natd"-"$vHubNr".pid \
340 -m /var/run/"$natd"-"$vHubNr".mac \
bea3b8f8 341 -c "$vmware_etc_dir"/vmnet"$vHubNr"/nat/nat.conf >/dev/null 2>&1
345c7964 342 [ "$?" -eq 0 ] && ok || fail
3e0d5b52 343 fi
a5a25ae1 344 fi
3e0d5b52 345 vHubNr=$(($vHubNr + 1))
a5a25ae1 346 done
29328d5b 347 fi
29328d5b 348 touch /var/lock/subsys/"$subsys"
349 ;;
350
351 stop)
3e0d5b52 352 if [ "`countVMs`" -gt 0 ]; then
353 echo 'At least one instance of VMware Workstation is still running.'
36b33dd9 354 echo 'Please stop all running instances of VMware Workstation first.'
345c7964 355 echo
29328d5b 356 fi
2e3c2f73 357 if [ ! -f /var/lock/subsys/"$subsys" ]; then
358 msg_not_running "VMware Workstation networking"
83ae92eb 359 fi
3e0d5b52 360 # Try to unload parport_pc. Failure is allowed as it does not exist
361 # on kernels 2.0, and some other process could be using it.
362 /sbin/modprobe -r parport_pc >/dev/null 2>&1
2e3c2f73 363 if [ "$VM_NETWORKING" = "yes" ]; then
a5a25ae1 364 # NB: must kill off processes using vmnet before
365 # unloading module
366 vHubNr=0
bea3b8f8 367 while [ $vHubNr -lt 9 ]; do
3e0d5b52 368 eval 'interface="$VNET_'"$vHubNr"'_INTERFACE"'
369 eval 'hostaddr="$VNET_'"$vHubNr"'_HOSTONLY_HOSTADDR"'
370 eval 'netmask="$VNET_'"$vHubNr"'_HOSTONLY_NETMASK"'
a5a25ae1 371 if [ -n "$interface" ]; then
345c7964 372 # Disconnect a physical host ethernet interface from a virtual ethernet hub
3e0d5b52 373 msg_stopping "Bridged networking on /dev/vmnet$vHubNr"
a5a25ae1 374 busy
345c7964 375 vmware_stop_pidfile /var/run/"$bridge"-"$vHubNr".pid
a5a25ae1 376 [ "$?" -eq 0 ] && ok || fail
a5a25ae1 377 elif [ -n "$hostaddr" -a -n "$netmask" ]; then
36b33dd9 378 # Stop a DHCP server on a private IP network
345c7964 379 msg_stopping "DHCP server on /dev/vmnet$vHubNr"
380 busy
36b33dd9 381 vmware_stop_pidfile /var/run/"$dhcpd"-"vmnet$vHubNr".pid
345c7964 382 [ "$?" -eq 0 ] && ok || fail
2e3c2f73 383 eval 'samba="$VNET_'"$vHubNr"'_SAMBA"'
3e0d5b52 384 if [ "$samba" = "yes" ]; then
36b33dd9 385 # Stop a SMB share server on a private IP network
3e0d5b52 386 msg_stopping 'SMB share server on /dev/vmnet'"$vHubNr"
345c7964 387 busy
36b33dd9 388 vmware_stop_pidfile /var/run/"$smbd"-'vmnet'"$vHubNr".pid
345c7964 389 [ "$?" -eq 0 ] && ok || fail
36b33dd9 390 # Stop a SMB name server on a private IP network
3e0d5b52 391 msg_stopping 'SMB name server on /dev/vmnet'"$vHubNr"
345c7964 392 busy
36b33dd9 393 vmware_stop_pidfile /var/run/"$nmbd"-'vmnet'"$vHubNr".pid
345c7964 394 [ "$?" -eq 0 ] && ok || fail
a5a25ae1 395 fi
2e3c2f73 396 eval 'nat="$VNET_'"$vHubNr"'_NAT"'
3e0d5b52 397 if [ "$nat" = "yes" ]; then
398 # Stop the NAT network user service
399 msg_stopping 'NAT networking on /dev/vmnet'"$vHubNr"
345c7964 400 busy
3e0d5b52 401 vmware_stop_pidfile /var/run/"$natd"-"$vHubNr".pid
345c7964 402 [ "$?" -eq 0 ] && ok || fail
3e0d5b52 403 fi
404 msg_stopping 'Host-only networking on /dev/vmnet'"$vHubNr"
405 busy
406 vmware_stop_hostonly 'vmnet'"$vHubNr" "$hostaddr" "$netmask"
407 [ "$?" -eq 0 ] && ok || fail
a5a25ae1 408
409 fi
3e0d5b52 410 vHubNr=$(($vHubNr + 1))
a5a25ae1 411 done
c6254721 412 msg_stopping 'Virtual machine monitor'
413 busy
414 if /sbin/lsmod | grep -q ^"$driver"; then
415 /sbin/rmmod "$driver"
416 fi
417 [ "$?" -eq "0" ] && ok || fail
a5a25ae1 418 msg_stopping 'Virtual ethernet'
419 busy
36b33dd9 420 if /sbin/lsmod | grep -q ^"$vnet"; then
3e0d5b52 421 /sbin/rmmod "$vnet"
345c7964 422 fi
a5a25ae1 423 [ "$?" -eq "0" ] && ok || fail
3e0d5b52 424 fi
29328d5b 425 rm -f /var/lock/subsys/"$subsys"
426 ;;
29328d5b 427 status)
3e0d5b52 428 if [ "`countVMs`" -gt 0 ]; then
429 echo 'At least one instance of VMware Workstation is still running.'
430 echo
29328d5b 431 fi
2e3c2f73 432 if [ "$VM_NETWORKING" = "yes" ]; then
3e0d5b52 433 status "$bridge"
434 status "$dhcpd"
435 status "$netifup"
436 fi
2e3c2f73 437 if [ "$VM_NETWORKING" = "yes" ]; then
3e0d5b52 438 echo -n "Module $vnet "
439 /sbin/modprobe "$vnet" >/dev/null 2>&1 && echo installed || echo "not installed"
440 fi
29328d5b 441 ;;
29328d5b 442 restart)
443 "$0" stop && "$0" start
444 ;;
29328d5b 445 *)
446 echo "Usage: `basename "$0"` {start|stop|status|restart}"
3e0d5b52 447 exit 3
29328d5b 448esac
449
450exit 0
This page took 0.145475 seconds and 4 git commands to generate.