]> git.evergreen-ils.org Git - OpenSRF.git/blob - bin/opensrf_all
cf6eaabf47b29ebc85cf953be189c7a474ebd10c
[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=3; # can be 1-4, 4 is the highest
44 JSERVERIP="*"; # can be "*" or a specific local IP address
45 ROUTERLOG="$LOGDIR/router.log"  # jabber router log
46 # --------------------------------------------------------------------------
47 # --------------------------------------------------------------------------
48
49 JSERVERBIN="jserver-c" 
50 export LD_LIBRARY_PATH="$PREFIX/lib:$LD_LIBRARY_PATH";
51 export PERL5LIB="$PREFIX/lib/perl5:$PERL5LIB";
52 export PATH="$PREFIX/bin:$PATH";
53
54
55 function fail { echo "$0 exited: $*"; exit 99; }
56
57
58 function startJserver {
59
60         ACTIVE=$(netstat -an | grep $JSERVERPORT);
61         
62         if [ ! -z "$ACTIVE" ]; then
63
64                 echo "Port $JSERVERPORT is busy. Waiting 60 seconds for the port to clear up..."
65
66                 for ((i=0; i!= 60; i++)) {
67                         ACTIVE=$(netstat -an | grep $JSERVERPORT);
68                         [ -z "$ACTIVE" ] && break; 
69                         echo -n "+";
70                         sleep 1;
71                 }
72                 echo "";
73                 ACTIVE=$(netstat -an | grep $JSERVERPORT);
74                 [ ! -z "$ACTIVE" ] && fail "Port $JSERVERPORT is busy...exiting";
75         fi;
76         
77         rm -f "$JSERVERSOCK";
78         "$BINDIR/$JSERVERBIN" $JSERVERPORT "$JSERVERIP" "$JSERVERSOCK" "$JSERVERLEVEL" "$JSERVERLOG"
79 }
80
81
82 function startRouter {
83         "$BINDIR/router" "$ETCDIR/router_config.xml" 
84 }
85
86 function startOpenSRF {
87          "$BINDIR/opensrf_ctl" start "$BOOTSTRAP";
88 }
89
90
91
92 function makeMeGo {
93         
94         if [ ! -z "$JSERVER" ]; then
95                 echo "Starting Chop Chop, Jabber (jserver-c)...";
96                 startJserver;
97                 echo "Chop Chop started OK";
98         fi
99
100         sleep 1;
101
102         if [ ! -z "$ROUTER" ]; then
103                 echo "Starting router...";
104                 startRouter;
105                 echo "Router started OK";
106         fi
107
108         sleep 1;
109
110         if [ ! -z "$OPENSRF" ]; then
111                 echo "Starting OpenSRF...";
112                 startOpenSRF;
113                 echo "OpenSRF started OK";
114         fi
115         return 0;
116                 
117 }
118
119
120 function stopMe {
121
122         echo "Stopping OpenSRF...";
123         "$BINDIR/opensrf_ctl" stop;
124         sleep 2;
125         
126         echo "Stopping The Router...";
127         killall router;
128         
129         sleep 2;
130         
131         echo "Stopping Chop Chop...";
132         killall jserver-c;
133         return 0;
134 }
135
136
137
138 [ "$1" = "stop" ] && stopMe && exit;
139 [ "$1" = "restart" ] && stopMe && makeMeGo && exit;
140
141 makeMeGo;
142
143