#!/bin/sh
### BEGIN INIT INFO
# Provides:          xvfb
# Required-Start:    $remote_fs $syslog
# Required-Stop:     $remote_fs $syslog
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: XVFB - Virtual X server display
# Description:       XVFB - Virtual X server display
### END INIT INFO

# Author: Matthieu Faure <mfaure@asqatasun.org>

# Do NOT "set -e"
# TODO: improve with help from /etc/init.d/skeleton

RUN_AS_USER=tomcat7
OPTS=":99 -screen 1 1024x768x24 -nolisten tcp"
XVFB_DIR=/usr/bin
PIDFILE=/var/run/xvfb

case $1 in

start)
	start-stop-daemon --chuid $RUN_AS_USER -b --start --exec $XVFB_DIR/Xvfb --make-pidfile --pidfile $PIDFILE -- $OPTS &
;;

stop)
	start-stop-daemon --stop --user $RUN_AS_USER --pidfile $PIDFILE
	rm -f $PIDFILE
;;

restart)
	if start-stop-daemon --test --stop --user $RUN_AS_USER --pidfile $PIDFILE >/dev/null; then
		$0 stop
	fi;
	$0 start
;;

*)
	echo "Usage: $0 (start|restart|stop)"
	exit 1
;;

esac

exit 0
