summaryrefslogtreecommitdiff
path: root/open-vm-tools/vmtools.rc
diff options
context:
space:
mode:
Diffstat (limited to 'open-vm-tools/vmtools.rc')
-rwxr-xr-xopen-vm-tools/vmtools.rc72
1 files changed, 60 insertions, 12 deletions
diff --git a/open-vm-tools/vmtools.rc b/open-vm-tools/vmtools.rc
index ca6f7cb02..71db6e4f4 100755
--- a/open-vm-tools/vmtools.rc
+++ b/open-vm-tools/vmtools.rc
@@ -1,29 +1,77 @@
-#!/bin/sh
-#
-# /etc/rc.d/vmtools: start/stop VMware Tools
-#
+#!/bin/bash
-PIDFILE=/var/run/vmware-tools.pid
-VMTOOLSD_BIN=/usr/bin/vmtoolsd
+NAME=vmtools
+USER=root
+CONFIG="/etc/vmware-tools/tools.conf"
+RUNDIR="/var/run"
+PIDFILE="$RUNDIR/vmtoolsd.pid"
+STARTCMD="/usr/bin/vmtoolsd --config=$CONFIG --background=$PIDFILE"
+STOPCMD=""
+STOPTIMEOUT=300
+
+function getpid() {
+ if [ -z "$PIDFILE" ]; then
+ pid="$(pgrep -xfn "$STARTCMD")"
+ else
+ if [ -f "$PIDFILE" ]; then
+ pid=$(< $PIDFILE)
+ if [ ! -d /proc/"$pid" ]; then
+ echo "$NAME: removing stale pidfile $PIDFILE" >&2
+ rm -f "$PIDFILE"
+ unset pid
+ fi
+ fi
+ fi
+ echo "$pid"
+}
case $1 in
start)
- $VMTOOLSD_BIN --background=$PIDFILE
+ pid=$(getpid)
+ install -d -m 755 -o $USER $RUNDIR || exit 1
+ if [ -n "$pid" ]; then
+ echo "$NAME already running with pid $pid" >&2
+ exit 1
+ fi
+ eval "$STARTCMD"
;;
stop)
- if [ -f $PIDFILE ]; then
- kill $(< $PIDFILE) && rm -f $PIDFILE
+ pid=$(getpid)
+ if [ -n "$pid" ]; then
+ if [ -n "$STOPCMD" ]; then
+ eval "$STOPCMD"
+ else
+ kill "$pid"
+ fi
+ t=$(printf '%(%s)T' -1)
+ tend=$((t+STOPTIMEOUT))
+ while [ -d /proc/$pid -a $t -lt $tend ]; do
+ sleep 0.5
+ t=$(printf '%(%s)T' -1)
+ done
+ if [ -d /proc/"$pid" ]; then
+ echo "$NAME still running with pid $pid" >&2
+ else
+ [ -n "$PIDFILE" ] && rm -f "$PIDFILE"
+ fi
else
- killall -q $VMTOOLSD_BIN
+ echo "$NAME is not running" >&2
fi
;;
restart)
$0 stop
$0 start
;;
+status)
+ pid=$(getpid)
+ if [ -n "$pid" ]; then
+ echo "$NAME is running with pid $pid"
+ else
+ echo "$NAME is not running"
+ fi
+ ;;
*)
- echo "usage: $0 [start|stop|restart]"
+ echo "usage: $0 [start|stop|restart|status]"
;;
esac
-# End of file

Generated by cgit