From 6a0ade2e2c44f88f20615222e00fe052ad5b35a6 Mon Sep 17 00:00:00 2001 From: erickson Date: Tue, 26 Jul 2005 17:08:59 +0000 Subject: [PATCH] more install goodness, fixed random jserver bug added an opensrf_all script to load jserver, router, and opesnrf core git-svn-id: svn://svn.open-ils.org/ILS/trunk@1492 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- Open-ILS/src/Makefile | 13 +- OpenSRF/bin/opensrf_all | 140 +++++++++++++++++++ OpenSRF/examples/bootstrap.conf.example | 16 +++ OpenSRF/src/Makefile | 1 + OpenSRF/src/gateway/gateway.xml.example | 10 +- OpenSRF/src/jserver/jserver-c.c | 5 +- OpenSRF/src/perlmods/OpenSRF/System.pm | 4 +- OpenSRF/src/router/router_config.xml.example | 6 + OpenSRF/src/utils/socket_bundle.c | 14 ++ install.sh | 6 +- 10 files changed, 208 insertions(+), 7 deletions(-) create mode 100755 OpenSRF/bin/opensrf_all diff --git a/Open-ILS/src/Makefile b/Open-ILS/src/Makefile index 8dd4fe79a6..909417f38f 100644 --- a/Open-ILS/src/Makefile +++ b/Open-ILS/src/Makefile @@ -1,6 +1,6 @@ all: -install: perl-install javascript-install web-templates-install string-templates-install storage-bootstrap +install: perl-install javascript-install web-templates-install string-templates-install storage-bootstrap xsl-install JSDIR=$(WEBDIR)/js @@ -11,29 +11,40 @@ marcdumper-install: make -C extras/marcdumper install perl-install: + @echo "Installing Perl modules to $(PERLDIR)" mkdir -p $(PERLDIR) cp -r perlmods/* $(PERLDIR) cp ../examples/openils.xml.example $(ETCDIR) javascript-install: + @echo "Installing javascript to $(JSDIR)" mkdir -p $(JSDIR) cp -r javascript/* $(JSDIR) cp ../../$(OPENSRFDIR)/javascript/JSON.js $(JSDIR)/util/ cp ../../$(OPENSRFDIR)/javascript/md5.js $(JSDIR)/util/ storage-bootstrap: + @echo "Installing cgi's to $(CGIDIR)" mkdir -p $(CGIDIR) cp -r cgi-bin/* $(CGIDIR) ./extras/import/build-oils-db.sh $(DBDRVR) $(DBHOST) $(DBNAME) $(DBUSER) $(DBPW) web-templates-install: + @echo "Installing web templates to $(TEMPLATEDIR)" mkdir -p $(TEMPLATEDIR) cp -r templates/opac $(TEMPLATEDIR) cp -r templates/html $(TEMPLATEDIR) string-templates-install: + @echo "Installing string templates to $(TEMPLATEDIR)" + mkdir -p $(TEMPLATEDIR) cp -r templates/strings $(TEMPLATEDIR) +xsl-install: + @echo "Installing XSL files to $(XSLDIR)" + mkdir -p $(XSLDIR) + cp ../xsl/*.xsl $(XSLDIR) + clean: @echo "Cleaning..." make -C extras clean diff --git a/OpenSRF/bin/opensrf_all b/OpenSRF/bin/opensrf_all new file mode 100755 index 0000000000..2c12c66e13 --- /dev/null +++ b/OpenSRF/bin/opensrf_all @@ -0,0 +1,140 @@ +#!/bin/bash +# -------------------------------------------------------------------- +# Copyright (C) 2005 Georgia Public Library Service +# Bill Erickson + +# 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. +# -------------------------------------------------------------------- + + +# -------------------------------------------------------------------------- +# Utility script for starting the jserver (the opensrf jabber server), the +# opensrf router, and opensrf proper. +# see vars below for ways to alter the behavior and directory locations +# -------------------------------------------------------------------------- + + + +# -------------------------------------------------------------------------- +# Change to suit +# -------------------------------------------------------------------------- +PREFIX=/openils; +ETCDIR="$PREFIX/conf"; # config files are found here +LOGDIR="$PREFIX/var/log"; # logs go here +BINDIR="$PREFIX/bin"; # executables are found here +BOOTSTRAP="$ETCDIR/bootstrap.conf"; # opensrf config is here + +# should these be started? set to "" or nothing to disable them +JSERVER="1"; +ROUTER="1"; +OPENSRF="1"; + +JSERVERSOCK="$PREFIX/var/sock/jserver.sock"; # jabber server socket file +JSERVERLOG="$LOGDIR/jserver.log" # jabber server log +JSERVERPORT=5222; # jabber server port +JSERVERLEVEL=4; # can be 1-4, 4 is the highest +ROUTERLOG="$LOGDIR/router.log" # jabber router log +# -------------------------------------------------------------------------- +# -------------------------------------------------------------------------- + +JSERVERBIN="jserver-c" +export LD_LIBRARY_PATH="$PREFIX/lib:$LD_LIBRARY_PATH"; +export PERL5LIB="$PREFIX/lib/perl5:$PERL5LIB"; +export PATH="$PREFIX/bin:$PATH"; + + +function fail { echo "$0 exited: $*"; exit 99; } + + +function startJserver { + + ACTIVE=$(netstat -an | grep $JSERVERPORT); + + if [ ! -z "$ACTIVE" ]; then + + echo "Port $JSERVERPORT is busy. Waiting 60 seconds for the port to clear up..." + + for ((i=0; i!= 60; i++)) { + ACTIVE=$(netstat -an | grep $JSERVERPORT); + [ -z "$ACTIVE" ] && break; + echo -n "+"; + sleep 1; + } + echo ""; + ACTIVE=$(netstat -an | grep $JSERVERPORT); + [ ! -z "$ACTIVE" ] && fail "Port $JSERVERPORT is busy...exiting"; + fi; + + rm -f "$JSERVERSOCK"; + nohup "$BINDIR/$JSERVERBIN" $JSERVERPORT "$JSERVERSOCK" "$JSERVERLEVEL" "$JSERVERLOG" & +} + + +function startRouter { + nohup "$BINDIR/router" "$ETCDIR/router_config.xml" & +} + +function startOpenSRF { + "$BINDIR/opensrf_ctl" start "$BOOTSTRAP"; +} + + + +function makeMeGo { + + if [ ! -z "$JSERVER" ]; then + echo "Starting Chop Chop, Jabber (jserver-c)..."; + startJserver; + echo "Chop Chop started OK"; + fi + + sleep 1; + + if [ ! -z "$ROUTER" ]; then + echo "Starting router..."; + startRouter; + echo "Router started OK"; + fi + + sleep 1; + + if [ ! -z "$OPENSRF" ]; then + echo "Starting OpenSRF..."; + startOpenSRF; + echo "OpenSRF started OK"; + fi + +} + + +function stopMe { + + echo "Stopping OpenSRF..."; + "$BINDIR/opensrf_ctl" stop; + sleep 2; + + echo "Stopping The Router..."; + killall router; + + sleep 2; + + echo "Stopping Chop Chop..."; + killall jserver-c; +} + + + +[ "$1" = "stop" ] && stopMe && exit; +[ "$1" = "restart" ] && stopMe && makeMeGo && exit; + +makeMeGo; + + diff --git a/OpenSRF/examples/bootstrap.conf.example b/OpenSRF/examples/bootstrap.conf.example index ae6fa250a9..add51209d6 100644 --- a/OpenSRF/examples/bootstrap.conf.example +++ b/OpenSRF/examples/bootstrap.conf.example @@ -3,22 +3,38 @@ # ---------------------------------------------------------- [bootstrap] +# location of the opensrf.xml config file settings_config = /path/to/opensrf.xml + +# log files directory log_dir = /path/to/log +# log level debug = ERROR #debug = INFO #debug = DEBUG #debug = INTERNAL +# the jabber login of the router (changing this will likely cause problems) router_name = router + +# all jabber domains we want our app to connect to list:domains = router1.domain.com, router2.domain.com + +# jabber login username = jabber_username + +# jabber password passwd = jabber_password + +# if port is non-numeric (e.g. /tmp/mysock.sock) then we will attempt to +# connect to the specified string as a unix socket file +# This works with Chop Chop jabber only (opensrf custom jabber server) port = 5222 # -------------------------------------- +# log file names [logs] debug = debug.log error = error.log diff --git a/OpenSRF/src/Makefile b/OpenSRF/src/Makefile index 79592ea60b..0cbe7bbe46 100644 --- a/OpenSRF/src/Makefile +++ b/OpenSRF/src/Makefile @@ -115,6 +115,7 @@ perl-install: install-prep cp -r perlmods/* $(PERLDIR)/ cp ../examples/bootstrap.conf.example $(ETCDIR) cp ../bin/opensrf_ctl $(BINDIR) + cp ../bin/opensrf_all $(BINDIR) cp ../examples/opensrf.xml.example $(ETCDIR) diff --git a/OpenSRF/src/gateway/gateway.xml.example b/OpenSRF/src/gateway/gateway.xml.example index dbe9775b4d..43cebbd54d 100644 --- a/OpenSRF/src/gateway/gateway.xml.example +++ b/OpenSRF/src/gateway/gateway.xml.example @@ -1,19 +1,27 @@ - /path/to/opensrf.xml + INFO + + router + host.example.com + my_jabber_login my_jabber_password 5222 + + /path/to/log/gateway.log diff --git a/OpenSRF/src/jserver/jserver-c.c b/OpenSRF/src/jserver/jserver-c.c index 80e900481b..2b8394144a 100644 --- a/OpenSRF/src/jserver/jserver-c.c +++ b/OpenSRF/src/jserver/jserver-c.c @@ -182,6 +182,9 @@ void _jserver_remove_client_id(jserver* js, int id) { jclient_node* node = js->client; + debug_handler("Searching for jclient to remove with id %d", id); + debug_handler("First node in list has id %d", node->id ); + if(node->id == id) { js->client = node->next; debug_handler("Removing the first jserver client"); @@ -190,11 +193,11 @@ void _jserver_remove_client_id(jserver* js, int id) { return; } - debug_handler("Searching for jclient to remove"); jclient_node* tail_node = node; node = node->next; while(node) { + debug_handler("Checking node %d to remove", node->id); if(node->id == id) { tail_node->next = node->next; debug_handler("Removing a jserver client"); diff --git a/OpenSRF/src/perlmods/OpenSRF/System.pm b/OpenSRF/src/perlmods/OpenSRF/System.pm index eea252bb8c..87d7848539 100644 --- a/OpenSRF/src/perlmods/OpenSRF/System.pm +++ b/OpenSRF/src/perlmods/OpenSRF/System.pm @@ -145,7 +145,7 @@ sub bootstrap { my $apps = $client->config_value("activeapps", "appname"); if(!ref($apps) eq "ARRAY") { $apps = [$apps]; } - if(@$apps == 0) { + if(!defined($apps) || @$apps == 0) { print "No apps to load, exiting..."; return; } @@ -167,7 +167,7 @@ sub bootstrap { my $apps = $client->config_value("activeapps", "appname" ); if(!ref($apps)) { $apps = [$apps]; } - if(@$apps == 0) { + if(!defined($apps) || @$apps == 0) { print "No apps to load, exiting..."; return; } diff --git a/OpenSRF/src/router/router_config.xml.example b/OpenSRF/src/router/router_config.xml.example index c4c11e7d19..f9c90a715e 100644 --- a/OpenSRF/src/router/router_config.xml.example +++ b/OpenSRF/src/router/router_config.xml.example @@ -18,6 +18,11 @@ + + + jabber_server.domain.com 5222 @@ -28,6 +33,7 @@ 5 + /pines/log/router.log diff --git a/OpenSRF/src/utils/socket_bundle.c b/OpenSRF/src/utils/socket_bundle.c index 639f738b69..24ebb49a78 100644 --- a/OpenSRF/src/utils/socket_bundle.c +++ b/OpenSRF/src/utils/socket_bundle.c @@ -299,6 +299,8 @@ int _socket_route_data( if(mgr == NULL) return -1; + int last_failed_id = -1; + /* come back here if someone yanks a socket_node from beneath us */ while(1) { @@ -310,9 +312,20 @@ int _socket_route_data( while(node && (handled < num_active)) { int sock_fd = node->sock_fd; + + if(last_failed_id != -1) { + /* in case it was not removed by our overlords */ + debug_handler("Attempting to remove last_failed_id of %d", last_failed_id); + socket_remove_node( mgr, last_failed_id ); + last_failed_id = -1; + status = -1; + break; + } + /* does this socket have data? */ if( FD_ISSET( sock_fd, read_set ) ) { + debug_handler("Socket %d active", sock_fd); handled++; @@ -327,6 +340,7 @@ int _socket_route_data( /* someone may have yanked a socket_node out from under us...start over with the first socket */ if(status == -1) { + last_failed_id = sock_fd; debug_handler("Backtracking back to start of loop because " "of -1 return code from _socket_handle_client_data()"); } diff --git a/install.sh b/install.sh index acea66d38b..ecfc2ed6be 100755 --- a/install.sh +++ b/install.sh @@ -128,8 +128,9 @@ function runInstall { APACHE2_HEADERS=$APACHE2_HEADERS LIBXML2_HEADERS=$LIBXML2_HEADERS \ BINDIR=$BINDIR LIBDIR=$LIBDIR PERLDIR=$PERLDIR INCLUDEDIR=$INCLUDEDIR \ WEBDIR=$WEBDIR TEMPLATEDIR=$TEMPLATEDIR ETCDIR=$ETCDIR \ - OPENSRFDIR=$OPENSRFDIR OPENILSDIR=$OPENILSDIR EVERGREENDIR=$EVERGREENDIR CIRCRULESDIR=$CIRCRULESDIR\ - CGIDIR=$CGIDIR DBDRVR=$DBDRVR DBHOST=$DBHOST DBNAME=$DBNAME DBUSER=$DBUSER DBPW=$DBPW"; + OPENSRFDIR=$OPENSRFDIR OPENILSDIR=$OPENILSDIR EVERGREENDIR=$EVERGREENDIR \ + CIRCRULESDIR=$CIRCRULESDIR CGIDIR=$CGIDIR DBDRVR=$DBDRVR DBHOST=$DBHOST \ + DBNAME=$DBNAME DBUSER=$DBUSER DBPW=$DBPW XSLDIR=$XSLDIR"; case "$target" in @@ -177,6 +178,7 @@ function runInstall { if installing; then $MAKE -C "$OPENILSDIR" "perl-install"; $MAKE -C "$OPENILSDIR" "string-templates-install"; + $MAKE -C "$OPENILSDIR" "xsl-install"; fi; ;; -- 2.43.2