Rev 4 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed
#!/bin/sh## Copyright (C) 1998-2010 VMware, Inc. All Rights Reserved.## This script manages the services needed to run VMware software# Basic support for IRIX style chkconfig# chkconfig: 235 55 6# description: This services starts and stops the Workstation as a Server daemon.SCRIPTNAME="$(basename $(readlink -f "$0"))"MODNAME="hostd"ETCDIR=/etc/vmwareADMIN_TOOL=vmware-wssc-adminToolVIM_CMD=vmware-vim-cmdHOHO_ADMIN="". $ETCDIR/bootstraplibdir="$LIBDIR"/vmware. "$libdir"/scripts/util.sh# This comment is a hack to prevent RedHat distributions from outputing# "Starting <basename of this script>" when running this startup script.# We just need to write the word daemon followed by a spaceSYSTEM_DAEMON=vmware-hostd# We need a more specific match than just "vmware-hostd".PGREP_MATCH="vmware/bin/$SYSTEM_DAEMON"# Make sure the ESC byte is literal: Ash does not support echo -erc_done='[71G done'rc_failed='[71Gfailed'## Utilities#upperCase() {echo "`echo $1|tr '[:lower:]' '[:upper:]'`"}wssc_findAdmin() {HOHO_ADMIN=`$ADMIN_TOOL $ETCDIR/hostd/authorization.xml 2>/dev/null`adminRet=$?if [ $adminRet != 0 ]; thenecho "Could not find administrative user. Error $adminRet."HOHO_ADMIN=""fireturn $adminRet}vim_shutdown() {if [ "x" = "x$HOHO_ADMIN" ]; thenreturn 1fi$VIM_CMD -U "$HOHO_ADMIN" internalsvc/shutdown}vim_autostop() {if [ "x" = "x$HOHO_ADMIN" ]; thenreturn 1fi$VIM_CMD -U "$HOHO_ADMIN" hostsvc/autostartmanager/autostop}vmware_start_daemon() {# Check if certificates exist. If not, we need to generate them, ala sshd.if [ ! -e ${ETCDIR}/ssl/rui.key -o ! -e ${ETCDIR}/ssl/rui.crt ]; thenmkdir -p ${ETCDIR}/sslenv LD_LIBRARY_PATH=${libdir}/lib/libssl.so.1.0.1:${libdir}/lib/libcrypto.so.1.0.1 ${libdir}/bin/openssl req -x509 -days 365 -newkey rsa:2048 -sha256 -keyout ${ETCDIR}/ssl/rui.key -out ${ETCDIR}/ssl/rui.crt -config ${ETCDIR}/ssl/hostd.ssl.configchmod -R 600 ${ETCDIR}/sslfi# Start the daemoncd "$BINDIR" && "$BINDIR"/$1 \-a -d $ETCDIR/hostd/config.xmlreturn $?}vmware_kill_daemon() {pid=`pgrep -f $PGREP_MATCH`if [ "$pid" = "" ]; thenreturn 0fi# Kill the vmware-hostd processkill -15 $pid# Give it a few seconds to shut down properlyfor f in '1 2 3 4 5 6 7 8 9 10'; doif ! ps $pid >/dev/null; then# No need to wait if it's already downbreakfisleep 1done# Give it a few seconds to shut down after the killfor f in '1 2 3 4 5 6 7 8 9 10'; doif ! ps $pid >/dev/null; then# No need to wait if it's already downbreakfisleep 1doneif ps $pid >/dev/null; then# Failed to kill it...return 1else# Success!return 0fi}vmware_stop_daemon() {pid=`pgrep -f $PGREP_MATCH`if [ "$pid" = "" ]; thenreturn 0fivim_autostopvmware_kill_daemon}vmware_force_stop_daemon() {pid=`pgrep -f $PGREP_MATCH`if [ "$pid" = "" ]; thenreturn 0fivmware_stop_daemon || kill -9 $pid# Give it a few seconds to shut down after the hard killfor f in '1 2 3 4 5 6 7 8 9 10'; doif ! ps $pid >/dev/null; then# No need to wait if it's already downbreakfisleep 1doneif ps $pid >/dev/null; then# Failed to kill it, even with a kill -9return 1else# Success!return 0fi}vmware_daemon_status() {pid=`pgrep -f $PGREP_MATCH`if [ "$pid" = "" ]; thenecho 'Workstation Server is not running'elseecho 'Workstation Server is running, process' $pidfi}main(){# See how we were called.case "$1" instart)exitcode='0'vmware_exec 'Starting Workstation Server:' vmware_start_daemon $SYSTEM_DAEMONexitcode=$(($exitcode + $?))if [ "$exitcode" -gt 0 ]; thenexit 1fi;;stop)wssc_findAdminexitcode='0'vmware_exec 'Stopping Workstation Server:' vmware_stop_daemonexitcode=$(($exitcode + $?))if [ "$exitcode" -gt 0 ]; thenexit 1fi;;force-stop)wssc_findAdminexitcode='0'vmware_exec 'Forcing stop of Workstation Server:' vmware_force_stop_daemonexitcode=$(($exitcode + $?))if [ "$exitcode" -gt 0 ]; thenexit 1fi;;restart)vmware_kill_daemon && "$0" start;;force-reload)"$0" force-stop && "$0" start;;source)# Used to source the script so that functions can be# selectively overridden.return 0;;status)vmware_daemon_status;;*)echo "Usage: `basename "$0"` {start|stop|status|restart|force-reload}"exit 1esacexit 0}main "$@"