author "Neal H. Walfield <neal@cs.jhu.edu>"
description "Smart storage logger.  See http://hssl.cs.jhu.edu/~neal/smart-storage"

start on started hildon-desktop
stop on ACT_DEAD
stop on starting shutdown

console none

# Make sure the user's dbus session bus is accessible.
script
	USER=`whoami`
	if [ x"$USER" = xroot ]; 
	then
	  USER=user
	fi
	source /tmp/session_bus_address.$USER

	/usr/sbin/waitdbus system
	/usr/sbin/waitdbus session

	{
	  echo "Running smart-storage-logger-consent."
	  if run-standalone.sh python /usr/bin/smart-storage-logger-consent
	  then
	    echo "Have user's consent."
	    exec /usr/bin/smart-storage-logger --no-fork
	  else
	    echo "User did not give consent, uninstalling."
	    sleep 10
	    while ! nohup dpkg -P smart-storage-logger
	    do
	      echo "Uninstalling smart-storage-logger failed." \
	        "Sleeping and trying again."
	      sleep 5
	    done
	  fi
	} >/tmp/smart-storage-logger-output 2>&1
end script

post-stop script
	exec /usr/bin/smart-storage-logger-recover
end script

respawn
nice 5
# We'd really prefer that smart-storage-logger exits cleanly...
kill timeout 20
