#!/bin/sh # # Startup script for the web server that runs the VMware Management UI # # description: The VMware Management UI uses Apache compiled with # mod_perl. # # Start order should be 91. Kill order should be 07. # # processname: /usr/lib/vmware-mui/apache/bin/httpd.vmware # pidfile: /var/run/httpd.vmware.pid # config: /usr/lib/vmware-mui/apache/conf/access.conf # config: /usr/lib/vmware-mui/apache/conf/httpd.conf # config: /usr/lib/vmware-mui/apache/conf/srm.conf # # Basic support for IRIX style chkconfig # chkconfig: 3 91 07 # description: Manages the services needed to run VMware MUI # ### BEGIN INIT INFO # Provides: VMwareMUI # Required-Start: $network $syslog VMware # Required-Stop: # Default-Start: 3 5 # Default-Stop: 0 1 2 4 6 # Description: Manages the services needed to run VMware MUI ### END INIT INFO INITDIR=/etc/init.d INSTALLDIR=/usr/lib/vmware-mui if [ -z "$LD_LIBRARY_PATH" ]; then LD_LIBRARY_PATH="$INSTALLDIR/lib" else LD_LIBRARY_PATH="$LD_LIBRARY_PATH:$INSTALLDIR/lib" fi # BEGINNING_OF_UTIL_DOT_SH #!/bin/sh # A few utility functions used by our shell scripts. These are patched in during # make. # They are a lot of small utility programs to create temporary files in a # secure way, but none of them is standard. So I wrote this --hpreg make_tmp_dir() { local dirname="$1" # OUT local prefix="$2" # IN local tmp local serial local loop tmp="${TMPDIR:-/tmp}" # Don't overwrite existing user data # -> Create a directory with a name that didn't exist before # # This may never succeed (if we are racing with a malicious process), but at # least it is secure serial=0 loop='yes' while [ "$loop" = 'yes' ]; do # Check the validity of the temporary directory. We do this in the loop # because it can change over time if [ ! -d "$tmp" ]; then echo 'Error: "'"$tmp"'" is not a directory.' echo exit 1 fi if [ ! -w "$tmp" -o ! -x "$tmp" ]; then echo 'Error: "'"$tmp"'" should be writable and executable.' echo exit 1 fi # Be secure # -> Don't give write access to other users (so that they can not use this # directory to launch a symlink attack) if mkdir -m 0755 "$tmp"'/'"$prefix$serial" >/dev/null 2>&1; then loop='no' else serial=`expr $serial + 1` serial_mod=`expr $serial % 200` if [ "$serial_mod" = '0' ]; then echo 'Warning: The "'"$tmp"'" directory may be under attack.' echo fi fi done eval "$dirname"'="$tmp"'"'"'/'"'"'"$prefix$serial"' } # Check if the process associated to a pidfile is running. # Return 0 if the pidfile exists and the process is running, 1 otherwise vmware_check_pidfile() { local pidfile="$1" # IN local pid pid=`cat "$pidfile" 2>/dev/null` if [ "$pid" = '' ]; then # The file probably does not exist or is empty. Failure return 1 fi # Keep only the first number we find, because some Samba pid files are really # trashy: they end with NUL characters # There is no double quote around $pid on purpose set -- $pid pid="$1" [ -d /proc/"$pid" ] } # Note: # . Each daemon must be started from its own directory to avoid busy devices # . Each PID file doesn't need to be added to the installer database, because # it is going to be automatically removed when it becomes stale (after a # reboot). It must go directly under /var/run, or some distributions # (RedHat 6.0) won't clean it # # Terminate a process synchronously vmware_synchrone_kill() { local pid="$1" # IN local signal="$2" # IN local second kill -"$signal" "$pid" # Wait a bit to see if the dirty job has really been done for second in 0 1 2 3 4 5 6 7 8 9 10; do if [ ! -d /proc/"$pid" ]; then # Success return 0 fi sleep 1 done # Timeout return 1 } # Kill the process associated to a pidfile vmware_stop_pidfile() { local pidfile="$1" # IN local pid pid=`cat "$pidfile" 2>/dev/null` if [ "$pid" = '' ]; then # The file probably does not exist or is empty. Success return 0 fi # Keep only the first number we find, because some Samba pid files are really # trashy: they end with NUL characters # There is no double quote around $pid on purpose set -- $pid pid="$1" # First try a nice SIGTERM if vmware_synchrone_kill "$pid" 15; then return 0 fi # Then send a strong SIGKILL if vmware_synchrone_kill "$pid" 9; then return 0 fi return 1 } # END_OF_UTIL_DOT_SH # This defines echo_success() and echo_failure() on RedHat if [ -r "$INITDIR"/functions ]; then . "$INITDIR"/functions elif [ -r /lib/lsb/init-functions ]; then . /lib/lsb/init-functions fi # This defines $rc_done and $rc_failed on S.u.S.E. if [ -f /etc/rc.config ]; then # Don't quite feel like including the entire file. # There could be conflicts. rc_done="\033[71G\033[32mdone\033[m" rc_failed="\033[71G\033[31m\033[1mfailed\033[m" else rc_done="\033[71G done" rc_failed="\033[71Gfailed" fi vmware_failed() { if [ "`type -t 'echo_failure' 2>/dev/null`" = 'function' ]; then echo_failure else echo -ne "$rc_failed" fi } vmware_success() { if [ "`type -t 'echo_success' 2>/dev/null`" = 'function' ]; then echo_success else echo -ne "$rc_done" fi } # Execute a macro vmware_exec() { local msg="$1" # IN local func="$2" # IN shift 2 echo -n ' '"$msg" # On Caldera 2.2, SIGHUP is sent to all our children when this script exits # I wanted to use shopt -u huponexit instead but their bash version # 1.14.7(1) is too old if [ "$VMWARE_DEBUG" = 'yes' ]; then (trap '' HUP; "$func" "$@") else (trap '' HUP; "$func" "$@") >/dev/null 2>&1 fi if [ "$?" -gt 0 ]; then vmware_failed echo return 1 fi vmware_success echo return 0 } vmware_start_httpd() { export LD_LIBRARY_PATH if /bin/grep -i "^security.host.muissl.*=.*\(n\|f\|0\)" /etc/vmware/config > /dev/null 2>&1 ; then USE_SSL="" else USE_SSL="-DSSL_ONLY" fi $INSTALLDIR/apache/bin/httpd.vmware -DSSL $USE_SSL -DGSX -d $INSTALLDIR/apache touch /var/lock/subsys/httpd.vmware } vmware_stop_httpd() { killproc $INSTALLDIR/apache/bin/httpd.vmware rm -f /var/lock/subsys/httpd.vmware } # See how we were called. case "$1" in start) if [ ! -d /var/run/vmware/httpd ] then echo "Directory: var/run/vmware/httpd Not found. Creating it." mkdir /var/run/vmware/httpd echo "Setting user and group ownership to: User: www-data, Group: nogroup" chown www-data:nogroup /var/run/vmware/httpd echo "Setting directory permissions to: RWX------ (700)" chmod 700 /var/run/vmware/httpd fi echo "Starting httpd.vmware:" vmware_start_httpd ;; stop) echo "Shutting down http.vmware: " vmware_stop_httpd ;; status) echo -n 'vmware.httpd' if vmware_check_pidfile /var/run/httpd.vmware.pid; then echo ' is running.' else echo ' is not running.' fi ;; restart) $0 stop $0 start ;; reload) echo -n "Reloading httpd.vmware: " killproc $INSTALLDIR/apache/bin/httpd.vmware -HUP echo ;; *) echo "Usage: $0 {start|stop|restart|reload|status}" exit 1 esac exit 0