Subversion Repositories configs

Rev

Rev 64 | 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
175 - 76
      env LD_LIBRARY_PATH=${libdir}/lib/libssl.so.1.0.2:${libdir}/lib/libcrypto.so.1.0.2 ${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
77
 
78
      # The .random_number_seed file is specified in hostd.ssl.config. It is
79
      # used for random number seed generation required by openssl. After
80
      # creating the key pair, the temp file should be removed.
81
      rm ./.random_number_seed
82
 
4 - 83
      chmod -R 600 ${ETCDIR}/ssl
84
   fi
85
 
86
   # Start the daemon
87
   cd "$BINDIR" && "$BINDIR"/$1 \
88
      -a -d $ETCDIR/hostd/config.xml
89
 
90
   return $?
91
}
92
 
93
vmware_kill_daemon() {
94
   pid=`pgrep -f $PGREP_MATCH`
95
 
96
   if [ "$pid" = "" ]; then
97
      return 0
98
   fi
99
 
100
   # Kill the vmware-hostd process
101
   kill -15 $pid
102
   # Give it a few seconds to shut down properly
103
   for f in '1 2 3 4 5 6 7 8 9 10'; do
104
      if ! ps $pid >/dev/null; then
105
         # No need to wait if it's already down
106
         break
107
      fi
108
      sleep 1
109
   done
110
 
111
   # Give it a few seconds to shut down after the kill
112
   for f in '1 2 3 4 5 6 7 8 9 10'; do
113
      if ! ps $pid >/dev/null; then
114
         # No need to wait if it's already down
115
         break
116
      fi
117
      sleep 1
118
   done
119
 
120
   if ps $pid >/dev/null; then
121
      # Failed to kill it...
122
      return 1
123
   else
124
      # Success!
125
      return 0
126
   fi
127
}
128
 
129
vmware_stop_daemon() {
130
   pid=`pgrep -f $PGREP_MATCH`
131
 
132
   if [ "$pid" = "" ]; then
133
      return 0
134
   fi
135
 
136
   vim_autostop
137
   vmware_kill_daemon
138
}
139
 
140
vmware_force_stop_daemon() {
141
   pid=`pgrep -f $PGREP_MATCH`
142
 
143
   if [ "$pid" = "" ]; then
144
      return 0
145
   fi
146
 
147
   vmware_stop_daemon || kill -9 $pid
148
 
149
   # Give it a few seconds to shut down after the hard kill
150
   for f in '1 2 3 4 5 6 7 8 9 10'; do
151
      if ! ps $pid >/dev/null; then
152
         # No need to wait if it's already down
153
         break
154
      fi
155
      sleep 1
156
   done
157
 
158
   if ps $pid >/dev/null; then
159
      # Failed to kill it, even with a kill -9
160
      return 1
161
   else
162
      # Success!
163
      return 0
164
   fi
165
 
166
}
167
 
168
vmware_daemon_status() {
169
   pid=`pgrep -f $PGREP_MATCH`
170
 
171
   if [ "$pid" = "" ]; then
172
      echo 'Workstation Server is not running'
173
   else
174
      echo 'Workstation Server is running, process' $pid
175
 
176
   fi
177
}
178
 
179
main()
180
{
181
   # See how we were called.
182
   case "$1" in
183
      start)
184
         exitcode='0'
185
 
186
         vmware_exec 'Starting Workstation Server:' vmware_start_daemon $SYSTEM_DAEMON
187
         exitcode=$(($exitcode + $?))
188
 
189
 
190
         if [ "$exitcode" -gt 0 ]; then
191
            exit 1
192
         fi
193
         ;;
194
 
195
      stop)
196
         wssc_findAdmin
197
         exitcode='0'
198
 
199
         vmware_exec 'Stopping Workstation Server:' vmware_stop_daemon
200
         exitcode=$(($exitcode + $?))
201
 
202
         if [ "$exitcode" -gt 0 ]; then
203
            exit 1
204
         fi
205
         ;;
206
 
207
      force-stop)
208
         wssc_findAdmin
209
         exitcode='0'
210
 
211
         vmware_exec 'Forcing stop of Workstation Server:' vmware_force_stop_daemon
212
         exitcode=$(($exitcode + $?))
213
 
214
         if [ "$exitcode" -gt 0 ]; then
215
            exit 1
216
         fi
217
         ;;
218
 
219
      restart)
220
         vmware_kill_daemon && "$0" start
221
         ;;
222
 
223
      force-reload)
224
         "$0" force-stop && "$0" start
225
         ;;
226
 
227
      source)
228
         # Used to source the script so that functions can be
229
         # selectively overridden.
230
         return 0
231
         ;;
232
 
233
      status)
234
         vmware_daemon_status
235
         ;;
236
      *)
237
         echo "Usage: `basename "$0"` {start|stop|status|restart|force-reload}"
238
         exit 1
239
   esac
240
 
241
   exit 0
242
}
243
 
244
main "$@"