]> git.evergreen-ils.org Git - Evergreen.git/blob - OpenSRF/bin/opensrf_all
matching non-letter and non-number
[Evergreen.git] / OpenSRF / 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 # --------------------------------------------------------------------------
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 function usage { echo "$0 [ start | stop | restart ]"; }
57
58
59 function startJserver {
60
61         ACTIVE=$(netstat -an | grep $JSERVERPORT);
62         
63         if [ ! -z "$ACTIVE" ]; then
64
65                 echo "Port $JSERVERPORT is busy. Waiting 60 seconds for the port to clear up..."
66
67                 for ((i=0; i!= 60; i++)) {
68                         ACTIVE=$(netstat -an | grep $JSERVERPORT);
69                         [ -z "$ACTIVE" ] && break; 
70                         echo -n "+";
71                         sleep 1;
72                 }
73                 echo "";
74                 ACTIVE=$(netstat -an | grep $JSERVERPORT);
75                 [ ! -z "$ACTIVE" ] && fail "Port $JSERVERPORT is busy...exiting";
76         fi;
77         
78         rm -f "$JSERVERSOCK";
79         "$BINDIR/$JSERVERBIN" $JSERVERPORT "$JSERVERIP" "$JSERVERSOCK" "$JSERVERLEVEL" "$JSERVERLOG"
80 }
81
82
83 function startRouter {
84         "$BINDIR/opensrf_router" "$ETCDIR/opensrf_core.xml" 
85 }
86
87 function startOpenSRF {
88          "$BINDIR/opensrf_ctl" start "$BOOTSTRAP";
89 }
90
91
92
93 function makeMeGo {
94         
95         if [ ! -z "$JSERVER" ]; then
96                 echo "Starting Chop Chop, Jabber (jserver-c)...";
97                 startJserver;
98                 echo "Chop Chop started OK";
99         fi
100
101         sleep 1;
102
103         if [ ! -z "$ROUTER" ]; then
104                 echo "Starting router...";
105                 startRouter;
106                 echo "Router started OK";
107         fi
108
109         sleep 1;
110
111         if [ ! -z "$OPENSRF" ]; then
112                 echo "Starting OpenSRF...";
113                 startOpenSRF;
114                 echo "OpenSRF started OK";
115         fi
116         return 0;
117                 
118 }
119
120
121 function stopMe {
122
123         echo "Stopping OpenSRF...";
124         "$BINDIR/opensrf_ctl" stop;
125         sleep 1;
126         
127         echo "Stopping The Router...";
128         killall opensrf_router;
129         
130         sleep 1;
131         
132         echo "Stopping Chop Chop...";
133         killall jserver-c;
134         return 0;
135 }
136
137
138
139 [ "$1" = "stop" ] && stopMe && exit;
140 [ "$1" = "restart" ] && stopMe && makeMeGo && exit;
141 [ "$1" = "start" ] && makeMeGo && exit;
142
143
144 usage;