]> git.pld-linux.org Git - packages/VMware-workstation.git/blob - VMware-workstation.init
b020b08d5343d38187ecaa2439107ee8f077aac3
[packages/VMware-workstation.git] / VMware-workstation.init
1 #!/bin/sh
2 #
3 # Copyright 1998 VMware, Inc.  All rights reserved.
4 #
5
6 # vmware:       Manages the services needed to run VMware software
7 #
8 # description:  Manages the services needed to run VMware software
9 #
10 # chkconfig:    5 90 8
11 #
12 # probe:        true
13 # hide:         true
14
15
16 . /etc/rc.d/init.d/functions
17
18 #
19 # Create a temporary directory
20 #
21
22 # They are a lot of small utility programs to create temporary files in a
23 # secure way, but none of them is standard. So I wrote this --hpreg
24 make_tmp_dir() {
25   local dirname="$1" # OUT
26   local prefix="$2"  # IN
27   local tmp
28   local serial
29   local loop
30
31   tmp="${TMPDIR:-/tmp}"
32
33   # Don't overwrite existing user data
34   # -> Create a directory with a name that didn't exist before
35   #
36   # This may never succeed (if we are racing with a malicious process), but at
37   # least it is secure
38   serial=0
39   loop='yes'
40   while [ "$loop" = 'yes' ]; do
41     # Check the validity of the temporary directory. We do this in the loop
42     # because it can change over time
43     if [ ! -d "$tmp" ]; then
44       echo 'Error: "'"$tmp"'" is not a directory.'
45       echo
46       exit 1
47     fi
48     if [ ! -w "$tmp" -o ! -x "$tmp" ]; then
49       echo 'Error: "'"$tmp"'" should be writable and executable.'
50       echo
51       exit 1
52     fi
53
54     # Be secure
55     # -> Don't give write access to other users (so that they can not use this
56     # directory to launch a symlink attack)
57     if mkdir -m 0755 "$tmp"'/'"$prefix$serial" >/dev/null 2>&1; then
58       loop='no'
59     else
60       serial=`expr "$serial" + 1`
61       if [ "`expr "$serial" % 200`" = '0' ]; then
62         echo 'Warning: The "'"$tmp"'" directory may be under attack.'
63         echo
64       fi
65     fi
66   done
67
68   eval "$dirname"'="$tmp"'"'"'/'"'"'"$prefix$serial"'
69 }
70
71 # END_OF_TMPDIR_DOT_SH
72
73 vmware_etc_dir=/etc/vmware
74
75 #
76 # From now on, this is a normal startup script. I swear.
77 #
78
79 # Since this script is installed, our main database should be installed too and
80 # should contain the basic information
81 vmware_db="$vmware_etc_dir"/locations
82 if [ ! -r "$vmware_db" ]; then
83     echo 'Warning: Unable to find '"`vmware_product_name`""'"'s main database '"$vmware_db"'.'
84     echo            
85     
86     exit 1
87 fi
88
89 # BEGINNING_OF_DB_DOT_SH
90
91 #
92 # Manage an installer database
93 #
94
95 # Add an answer to a database in memory
96 db_answer_add() {
97   local dbvar="$1" # IN/OUT
98   local id="$2"    # IN
99   local value="$3" # IN
100   local answers
101   local i
102
103   eval "$dbvar"'_answer_'"$id"'="$value"'
104
105   eval 'answers="$'"$dbvar"'_answers"'
106   # There is no double quote around $answers on purpose
107   for i in $answers; do
108     if [ "$i" = "$id" ]; then
109       return
110     fi
111   done
112   answers="$answers"' '"$id"
113   eval "$dbvar"'_answers="$answers"'
114 }
115
116 # Remove an answer from a database in memory
117 db_answer_remove() {
118   local dbvar="$1" # IN/OUT
119   local id="$2"    # IN
120   local new_answers
121   local answers
122   local i
123
124   eval 'unset '"$dbvar"'_answer_'"$id"
125
126   new_answers=''
127   eval 'answers="$'"$dbvar"'_answers"'
128   # There is no double quote around $answers on purpose
129   for i in $answers; do
130     if [ "$i" != "$id" ]; then
131       new_answers="$new_answers"' '"$i"
132     fi
133   done
134   eval "$dbvar"'_answers="$new_answers"'
135 }
136
137 # Load all answers from a database on stdin to memory (<dbvar>_answer_*
138 # variables)
139 db_load_from_stdin() {
140   local dbvar="$1" # OUT
141
142   eval "$dbvar"'_answers=""'
143
144 # read doesn't support -r on FreeBSD 3.x.
145 # For this reason, the folowing line is patched to remove the -r in case of 
146 # Free BSD tools build. Please look at
147 # bora-vmsoft/install/FreeBSD/tools-tar.make before making drastic changes to
148 # the folowing line.
149 # -- Jeremy Bar
150   while read -r action p1 p2; do
151     if [ "$action" = 'answer' ]; then
152       db_answer_add "$dbvar" "$p1" "$p2"
153     elif [ "$action" = 'remove_answer' ]; then
154       db_answer_remove "$dbvar" "$p1"
155     fi
156   done
157 }
158
159 # Load all answers from a database on disk to memory (<dbvar>_answer_*
160 # variables)
161 db_load() {
162   local dbvar="$1"  # OUT
163   local dbfile="$2" # IN
164
165   db_load_from_stdin "$dbvar" < "$dbfile"
166 }
167
168 # Iterate through all answers in a database in memory, calling <func> with
169 # id/value pairs and the remaining arguments to this function
170 db_iterate() {
171   local dbvar="$1" # IN
172   local func="$2"  # IN
173   shift 2
174   local answers
175   local i
176   local value
177
178   eval 'answers="$'"$dbvar"'_answers"'
179   # There is no double quote around $answers on purpose
180   for i in $answers; do
181     eval 'value="$'"$dbvar"'_answer_'"$i"'"'
182     "$func" "$i" "$value" "$@"
183   done
184 }
185
186 # If it exists in memory, remove an answer from a database (disk and memory)
187 db_remove_answer() {
188   local dbvar="$1"  # IN/OUT
189   local dbfile="$2" # IN
190   local id="$3"     # IN
191   local answers
192   local i
193
194   eval 'answers="$'"$dbvar"'_answers"'
195   # There is no double quote around $answers on purpose
196   for i in $answers; do
197     if [ "$i" = "$id" ]; then
198       echo 'remove_answer '"$id" >> "$dbfile"
199       db_answer_remove "$dbvar" "$id"
200       return
201     fi
202   done
203 }
204
205 # Add an answer to a database (disk and memory)
206 db_add_answer() {
207   local dbvar="$1"  # IN/OUT
208   local dbfile="$2" # IN
209   local id="$3"     # IN
210   local value="$4"  # IN
211
212   db_remove_answer "$dbvar" "$dbfile" "$id"
213   echo 'answer '"$id"' '"$value" >> "$dbfile"
214   db_answer_add "$dbvar" "$id" "$value"
215 }
216
217 # Add a file to a database on disk
218 # 'file' is the file to put in the database (it may not exist on the disk)
219 # 'tsfile' is the file to get the timestamp from, '' if no timestamp
220 db_add_file() {
221   local dbfile="$1" # IN
222   local file="$2"   # IN
223   local tsfile="$3" # IN
224   local date
225
226   if [ "$tsfile" = '' ]; then
227     echo 'file '"$file" >> "$dbfile"
228   else
229     date=`date -r "$tsfile" '+%s' 2> /dev/null`
230     if [ "$date" != '' ]; then
231       date=' '"$date"
232     fi
233     echo 'file '"$file$date" >> "$dbfile"
234   fi
235 }
236
237 # Add a directory to a database on disk
238 db_add_dir() {
239   local dbfile="$1" # IN
240   local dir="$2"    # IN
241
242   echo 'directory '"$dir" >> "$dbfile"
243 }
244 # END_OF_DB_DOT_SH
245
246 db_load 'vmdb' "$vmware_db"
247
248 # This comment is a hack to prevent RedHat distributions from outputing
249 # "Starting <basename of this script>" when running this startup script.
250 # We just need to write the word daemon followed by a space --hpreg.
251
252 # This defines echo_success() and echo_failure() on RedHat
253 if [ -r "$vmdb_answer_INITSCRIPTSDIR"'/functions' ]; then
254     . "$vmdb_answer_INITSCRIPTSDIR"'/functions'
255 fi
256
257 # This defines $rc_done and $rc_failed on S.u.S.E.
258 if [ -f /etc/rc.config ]; then
259    # Don't include the entire file: there could be conflicts
260    rc_done=`(. /etc/rc.config; echo "$rc_done")`
261    rc_failed=`(. /etc/rc.config; echo "$rc_failed")`
262 else
263    # Make sure the ESC byte is literal: Ash does not support echo -e
264    rc_done='\e[71G done'
265    rc_failed='\e[71Gfailed'
266 fi
267
268 subsys=vmware
269 driver=vmmon
270 ppuser=vmppuser
271 vnet=vmnet
272 bridge=vmnet-bridge
273 dhcpd=vmnet-dhcpd
274 netifup=vmnet-netifup
275 natd=vmnet-natd
276 ping=vmware-ping
277 smbd=vmware-smbd
278 nmbd=vmware-nmbd
279
280 #
281 # Utilities
282 #
283
284 # BEGINNING_OF_IPV4_DOT_SH
285
286 #
287 # IPv4 address functions
288 #
289 # Thanks to Owen DeLong <owen@delong.com> for pointing me at bash's arithmetic
290 # expansion ability, which is a lot faster than using 'expr' --hpreg
291 #
292
293 # Compute the subnet address associated to a couple IP/netmask
294 ipv4_subnet() {
295   local ip="$1"
296   local netmask="$2"
297
298   # Split quad-dotted addresses into bytes
299   # There is no double quote around the back-quoted expression on purpose
300   # There is no double quote around $ip and $netmask on purpose
301   set -- `IFS='.'; echo $ip $netmask`
302
303   echo $(($1 & $5)).$(($2 & $6)).$(($3 & $7)).$(($4 & $8))
304 }
305
306 # Compute the broadcast address associated to a couple IP/netmask
307 ipv4_broadcast() {
308   local ip="$1"
309   local netmask="$2"
310
311   # Split quad-dotted addresses into bytes
312   # There is no double quote around the back-quoted expression on purpose
313   # There is no double quote around $ip and $netmask on purpose
314   set -- `IFS='.'; echo $ip $netmask`
315
316   echo $(($1 | (255 - $5))).$(($2 | (255 - $6))).$(($3 | (255 - $7))).$(($4 | (255 - $8)))
317 }
318
319 # END_OF_IPV4_DOT_SH
320
321 # Are we running in a VM?
322 vmware_inVM() {
323   "$vmware_etc_dir"/checkvm >/dev/null 2>&1
324 }
325
326 # This is a function in case a future product name contains language-specific
327 # escape characters.
328 vmware_product_name() {
329   echo 'VMware Workstation'
330   exit 0
331 }
332
333
334 #
335 # Count the number of running virtual machines
336 # by looking at the number of references to the
337 # $driver module.
338 #
339 countVMs() {
340     # Beware of module dependancies here. An exact match is important
341     /sbin/lsmod | awk 'BEGIN {n = 0;} {if ($1 == "'"$driver"'") n = $3;} END {print n;}'
342 }
343
344 # Is a given module loaded?
345 isLoaded() {
346   local module="$1"
347
348   /sbin/lsmod | awk 'BEGIN {n = "no";} {if ($1 == "'"$module"'") n = "yes";} END {print n;}'
349 }
350
351 # Check if there is an IP route for a given subnet via a given interface
352 # Return true if there is _NO_ such route
353 noRoutePresent() {
354   local subnet="$1" # IN
355   local intf="$2"   # IN
356
357   # Beware, there may be several identical routes
358   [ "`/sbin/route -n | grep '^'"$subnet"'.*'"$intf"'$'`" = '' ]
359 }
360
361 #
362 # Check that the IP address we are going to assign to the host machine on
363 # a private IP network does not already exist
364 #
365 # NB: If you don't want to do this test, just substitute
366 #     false for it.
367 #
368 lookForHostOnlyNetwork() {
369   local ip="$1"
370
371   "$vmdb_answer_BINDIR"/"$ping" -q "$ip"
372 }
373
374 # Build a Linux kernel integer version
375 kernel_version_integer() {
376   echo $(((($1 * 256) + $2) * 256 + $3))
377 }
378
379 # Get the running kernel integer version
380 get_version_integer() {
381   local version_uts
382   local v1
383   local v2
384   local v3
385
386   version_uts=`uname -r`
387
388   # There is no double quote around the back-quoted expression on purpose
389   # There is no double quote around $version_uts on purpose
390   set -- `IFS='.'; echo $version_uts`
391   v1="$1"
392   v2="$2"
393   v3="$3"
394   # There is no double quote around the back-quoted expression on purpose
395   # There is no double quote around $v3 on purpose
396   set -- `IFS='-ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz'; echo $v3`
397   v3="$1"
398
399   kernel_version_integer "$v1" "$v2" "$v3"
400 }
401
402 # Do we need the ppuser module?
403 isPpuserNeeded() {
404   local version_integer
405
406   version_integer=`get_version_integer`
407   echo $(((`kernel_version_integer '2' '1' '127'` <= $version_integer) && ($version_integer <= `kernel_version_integer '2' '3' '9'`)))
408 }
409
410 vmware_failed() {
411   if [ "`type -t 'echo_failure' 2>/dev/null`" = 'function' ]; then
412     echo_failure
413   else
414     echo -n "$rc_failed"
415   fi
416 }
417
418 vmware_success() {
419   if [ "`type -t 'echo_success' 2>/dev/null`" = 'function' ]; then
420     echo_success
421   else
422     echo -n "$rc_done"
423   fi
424 }
425
426 # Execute a macro
427 vmware_exec() {
428   local msg="$1"  # IN
429   local func="$2" # IN
430   shift 2
431
432   echo -n '   '"$msg"
433
434   # On Caldera 2.2, SIGHUP is sent to all our children when this script exits
435   # I wanted to use shopt -u huponexit instead but their bash version
436   # 1.14.7(1) is too old
437   #
438   # Ksh does not recognize the SIG prefix in front of a signal name
439   if [ "$VMWARE_DEBUG" = 'yes' ]; then
440     (trap '' HUP; "$func" "$@")
441   else
442     (trap '' HUP; "$func" "$@") >/dev/null 2>&1
443   fi
444   if [ "$?" -gt 0 ]; then
445     vmware_failed
446     echo
447     return 1
448   fi
449
450   vmware_success
451   echo
452   return 0
453 }
454
455 # Execute a macro in the background
456 vmware_bg_exec() {
457   local msg="$1"  # IN
458   local func="$2" # IN
459   shift 2
460
461   if [ "$VMWARE_DEBUG" = 'yes' ]; then
462     # Force synchronism when debugging
463     vmware_exec "$msg" "$func" "$@"
464   else
465     echo -n '   '"$msg"' (background)'
466
467     # On Caldera 2.2, SIGHUP is sent to all our children when this script exits
468     # I wanted to use shopt -u huponexit instead but their bash version
469     # 1.14.7(1) is too old
470     #
471     # Ksh does not recognize the SIG prefix in front of a signal name
472     (trap '' HUP; "$func" "$@") 2>&1 | logger -t 'VMware[init]' -p daemon.err &
473
474     vmware_success
475     echo
476     return 0
477   fi
478 }
479
480 #
481 # Macro definitions
482 #
483 # Note:
484 #  . Each daemon must be started from its own directory to avoid busy devices
485 #  . Each PID file doesn't need to be added to the installer database, because
486 #    it is going to be automatically removed when it becomes stale (after a
487 #    reboot). It must go directly under /var/run, or some distributions
488 #    (RedHat 6.0) won't clean it
489 #
490
491 # Terminate a process synchronously
492 vmware_synchrone_kill() {
493   local pid="$1"    # IN
494   local signal="$2" # IN
495   local second
496
497   kill -"$signal" "$pid"
498
499   # Wait a bit to see if the dirty job has really been done
500   for second in 0 1 2 3 4 5 6 7 8 9 10; do
501     if [ ! -d /proc/"$pid" ]; then
502       # Success
503       return 0
504     fi
505
506     sleep 1
507   done
508
509   # Timeout
510   return 1
511 }
512
513 # Kill the process associated to a pidfile
514 vmware_stop_pidfile() {
515   local pidfile="$1" # IN
516   local pid
517
518   pid=`cat "$pidfile" 2>/dev/null`
519   if [ "$pid" = '' ]; then
520     # The file probably does not exist or is empty. Success
521     return 0
522   fi
523   # Keep only the first number we find, because some Samba pid files are really
524   # trashy: they end with NUL characters
525   # There is no double quote around $pid on purpose
526   set -- $pid
527   pid="$1"
528
529   # First try a nice SIGTERM
530   if vmware_synchrone_kill "$pid" 15; then
531     return 0
532   fi
533
534   # Then send a strong SIGKILL
535   if vmware_synchrone_kill "$pid" 9; then
536     return 0
537   fi
538
539   return 1
540 }
541
542 vmware_load_module() {
543 #   /sbin/insmod -s -f "/lib/modules/`uname -r`/misc/$1.o" || exit 1
544         /sbin/modprobe $1 || exit 1
545 #       exit 0
546 }
547
548 vmware_unload_module() {
549    if [ "`isLoaded "$1"`" = 'yes' ]; then
550       /sbin/rmmod "$1" || exit 1
551    fi
552    exit 0
553 }
554
555 # Start the virtual machine monitor kernel service
556 vmware_start_vmmon() {
557    vmware_load_module $driver
558 }
559
560 # Stop the virtual machine monitor kernel service
561 vmware_stop_vmmon() {
562   vmware_unload_module $driver
563 }
564
565 # Start the virtual machine parallel port kernel service
566 vmware_start_vmppuser() {
567    if ! grep -q ' parport_release[^'$'\t'']*$' /proc/ksyms; then
568      # parport support is not built in the kernel
569      /sbin/modprobe parport || exit 1
570    fi
571    if ! grep -q ' parport_pc_[^'$'\t'']*$' /proc/ksyms; then
572      # parport_pc support is not built in the kernel
573      /sbin/modprobe parport_pc || exit 1
574    fi
575    vmware_load_module $ppuser
576 }
577
578 # Stop the virtual machine parallel port kernel service
579 vmware_stop_vmppuser() {
580   if [ "`isLoaded "$ppuser"`" = 'yes' ]; then
581     /sbin/rmmod "$ppuser" || exit 1
582   fi
583   # Try to unload the modules. Failure is allowed because some other process
584   # could be using them.
585   /sbin/modprobe -r parport_pc
586   /sbin/modprobe -r parport
587
588   # Return the right exitcode even if the previous commands failed
589   exit 0
590 }
591
592 # Start the virtual ethernet kernel service
593 vmware_start_vmnet() {
594   vmware_load_module $vnet
595 }
596
597 # Stop the virtual ethernet kernel service
598 vmware_stop_vmnet() {
599   vmware_unload_module $vnet
600 }
601
602 # Create a virtual host ethernet interface and connect it to a virtual
603 # ethernet hub
604 vmware_start_netifup() {
605   local vHostIf="$1" # IN
606   local vHubNr="$2"  # IN
607
608   cd "$vmdb_answer_BINDIR" && "$vmdb_answer_BINDIR"/"$netifup" \
609     -d /var/run/"$netifup"-"$vHostIf".pid /dev/vmnet"$vHubNr" "$vHostIf"
610 }
611
612 # Disconnect a virtual host ethernet interface from a virtual ethernet hub
613 # and destroy the virtual host ethernet interface
614 vmware_stop_netifup() {
615   local vHostIf="$1" # IN
616   
617   vmware_stop_pidfile /var/run/"$netifup"-"$vHostIf".pid
618 }
619
620 # Connect a physical host ethernet interface to a virtual ethernet hub
621 vmware_start_bridge() {
622   local vHubNr="$1"  # IN
623   local pHostIf="$2" # IN
624
625   cd "$vmdb_answer_BINDIR" && "$vmdb_answer_BINDIR"/"$bridge" \
626     -d /var/run/"$bridge"-"$vHubNr".pid /dev/vmnet"$vHubNr" "$pHostIf"
627 }
628
629 # Disconnect a physical host ethernet interface from a virtual ethernet hub
630 vmware_stop_bridge() {
631   local vHubNr="$1"  # IN
632
633   vmware_stop_pidfile /var/run/"$bridge"-"$vHubNr".pid
634 }
635
636 # Start a SMB name server on a private IP network
637 vmware_start_nmbd() {
638   local vHostIf="$1" # IN
639
640   # Disable logging to avoid the uncontrolled creation of unmanaged files
641   cd "$vmdb_answer_BINDIR" && "$vmdb_answer_BINDIR"/"$nmbd" -D -l /dev/null \
642     -s "$vmware_etc_dir"/"$vHostIf"/smb/smb.conf \
643     -f /var/run/"$nmbd"-"$vHostIf".pid
644 }
645
646 # Stop a SMB name server on a private IP network
647 vmware_stop_nmbd() {
648   local vHostIf="$1" # IN
649   
650   vmware_stop_pidfile /var/run/"$nmbd"-"$vHostIf".pid
651 }
652
653 # Start a SMB share server on a private IP network
654 vmware_start_smbd() {
655   local vHostIf="$1" # IN
656
657   # Disable logging to avoid the uncontrolled creation of unmanaged files
658   cd "$vmdb_answer_BINDIR" && "$vmdb_answer_BINDIR"/"$smbd" -D -l /dev/null \
659     -s "$vmware_etc_dir"/"$vHostIf"/smb/smb.conf \
660     -f /var/run/"$smbd"-"$vHostIf".pid
661 }
662
663 # Stop a SMB share server on a private IP network
664 vmware_stop_smbd() {
665   local vHostIf="$1" # IN
666   
667   vmware_stop_pidfile /var/run/"$smbd"-"$vHostIf".pid
668 }
669
670 # Start a DHCP server on a private IP network
671 vmware_start_dhcpd() {
672   local vHostIf="$1" # IN
673   
674   # The daemon already logs its output in the system log, so we can safely
675   # trash it
676   cd "$vmdb_answer_BINDIR" && "$vmdb_answer_BINDIR"/"$dhcpd" \
677     -cf "$vmware_etc_dir"/"$vHostIf"/dhcpd/dhcpd.conf \
678     -lf "$vmware_etc_dir"/"$vHostIf"/dhcpd/dhcpd.leases \
679     -pf /var/run/"$dhcpd"-"$vHostIf".pid "$vHostIf" >/dev/null 2>&1
680 }
681
682 # Stop a DHCP server on a private IP network
683 vmware_stop_dhcpd() {
684   local vHostIf="$1" # IN
685   
686   vmware_stop_pidfile /var/run/"$dhcpd"-"$vHostIf".pid
687 }
688
689 # Start the host-only network user service
690 vmware_start_hostonly() {
691   local vHubNr="$1"    # IN
692   local vHostIf="$2"   # IN
693   local ifIp="$3"      # IN
694   local ifMask="$4"    # IN
695   local run_dhcpd="$5" # IN
696   local run_samba="$6" # IN
697   local ifNet
698
699   #
700   # Do a cursory check to see if the host-only network
701   # configuration is still ok.  We do this so that mobile
702   # hosts don't get setup at install time and then moved to
703   # a new locale where the host-only network config is no
704   # longer valid.
705   #
706   # NB: This really needs to be done at power-on time when
707   #     VM is configured to use host-only networking so that
708   #     we aren't fooled by dynamic changes in the network.
709   #
710   # XXX ping takes 10 seconds to timeout if nobody answers
711   #     that slows boot too much so we do this bit in the
712   #     background.
713   #
714   if lookForHostOnlyNetwork "$ifIp"; then
715     echo 'Host-only networking disabled because '"$ifIp"
716     echo 'appears to be a real, physical, existing address.'
717     echo 'Please run "'"$vmdb_answer_BINDIR"'/vmware-config.pl" to'
718     echo 'modify your host-only network configuration.'
719     exit 1
720   fi
721
722   vmware_start_netifup "$vHostIf" "$vHubNr" || exit 1
723
724   # Configure the virtual host ethernet interface and define the private IP
725   # network
726   #
727   # . We provide the broadcast address explicitly because versions of ifconfig
728   #   prior to 1.39 (1999-03-18) seem to miscompute it
729   # . 2.0.x kernels don't install a route when the interface is marked up, but
730   #   2.2.x kernel do. Since we want to see any errors from route we don't
731   #   just discard messages from route, but instead check if the route got
732   #   installed before manually adding one.
733   ifNet=`ipv4_subnet "$ifIp" "$ifMask"`
734   if    ifconfig "$vHostIf" inet "$ifIp" netmask "$ifMask" \
735           broadcast "`ipv4_broadcast "$ifIp" "$ifMask"`" up \
736      && noRoutePresent "$ifNet" "$vHostIf"; then
737      route add -net "$ifNet" netmask "$ifMask" "$vHostIf"
738   fi
739
740   if [ "$run_dhcpd" = 'yes' ]; then
741     vmware_start_dhcpd "$vHostIf" || exit 1
742   fi
743
744   if [ "$run_samba" = 'yes' ]; then
745     vmware_start_nmbd "$vHostIf" || exit 1
746     vmware_start_smbd "$vHostIf" || exit 1
747   fi
748
749   exit 0
750 }
751
752 # Stop the host-only network user service
753 vmware_stop_hostonly() {
754   local vHostIf="$1"   # IN
755   local ifIp="$2"      # IN
756   local ifMask="$3"    # IN
757   local ifNet
758
759   # Terminate the private network
760   ifNet=`ipv4_subnet "$ifIp" "$ifMask"`
761      noRoutePresent "$ifNet" "$vHostIf" \
762   || route del -net "$ifNet" netmask "$ifMask" || exit 1
763   # To test if the interface exists, we can not just look at the exitcode
764   # because old versions of ifconfig don't exit with 1 when invoked with a
765   # non-existing interface
766   if [ "`ifconfig "$vHostIf" 2>/dev/null`" != '' ]; then
767     ifconfig "$vHostIf" down || exit 1
768   fi
769
770   vmware_stop_netifup "$vHostIf" || exit 1
771
772   exit 0
773 }
774
775 # Start the NAT network user service
776 vmware_start_nat() {
777   local vHubNr="$1"    # IN
778
779   cd "$vmdb_answer_BINDIR" && "$vmdb_answer_BINDIR"/"$natd" \
780     -d /var/run/"$natd"-"$vHubNr".pid \
781     -m /var/run/"$natd"-"$vHubNr".mac \
782     -c "$vmware_etc_dir"/vmnet"$vHubNr"/nat/nat.conf
783 }
784
785 # Stop the NAT network user service
786 vmware_stop_nat() {
787   local vHubNr="$1"   # IN
788
789   vmware_stop_pidfile /var/run/"$natd"-"$vHubNr".pid
790 }
791
792 # See how we were called.
793 case "$1" in
794   start)
795         if [ -e "$vmware_etc_dir"/not_configured ]; then
796            echo "`vmware_product_name`"' is installed, but it has not been (correctly) configured'
797            echo 'for the running kernel. To (re-)configure it, invoke the'
798            echo 'following command: '"$vmdb_answer_BINDIR"'/vmware-config.pl.'
799            echo
800
801            exit 1
802         fi
803
804         if vmware_inVM; then
805             # Refuse to start services in a VM: they are useless
806             exit 1
807         fi
808
809         echo 'Starting VMware services:'
810         exitcode='0'
811
812         vmware_exec 'Virtual machine monitor' vmware_start_vmmon
813         exitcode=`expr "$exitcode" + "$?"`
814
815         if [ "`isPpuserNeeded`" = '1' ]; then
816            vmware_exec 'Virtual bidirectional parallel port' \
817              vmware_start_vmppuser
818            exitcode=`expr "$exitcode" + "$?"`
819         else
820            # Try to load parport_pc. Failure is allowed as it does not exist
821            # on kernels 2.0
822            /sbin/modprobe parport_pc >/dev/null 2>&1
823         fi
824
825         if [ "$vmdb_answer_NETWORKING" = 'yes' ]; then
826             msg_starting 'Virtual ethernet'
827             busy
828             vmware_start_vmnet
829             exitcode=`expr "$exitcode" + "$?"`
830             ok
831
832             vHubNr=0
833             while [ $vHubNr -lt 256 ]; do
834                 eval 'interface="$vmdb_answer_VNET_'"$vHubNr"'_INTERFACE"'
835                 eval 'hostaddr="$vmdb_answer_VNET_'"$vHubNr"'_HOSTONLY_HOSTADDR"'
836                 eval 'netmask="$vmdb_answer_VNET_'"$vHubNr"'_HOSTONLY_NETMASK"'
837                 if [ -n "$interface" ]; then
838                     vmware_exec 'Bridged networking on /dev/vmnet'"$vHubNr" \
839                     vmware_start_bridge "$vHubNr" "$interface"
840                     exitcode=`expr "$exitcode" + "$?"`
841                 elif [ -n "$hostaddr" -a -n "$netmask" ]; then
842                     eval 'samba="$vmdb_answer_VNET_'"$vHubNr"'_SAMBA"'
843                     vmware_bg_exec 'Host-only networking on /dev/vmnet'"$vHubNr" \
844                     vmware_start_hostonly "$vHubNr" 'vmnet'"$vHubNr" \
845                     "$hostaddr" "$netmask" 'yes' "$samba"
846                     exitcode=`expr "$exitcode" + "$?"`
847
848                     eval 'nat="$vmdb_answer_VNET_'"$vHubNr"'_NAT"'
849                     if [ "$nat" = 'yes' ]; then
850                         vmware_exec 'NAT networking on /dev/vmnet'"$vHubNr" \
851                           vmware_start_nat "$vHubNr"
852                         exitcode=`expr "$exitcode" + "$?"`
853                     fi
854                 fi
855                 vHubNr=`expr $vHubNr + 1`
856             done
857
858         fi
859
860         if [ "$exitcode" -gt 0 ]; then
861           # Set the 'not configured' flag
862           touch "$vmware_etc_dir"'/not_configured'
863           chmod 644 "$vmware_etc_dir"'/not_configured'
864           db_add_file "$vmware_db" "$vmware_etc_dir"'/not_configured' \
865             "$vmware_etc_dir"'/not_configured'
866           exit 1
867         fi
868
869         [ -d /var/lock/subsys ] || mkdir -p /var/lock/subsys
870         touch /var/lock/subsys/"$subsys"
871         ;;
872
873   stop)
874         if [ "`countVMs`" -gt 0 ]; then
875            echo 'At least one instance of '"`vmware_product_name`"' is still running. Please stop all running'
876            echo 'instances of '"`vmware_product_name`"' first.'
877            echo
878
879            # The unconfigurator handle this exit code differently
880            exit 2
881         fi
882
883         echo 'Stopping VMware services:'
884         exitcode='0'
885
886         vmware_exec 'Virtual machine monitor' vmware_stop_vmmon
887         exitcode=`expr "$exitcode" + "$?"`
888
889         if [ "`isPpuserNeeded`" = '1' ]; then
890            vmware_exec 'Virtual bidirectional parallel port' \
891              vmware_stop_vmppuser
892            exitcode=`expr "$exitcode" + "$?"`
893         else
894            # Try to unload parport_pc. Failure is allowed as it does not exist
895            # on kernels 2.0, and some other process could be using it.
896            /sbin/modprobe -r parport_pc >/dev/null 2>&1
897         fi
898
899         if [ "$vmdb_answer_NETWORKING" = "yes" ]; then
900             # NB: must kill off processes using vmnet before
901             #     unloading module
902             vHubNr=0
903             while [ $vHubNr -lt 256 ]; do
904                 eval 'interface="$vmdb_answer_VNET_'"$vHubNr"'_INTERFACE"'
905                 eval 'hostaddr="$vmdb_answer_VNET_'"$vHubNr"'_HOSTONLY_HOSTADDR"'
906                 eval 'netmask="$vmdb_answer_VNET_'"$vHubNr"'_HOSTONLY_NETMASK"'
907                 if [ -n "$interface" ]; then
908                     vmware_exec "Bridged networking on /dev/vmnet$vHubNr" vmware_stop_bridge "$vHubNr"
909                     exitcode=`expr "$exitcode" + "$?"`
910                 elif [ -n "$hostaddr" -a -n "$netmask" ]; then
911                     vmware_exec "DHCP server on /dev/vmnet$vHubNr" vmware_stop_dhcpd \
912                     "vmnet$vHubNr"
913                     exitcode=`expr "$exitcode" + "$?"`
914
915                     eval 'samba="$vmdb_answer_VNET_'"$vHubNr"'_SAMBA"'
916                     if [ "$samba" = "yes" ]; then
917                         vmware_exec 'SMB share server on /dev/vmnet'"$vHubNr" \
918                         vmware_stop_smbd 'vmnet'"$vHubNr"
919                         exitcode=`expr "$exitcode" + "$?"`
920
921                         vmware_exec 'SMB name server on /dev/vmnet'"$vHubNr" \
922                         vmware_stop_nmbd 'vmnet'"$vHubNr"
923                         exitcode=`expr "$exitcode" + "$?"`
924                     fi
925
926                     eval 'nat="$vmdb_answer_VNET_'"$vHubNr"'_NAT"'
927                     if [ "$nat" = "yes" ]; then
928                         vmware_exec 'NAT networking on /dev/vmnet'"$vHubNr" \
929                           vmware_stop_nat "$vHubNr"
930                         exitcode=`expr "$exitcode" + "$?"`
931                     fi
932
933                     vmware_exec 'Host-only networking on /dev/vmnet'"$vHubNr" \
934                     vmware_stop_hostonly 'vmnet'"$vHubNr" "$hostaddr" "$netmask"
935
936                 fi
937                 vHubNr=`expr $vHubNr + 1`
938             done
939
940             vmware_exec 'Virtual ethernet' vmware_stop_vmnet
941             exitcode=`expr "$exitcode" + "$?"`
942         fi
943
944         if [ "$exitcode" -gt 0 ]; then
945            exit 1
946         fi
947
948         rm -f /var/lock/subsys/"$subsys"
949         ;;
950
951   status)
952         if [ "`countVMs`" -gt 0 ]; then
953            echo 'At least one instance of '"`vmware_product_name`"' is still running.'
954            echo
955         fi
956
957         if [ "$vmdb_answer_NETWORKING" = "yes" ]; then
958             status "$bridge"
959             status "$dhcpd"
960             status "$netifup"
961         fi
962
963         echo -n "Module $driver "
964         /sbin/modprobe "$driver" >/dev/null 2>&1 && echo installed || echo "not installed"
965         if [ "`isPpuserNeeded`" = '1' ]; then
966             echo -n "Module $ppuser "
967             /sbin/modprobe "$ppuser" >/dev/null 2>&1 && echo installed || echo "not installed"
968         fi
969         if [ "$vmdb_answer_NETWORKING" = "yes" ]; then
970             echo -n "Module $vnet "
971             /sbin/modprobe "$vnet" >/dev/null 2>&1 && echo installed || echo "not installed"
972         fi
973         ;;
974
975   restart)
976         "$0" stop && "$0" start
977         ;;
978
979   *)
980         echo "Usage: `basename "$0"` {start|stop|status|restart}"
981         exit 1
982 esac
983
984 exit 0
This page took 0.109852 seconds and 3 git commands to generate.