Subversion Repositories configs

Rev

Rev 4 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
4 - 1
#!/bin/sh
2
#
3
# Copyright (C) 1998-2010 VMware, Inc.  All Rights Reserved.
4
#
5
# This script manages the services needed to run VMware software
6
 
7
# Basic support for IRIX style chkconfig
8
# chkconfig: 235 55 6
9
# description: This services starts and stops the Workstation as a Server daemon.
10
 
11
 
12
SCRIPTNAME="$(basename $(readlink -f "$0"))"
13
MODNAME="hostd"
14
ETCDIR=/etc/vmware
15
 
16
ADMIN_TOOL=vmware-wssc-adminTool
17
VIM_CMD=vmware-vim-cmd
18
HOHO_ADMIN=""
19
 
20
. $ETCDIR/bootstrap
21
libdir="$LIBDIR"/vmware
22
 
23
. "$libdir"/scripts/util.sh
24
 
25
# This comment is a hack to prevent RedHat distributions from outputing
26
# "Starting <basename of this script>" when running this startup script.
27
# We just need to write the word daemon followed by a space
28
 
29
SYSTEM_DAEMON=vmware-hostd
30
# We need a more specific match than just "vmware-hostd".
31
PGREP_MATCH="vmware/bin/$SYSTEM_DAEMON"
32
 
33
# Make sure the ESC byte is literal: Ash does not support echo -e
34
rc_done=' done'
35
rc_failed='failed'
36
 
37
#
38
# Utilities
39
#
40
 
41
upperCase() {
42
  echo "`echo $1|tr '[:lower:]' '[:upper:]'`"
43
}
44
 
45
wssc_findAdmin() {
46
   HOHO_ADMIN=`$ADMIN_TOOL $ETCDIR/hostd/authorization.xml 2>/dev/null`
47
   adminRet=$?
48
 
49
   if [ $adminRet != 0 ]; then
50
      echo "Could not find administrative user. Error $adminRet."
51
      HOHO_ADMIN=""
52
   fi
53
 
54
   return $adminRet
55
}
56
 
57
vim_shutdown() {
58
   if [ "x" = "x$HOHO_ADMIN" ]; then
59
      return 1
60
   fi
61
   $VIM_CMD -U "$HOHO_ADMIN" internalsvc/shutdown
62
}
63
 
64
vim_autostop() {
65
   if [ "x" = "x$HOHO_ADMIN" ]; then
66
      return 1
67
   fi
68
   $VIM_CMD -U "$HOHO_ADMIN" hostsvc/autostartmanager/autostop
69
}
70
 
71
 
72
vmware_start_daemon() {
73
   # Check if certificates exist.  If not, we need to generate them, ala sshd.
74
   if [ ! -e ${ETCDIR}/ssl/rui.key -o ! -e ${ETCDIR}/ssl/rui.crt ]; then
75
      mkdir -p ${ETCDIR}/ssl
64 - 76
      env 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.config
4 - 77
      chmod -R 600 ${ETCDIR}/ssl
78
   fi
79
 
80
   # Start the daemon
81
   cd "$BINDIR" && "$BINDIR"/$1 \
82
      -a -d $ETCDIR/hostd/config.xml
83
 
84
   return $?
85
}
86
 
87
vmware_kill_daemon() {
88
   pid=`pgrep -f $PGREP_MATCH`
89
 
90
   if [ "$pid" = "" ]; then
91
      return 0
92
   fi
93
 
94
   # Kill the vmware-hostd process
95
   kill -15 $pid
96
   # Give it a few seconds to shut down properly
97
   for f in '1 2 3 4 5 6 7 8 9 10'; do
98
      if ! ps $pid >/dev/null; then
99
         # No need to wait if it's already down
100
         break
101
      fi
102
      sleep 1
103
   done
104
 
105
   # Give it a few seconds to shut down after the kill
106
   for f in '1 2 3 4 5 6 7 8 9 10'; do
107
      if ! ps $pid >/dev/null; then
108
         # No need to wait if it's already down
109
         break
110
      fi
111
      sleep 1
112
   done
113
 
114
   if ps $pid >/dev/null; then
115
      # Failed to kill it...
116
      return 1
117
   else
118
      # Success!
119
      return 0
120
   fi
121
}
122
 
123
vmware_stop_daemon() {
124
   pid=`pgrep -f $PGREP_MATCH`
125
 
126
   if [ "$pid" = "" ]; then
127
      return 0
128
   fi
129
 
130
   vim_autostop
131
   vmware_kill_daemon
132
}
133
 
134
vmware_force_stop_daemon() {
135
   pid=`pgrep -f $PGREP_MATCH`
136
 
137
   if [ "$pid" = "" ]; then
138
      return 0
139
   fi
140
 
141
   vmware_stop_daemon || kill -9 $pid
142
 
143
   # Give it a few seconds to shut down after the hard kill
144
   for f in '1 2 3 4 5 6 7 8 9 10'; do
145
      if ! ps $pid >/dev/null; then
146
         # No need to wait if it's already down
147
         break
148
      fi
149
      sleep 1
150
   done
151
 
152
   if ps $pid >/dev/null; then
153
      # Failed to kill it, even with a kill -9
154
      return 1
155
   else
156
      # Success!
157
      return 0
158
   fi
159
 
160
}
161
 
162
vmware_daemon_status() {
163
   pid=`pgrep -f $PGREP_MATCH`
164
 
165
   if [ "$pid" = "" ]; then
166
      echo 'Workstation Server is not running'
167
   else
168
      echo 'Workstation Server is running, process' $pid
169
 
170
   fi
171
}
172
 
173
main()
174
{
175
   # See how we were called.
176
   case "$1" in
177
      start)
178
         exitcode='0'
179
 
180
         vmware_exec 'Starting Workstation Server:' vmware_start_daemon $SYSTEM_DAEMON
181
         exitcode=$(($exitcode + $?))
182
 
183
 
184
         if [ "$exitcode" -gt 0 ]; then
185
            exit 1
186
         fi
187
         ;;
188
 
189
      stop)
190
         wssc_findAdmin
191
         exitcode='0'
192
 
193
         vmware_exec 'Stopping Workstation Server:' vmware_stop_daemon
194
         exitcode=$(($exitcode + $?))
195
 
196
         if [ "$exitcode" -gt 0 ]; then
197
            exit 1
198
         fi
199
         ;;
200
 
201
      force-stop)
202
         wssc_findAdmin
203
         exitcode='0'
204
 
205
         vmware_exec 'Forcing stop of Workstation Server:' vmware_force_stop_daemon
206
         exitcode=$(($exitcode + $?))
207
 
208
         if [ "$exitcode" -gt 0 ]; then
209
            exit 1
210
         fi
211
         ;;
212
 
213
      restart)
214
         vmware_kill_daemon && "$0" start
215
         ;;
216
 
217
      force-reload)
218
         "$0" force-stop && "$0" start
219
         ;;
220
 
221
      source)
222
         # Used to source the script so that functions can be
223
         # selectively overridden.
224
         return 0
225
         ;;
226
 
227
      status)
228
         vmware_daemon_status
229
         ;;
230
      *)
231
         echo "Usage: `basename "$0"` {start|stop|status|restart|force-reload}"
232
         exit 1
233
   esac
234
 
235
   exit 0
236
}
237
 
238
main "$@"