summaryrefslogtreecommitdiff
path: root/open-vm-tools/vmtools.rc
blob: 71db6e4f462b323f44d500fb2ffa2047600f902b (plain)
    1 #!/bin/bash
    2 
    3 NAME=vmtools
    4 USER=root
    5 CONFIG="/etc/vmware-tools/tools.conf"
    6 RUNDIR="/var/run"
    7 PIDFILE="$RUNDIR/vmtoolsd.pid"
    8 STARTCMD="/usr/bin/vmtoolsd --config=$CONFIG --background=$PIDFILE"
    9 STOPCMD=""
   10 STOPTIMEOUT=300
   11 
   12 function getpid() {
   13 	if [ -z "$PIDFILE" ]; then
   14 		pid="$(pgrep -xfn "$STARTCMD")"
   15 	else
   16 		if [ -f "$PIDFILE" ]; then
   17 			pid=$(< $PIDFILE)
   18 			if [ ! -d /proc/"$pid" ]; then
   19 				echo "$NAME: removing stale pidfile $PIDFILE" >&2
   20 				rm -f "$PIDFILE"
   21 				unset pid
   22 			fi
   23 		fi
   24 	fi
   25 	echo "$pid"
   26 }
   27 
   28 case $1 in
   29 start)
   30 	pid=$(getpid)
   31 	install -d -m 755 -o $USER $RUNDIR || exit 1
   32 	if [ -n "$pid" ]; then
   33 		echo "$NAME already running with pid $pid" >&2
   34 		exit 1
   35 	fi
   36 	eval "$STARTCMD"
   37 	;;
   38 stop)
   39 	pid=$(getpid)
   40 	if [ -n "$pid" ]; then
   41 		if [ -n "$STOPCMD" ]; then
   42 			eval "$STOPCMD"
   43 		else
   44 			kill "$pid"
   45 		fi
   46 		t=$(printf '%(%s)T' -1)
   47 		tend=$((t+STOPTIMEOUT))
   48 		while [ -d /proc/$pid -a $t -lt $tend ]; do
   49 			sleep 0.5
   50 			t=$(printf '%(%s)T' -1)
   51 		done
   52 		if [ -d /proc/"$pid" ]; then
   53 			echo "$NAME still running with pid $pid" >&2
   54 		else
   55 			[ -n "$PIDFILE" ] && rm -f "$PIDFILE"
   56 		fi
   57 	else
   58 		echo "$NAME is not running" >&2
   59 	fi
   60 	;;
   61 restart)
   62 	$0 stop
   63 	$0 start
   64 	;;
   65 status)
   66 	pid=$(getpid)
   67 	if [ -n "$pid" ]; then
   68 		echo "$NAME is running with pid $pid"
   69 	else
   70 		echo "$NAME is not running"
   71 	fi
   72 	;;
   73 *)
   74 	echo "usage: $0 [start|stop|restart|status]"
   75 	;;
   76 esac

Generated by cgit