#!/bin/bash # /etc/init.d/xserver: start or stop the X server set -e PATH=/bin:/usr/bin:/sbin:/usr/sbin DAEMON=/usr/bin/X11/X DAEMONARGS=":0 -dpi 100 -indirect localhost" PIDFILE=/var/run/xserver.pid test -x $DAEMON || exit 0 stillrunning () { if [ "$DAEMON" = "$(cat /proc/$DAEMONPID/cmdline 2> /dev/null | sed -e 's/\/X:.*$/\/X/')" ]; then true else # if the daemon does not remove its own pidfile, we will rm -f $PIDFILE false fi; } case "$1" in start) # echo -n "Ugly modprobe stuff to get mouse working :-) " # modprobe hid # modprobe input # modprobe mousedev # echo "done." echo -n "Starting X server: $DAEMON" start-stop-daemon --start --quiet --background --pidfile $PIDFILE --exec $DAEMON -- $DAEMONARGS || echo -n " already running" echo `pidof $DAEMON` > $PIDFILE echo "." ;; restart) /etc/init.d/xserver stop if [ -f $PIDFILE ]; then if stillrunning; then exit 1 fi fi /etc/init.d/xserver start ;; reload) echo "xserver does not support reload" ;; force-reload) /etc/init.d/xserver reload ;; stop) echo -n "Stopping X server: X" if [ ! -f $PIDFILE ]; then echo " not running ($PIDFILE not found)." exit 0 else DAEMONPID=$(cat $PIDFILE | tr -d '[:blank:]') KILLCOUNT=1 if [ ! -e $UPGRADEFILE ]; then start-stop-daemon --stop --quiet --pidfile $PIDFILE --exec $DAEMON || echo -n " not running" fi while [ $KILLCOUNT -le 5 ]; do if stillrunning; then kill $DAEMONPID else break fi sleep 1 KILLCOUNT=$(expr $KILLCOUNT + 1) done if stillrunning; then echo -n " not responding to TERM signal (pid $DAEMONPID)" else rm -f $UPGRADEFILE fi fi echo "." ;; *) echo "Usage: /etc/init.d/xserver {start|stop|restart}" exit 1 ;; esac exit 0