#!/bin/sh
#
# AsynCluster: Node Display Manager (NDM):
# A simple X display manager for cluster nodes that also serve as
# access-restricted workstations. An NDM client runs on each node and
# communicates via Twisted's Perspective Broker to the Aysncluster server,
# which regulates when and how much each user can use his account on any of the
# workstations. The NDM server also dispatches cluster operations to the nodes
# via the NDM clients, unbeknownst to the workstation users.
#
# Copyright (C) 2006-2007 by Edwin A. Suominen, http://www.eepatents.com
#
# This program is free software; you can redistribute it and/or modify it under
# the terms of the GNU General Public License as published by the Free Software
# Foundation; either version 2 of the License, or (at your option) any later
# version.
# 
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE.  See the file COPYING for more details.
# 
# You should have received a copy of the GNU General Public License along with
# this program; if not, write to the Free Software Foundation, Inc., 51
# Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA

# Call with a single mode-determining argument
echo $@
if [ "$1" = "DAEMON" ]
    then
    # The Xinit (re)starter loop is what runs as the daemon
    export DISPLAY=:0
    XINIT_ARGS="$0 PYTHON -- /usr/bin/X -ac -br +kb :0"
    while [ 1 ]
      do
      /usr/bin/xinit $XINIT_ARGS
    done

elif [ "$1" = "PYTHON" ]
    then
    # Starts the Python interpreter as Xinit's sole X client
    exec python \
        -c "from asyncluster.ndm import node; node.Manager()" 2>/dev/null

else
    # Runs my Xinit (re)starter loop as a daemon
    /sbin/start-stop-daemon \
        --background --quiet --start \
        --pidfile /var/run/ndm --make-pidfile \
        --startas "$0" DAEMON

fi


