]> git.pld-linux.org Git - packages/VMware-workstation.git/blame - VMware-workstation.init
- updated to 5.0.0
[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
35 else
36 echo "FATAL: Unable to read $f"
37 exit 1
38 fi
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}
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"
2e3c2f73 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
2e3c2f73 303 if [ "$VM_NETWORKING" = 'yes' ]; then
a5a25ae1 304 msg_starting 'Virtual ethernet'
305 busy
345c7964 306 /sbin/modprobe $vnet
a5a25ae1 307 [ "$?" -eq 0 ] && ok || fail
a5a25ae1 308 vHubNr=0
bea3b8f8 309 while [ $vHubNr -lt 9 ]; do
3e0d5b52 310 eval 'interface="$VNET_'"$vHubNr"'_INTERFACE"'
311 eval 'hostaddr="$VNET_'"$vHubNr"'_HOSTONLY_HOSTADDR"'
312 eval 'netmask="$VNET_'"$vHubNr"'_HOSTONLY_NETMASK"'
a5a25ae1 313 if [ -n "$interface" ]; then
347c4848 314 vmware_create_vmnet "$vHubNr"
345c7964 315 # Connect a physical host ethernet interface to a virtual ethernet hub
3e0d5b52 316 msg_starting 'Bridged networking on /dev/vmnet'"$vHubNr"
a5a25ae1 317 busy
efe88284 318 cd "$VM_BINDIR" && "$VM_BINDIR"/"$bridge" \
3e0d5b52 319 -d /var/run/"$bridge"-"$vHubNr".pid /dev/vmnet"$vHubNr" "$interface"
a5a25ae1 320 [ "$?" -eq 0 ] && ok || fail
a5a25ae1 321 elif [ -n "$hostaddr" -a -n "$netmask" ]; then
347c4848 322 vmware_create_vmnet "$vHubNr"
2e3c2f73 323 eval 'samba="$VNET_'"$vHubNr"'_SAMBA"'
3e0d5b52 324 msg_starting 'Host-only networking on /dev/vmnet'"$vHubNr"
345c7964 325 busy
0e5e01f1 326 vmware_start_hostonly "$vHubNr" 'vmnet'"$vHubNr" "$hostaddr" \
3e0d5b52 327 "$netmask" 'yes' "$samba"
345c7964 328 [ "$?" -eq 0 ] && ok || fail
2e3c2f73 329 eval 'nat="$VNET_'"$vHubNr"'_NAT"'
3e0d5b52 330 if [ "$nat" = 'yes' ]; then
36b33dd9 331 # Start the NAT network user service
345c7964 332 msg_starting 'NAT networking on /dev/vmnet'"$vHubNr"
333 busy
efe88284 334 cd "$VM_BINDIR" && "$VM_BINDIR"/"$natd" \
3e0d5b52 335 -d /var/run/"$natd"-"$vHubNr".pid \
336 -m /var/run/"$natd"-"$vHubNr".mac \
bea3b8f8 337 -c "$vmware_etc_dir"/vmnet"$vHubNr"/nat/nat.conf >/dev/null 2>&1
345c7964 338 [ "$?" -eq 0 ] && ok || fail
3e0d5b52 339 fi
a5a25ae1 340 fi
3e0d5b52 341 vHubNr=$(($vHubNr + 1))
a5a25ae1 342 done
29328d5b 343 fi
29328d5b 344 touch /var/lock/subsys/"$subsys"
345 ;;
346
347 stop)
3e0d5b52 348 if [ "`countVMs`" -gt 0 ]; then
349 echo 'At least one instance of VMware Workstation is still running.'
36b33dd9 350 echo 'Please stop all running instances of VMware Workstation first.'
345c7964 351 echo
29328d5b 352 fi
2e3c2f73 353 if [ ! -f /var/lock/subsys/"$subsys" ]; then
354 msg_not_running "VMware Workstation networking"
2e3c2f73 355 fi
3e0d5b52 356 # Try to unload parport_pc. Failure is allowed as it does not exist
357 # on kernels 2.0, and some other process could be using it.
358 /sbin/modprobe -r parport_pc >/dev/null 2>&1
2e3c2f73 359 if [ "$VM_NETWORKING" = "yes" ]; then
a5a25ae1 360 # NB: must kill off processes using vmnet before
361 # unloading module
362 vHubNr=0
bea3b8f8 363 while [ $vHubNr -lt 9 ]; do
3e0d5b52 364 eval 'interface="$VNET_'"$vHubNr"'_INTERFACE"'
365 eval 'hostaddr="$VNET_'"$vHubNr"'_HOSTONLY_HOSTADDR"'
366 eval 'netmask="$VNET_'"$vHubNr"'_HOSTONLY_NETMASK"'
a5a25ae1 367 if [ -n "$interface" ]; then
345c7964 368 # Disconnect a physical host ethernet interface from a virtual ethernet hub
3e0d5b52 369 msg_stopping "Bridged networking on /dev/vmnet$vHubNr"
a5a25ae1 370 busy
345c7964 371 vmware_stop_pidfile /var/run/"$bridge"-"$vHubNr".pid
a5a25ae1 372 [ "$?" -eq 0 ] && ok || fail
a5a25ae1 373 elif [ -n "$hostaddr" -a -n "$netmask" ]; then
36b33dd9 374 # Stop a DHCP server on a private IP network
345c7964 375 msg_stopping "DHCP server on /dev/vmnet$vHubNr"
376 busy
36b33dd9 377 vmware_stop_pidfile /var/run/"$dhcpd"-"vmnet$vHubNr".pid
345c7964 378 [ "$?" -eq 0 ] && ok || fail
2e3c2f73 379 eval 'samba="$VNET_'"$vHubNr"'_SAMBA"'
3e0d5b52 380 if [ "$samba" = "yes" ]; then
36b33dd9 381 # Stop a SMB share server on a private IP network
3e0d5b52 382 msg_stopping 'SMB share server on /dev/vmnet'"$vHubNr"
345c7964 383 busy
36b33dd9 384 vmware_stop_pidfile /var/run/"$smbd"-'vmnet'"$vHubNr".pid
345c7964 385 [ "$?" -eq 0 ] && ok || fail
36b33dd9 386 # Stop a SMB name server on a private IP network
3e0d5b52 387 msg_stopping 'SMB name server on /dev/vmnet'"$vHubNr"
345c7964 388 busy
36b33dd9 389 vmware_stop_pidfile /var/run/"$nmbd"-'vmnet'"$vHubNr".pid
345c7964 390 [ "$?" -eq 0 ] && ok || fail
a5a25ae1 391 fi
2e3c2f73 392 eval 'nat="$VNET_'"$vHubNr"'_NAT"'
3e0d5b52 393 if [ "$nat" = "yes" ]; then
394 # Stop the NAT network user service
395 msg_stopping 'NAT networking on /dev/vmnet'"$vHubNr"
345c7964 396 busy
3e0d5b52 397 vmware_stop_pidfile /var/run/"$natd"-"$vHubNr".pid
345c7964 398 [ "$?" -eq 0 ] && ok || fail
3e0d5b52 399 fi
400 msg_stopping 'Host-only networking on /dev/vmnet'"$vHubNr"
401 busy
402 vmware_stop_hostonly 'vmnet'"$vHubNr" "$hostaddr" "$netmask"
403 [ "$?" -eq 0 ] && ok || fail
a5a25ae1 404
405 fi
3e0d5b52 406 vHubNr=$(($vHubNr + 1))
a5a25ae1 407 done
c6254721 408 msg_stopping 'Virtual machine monitor'
409 busy
410 if /sbin/lsmod | grep -q ^"$driver"; then
411 /sbin/rmmod "$driver"
412 fi
413 [ "$?" -eq "0" ] && ok || fail
a5a25ae1 414 msg_stopping 'Virtual ethernet'
415 busy
36b33dd9 416 if /sbin/lsmod | grep -q ^"$vnet"; then
3e0d5b52 417 /sbin/rmmod "$vnet"
345c7964 418 fi
a5a25ae1 419 [ "$?" -eq "0" ] && ok || fail
3e0d5b52 420 fi
29328d5b 421 rm -f /var/lock/subsys/"$subsys"
422 ;;
29328d5b 423 status)
3e0d5b52 424 if [ "`countVMs`" -gt 0 ]; then
425 echo 'At least one instance of VMware Workstation is still running.'
426 echo
29328d5b 427 fi
2e3c2f73 428 if [ "$VM_NETWORKING" = "yes" ]; then
3e0d5b52 429 status "$bridge"
430 status "$dhcpd"
431 status "$netifup"
432 fi
2e3c2f73 433 if [ "$VM_NETWORKING" = "yes" ]; then
3e0d5b52 434 echo -n "Module $vnet "
435 /sbin/modprobe "$vnet" >/dev/null 2>&1 && echo installed || echo "not installed"
436 fi
29328d5b 437 ;;
29328d5b 438 restart)
439 "$0" stop && "$0" start
440 ;;
29328d5b 441 *)
442 echo "Usage: `basename "$0"` {start|stop|status|restart}"
3e0d5b52 443 exit 3
29328d5b 444esac
445
446exit 0
This page took 0.132088 seconds and 4 git commands to generate.