#!/bin/sh
#
# Glasnost
# By: Odile Bnassy <obenassy@entrouvert.com>
#     Thierry Dulieu <tdulieu@easter-eggs.com>
#     Frdric Pters <fpeters@theridion.com>
#     Benjamin Poussin <poussin@codelutin.com>
#     Emmanuel Raviart <eraviart@entrouvert.com>
#     Emmanuel Saracco <esaracco@easter-eggs.com>
#
# Copyright (C) 2000, 2001 Easter-eggs & Emmanuel Raviart
# Copyright (C) 2002 Odile Bnassy, Code Lutin, Thierry Dulieu, Easter-eggs,
#     Entr'ouvert, Frdric Pters, Benjamin Poussin, Emmanuel Raviart,
#     Emmanuel Saracco & Thridion
# Copyright (C) 2003 Odile Bnassy, Code Lutin, Thierry Dulieu, Easter-eggs,
#     Entr'ouvert, Ouvaton, Frdric Pters, Benjamin Poussin, Rodolphe
#     Quideville, Emmanuel Raviart, Emmanuel Saracco, Thridion & Vecam
#
# 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
# GNU General Public License 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., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.

SERVERSDIR=/usr/lib/glasnost/servers

SERVERS="Dispatcher \
         Gateway \
         AccountsServer \
         AppointmentsServer \
         ArticlesServer \
         AtomsServer \
         AuthenticationLdapServer \
         AuthenticationPamServer \
         AuthenticationServer \
         BallotsServer \
         BooksServer \
         BrevesServer \
         Cache \
         CardsServer \
         CommentsServer \
         ContactInfosServer \
         ContactsServer \
         DirectoriesServer \
         ElectionsServer \
         EventsServer \
         FunctionCallsServer \
         GradesServer \
         GroupsServer \
         FIInitiativesServer \
         InitiativesServer \
         LedgersServer \
         MonitoringsServer \
         OperationsServer \
         OrganizationsServer \
         PageNamesServer \
         PELActionsServer \
         PELBilansServer \
         PeopleServer \
         PreferencesServer \
         RecordsServer \
         RubricsServer \
         SessionsServer \
         SkillDemandsServer \
         SkillOffersServer \
         SystemFilesServer \
         TasksServer \
         TranslationsServer \
         UploadFilesServer \
         VirtualHostsServer \
         VotesServer \
         WorkflowsServer"

start () {
    for SERV in $SERVERS
      do
      $SERVERSDIR/$SERV/$SERV.py
      if [ "$SERV" = "Dispatcher" ]; then
	  sleep 5
      fi
    done
    echo "Glasnost started. Don't forget to reload Apache."
}
 
stop () {
    for SERV in $SERVERS
      do
      pid=`ps xawww | grep python |grep "$SERVERSDIR/$SERV/$SERV.py" |sed -e "s/^ *//" |cut -f1 -d' '|tr '\n' ' '`
      if [ -n "$pid" ]; then
	  kill $pid
      fi
    done
}
 
ACTION=${1:-default}

if [ "$ACTION" = default ]; then
    ACTION=`basename $0 |cut -f2 -d'-'`
fi
  
case "$ACTION" in
    start)
        start
        ;;   
    stop)      
        stop 
        ;;   
    restart)   
        stop 
        sleep 20
        start   
        ;;      
    *)
        cat << EOF
Usage: $0 [start|stop|restart]
EOF
        ;;
esac
