some code cleanup, some unfinished projects, etc.
[OpenSRF.git] / bin / opensrf_all
1 #!/bin/bash
2 # --------------------------------------------------------------------
3 # Copyright (C) 2005  Georgia Public Library Service 
4 # Bill Erickson <highfalutin@gmail.com>
5
6 # This program is free software; you can redistribute it and/or
7 # modify it under the terms of the GNU General Public License
8 # as published by the Free Software Foundation; either version 2
9 # of the License, or (at your option) any later version.
10
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 # GNU General Public License for more details.
15 # --------------------------------------------------------------------
16
17
18 # --------------------------------------------------------------------------
19 # Utility script for starting the jserver (the opensrf jabber server), the
20 # opensrf router, and opensrf proper.
21 # see vars below for ways to alter the behavior and directory locations
22 # --------------------------------------------------------------------------
23
24
25
26 # --------------------------------------------------------------------------
27 # Change to suit
28 # --------------------------------------------------------------------------
29 PREFIX=/openils;
30 ETCDIR="$PREFIX/conf";  # config files are found here
31 LOGDIR="$PREFIX/var/log";       # logs go here
32 BINDIR="$PREFIX/bin";   # executables are found here
33 BOOTSTRAP="$ETCDIR/bootstrap.conf";     # opensrf config is here
34
35 # should these be started? set to "" or nothing to disable them
36 JSERVER="1";
37 ROUTER="1";
38 OPENSRF="1";
39
40 JSERVERSOCK="$PREFIX/var/sock/jserver.sock";    # jabber server socket file 
41 JSERVERLOG="$LOGDIR/jserver.log" # jabber server log 
42 JSERVERPORT=5222;                                               # jabber server port 
43 JSERVERLEVEL=4; # can be 1-4, 4 is the highest
44 ROUTERLOG="$LOGDIR/router.log"  # jabber router log
45 # --------------------------------------------------------------------------
46 # --------------------------------------------------------------------------
47
48 JSERVERBIN="jserver-c" 
49 export LD_LIBRARY_PATH="$PREFIX/lib:$LD_LIBRARY_PATH";
50 export PERL5LIB="$PREFIX/lib/perl5:$PERL5LIB";
51 export PATH="$PREFIX/bin:$PATH";
52
53
54 function fail { echo "$0 exited: $*"; exit 99; }
55
56
57 function startJserver {
58
59         ACTIVE=$(netstat -an | grep $JSERVERPORT);
60         
61         if [ ! -z "$ACTIVE" ]; then
62
63                 echo "Port $JSERVERPORT is busy. Waiting 60 seconds for the port to clear up..."
64
65                 for ((i=0; i!= 60; i++)) {
66                         ACTIVE=$(netstat -an | grep $JSERVERPORT);
67                         [ -z "$ACTIVE" ] && break; 
68                         echo -n "+";
69                         sleep 1;
70                 }
71                 echo "";
72                 ACTIVE=$(netstat -an | grep $JSERVERPORT);
73                 [ ! -z "$ACTIVE" ] && fail "Port $JSERVERPORT is busy...exiting";
74         fi;
75         
76         rm -f "$JSERVERSOCK";
77         "$BINDIR/$JSERVERBIN" $JSERVERPORT "$JSERVERSOCK" "$JSERVERLEVEL" "$JSERVERLOG"
78 }
79
80
81 function startRouter {
82         "$BINDIR/router" "$ETCDIR/router_config.xml" 
83 }
84
85 function startOpenSRF {
86          "$BINDIR/opensrf_ctl" start "$BOOTSTRAP";
87 }
88
89
90
91 function makeMeGo {
92         
93         if [ ! -z "$JSERVER" ]; then
94                 echo "Starting Chop Chop, Jabber (jserver-c)...";
95                 startJserver;
96                 echo "Chop Chop started OK";
97         fi
98
99         sleep 1;
100
101         if [ ! -z "$ROUTER" ]; then
102                 echo "Starting router...";
103                 startRouter;
104                 echo "Router started OK";
105         fi
106
107         sleep 1;
108
109         if [ ! -z "$OPENSRF" ]; then
110                 echo "Starting OpenSRF...";
111                 startOpenSRF;
112                 echo "OpenSRF started OK";
113         fi
114         return 0;
115                 
116 }
117
118
119 function stopMe {
120
121         echo "Stopping OpenSRF...";
122         "$BINDIR/opensrf_ctl" stop;
123         sleep 2;
124         
125         echo "Stopping The Router...";
126         killall router;
127         
128         sleep 2;
129         
130         echo "Stopping Chop Chop...";
131         killall jserver-c;
132         return 0;
133 }
134
135
136
137 [ "$1" = "stop" ] && stopMe && exit;
138 [ "$1" = "restart" ] && stopMe && makeMeGo && exit;
139
140 makeMeGo;
141
142