]> git.evergreen-ils.org Git - Evergreen.git/blob - OpenSRF/bin/opensrf_all
module now dies with a message if bootstrap_client has not been called
[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 OPENSRFC="1";
40
41 #JSERVERSOCK="$PREFIX/var/sock/jserver.sock";   # jabber server socket file 
42 #JSERVERLOG="$LOGDIR/jserver.log" # jabber server log 
43 JSERVERPORT=5222;                                               # jabber server port 
44 #JSERVERLEVEL=3; # can be 1-4, 4 is the highest
45 #JSERVERIP="*"; # can be "*" or a specific local IP address
46 # --------------------------------------------------------------------------
47 # --------------------------------------------------------------------------
48
49 JSERVERBIN="chopchop" 
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 function usage { echo "$0 [ start | stop | restart | restartforce ]"; }
58
59
60 function startJserver {
61
62         ACTIVE=$(netstat -an | grep $JSERVERPORT);
63         
64         if [ -z "$1" ]; then
65                 if [ ! -z "$ACTIVE" ]; then
66         
67                         echo "Port $JSERVERPORT is busy. Waiting 60 seconds for the port to clear up..."
68         
69                         for ((i=0; i!= 60; i++)) {
70                                 ACTIVE=$(netstat -an | grep $JSERVERPORT);
71                                 [ -z "$ACTIVE" ] && break; 
72                                 echo -n "+";
73                                 sleep 1;
74                         }
75                         echo "";
76                         ACTIVE=$(netstat -an | grep $JSERVERPORT);
77                         [ ! -z "$ACTIVE" ] && fail "Port $JSERVERPORT is busy...exiting";
78                 fi;
79         fi;
80         
81         "$BINDIR/$JSERVERBIN" "$ETCDIR/opensrf_core.xml" "chopchop"; 
82 }
83
84
85 function startRouter {
86         "$BINDIR/opensrf_router" "$ETCDIR/opensrf_core.xml" "router"
87 }
88
89 function startOpenSRF {
90
91         "$BINDIR/opensrf_ctl" start "$BOOTSTRAP";
92
93         if [ ! -z "$OPENSRFC" ]; then
94                 echo "Starting OpenSRF-C...";
95                 # localhost will need to be changed...
96                 "$BINDIR/opensrf-c" $(hostname -f) "$ETCDIR//opensrf_core.xml" "opensrf"
97                 echo "OpenSRF-C started OK";
98         fi
99 }
100
101
102 function makeMeGo {
103         
104         i=$(whoami) && [ "$i" != "opensrf" ] && echo "Must be run as user 'opensrf'.  Exiting..." && exit;
105         
106         if [ ! -z "$JSERVER" ]; then
107                 echo "Starting Chop Chop, Jabber (jserver-c)...";
108                 startJserver $1;
109                 echo "Chop Chop started OK";
110         fi
111
112         sleep 1;
113
114         if [ ! -z "$ROUTER" ]; then
115                 echo "Starting router...";
116                 startRouter;
117                 echo "Router started OK";
118         fi
119
120         sleep 1;
121
122         if [ ! -z "$OPENSRF" ]; then
123                 echo "Starting OpenSRF...";
124                 startOpenSRF;
125                 echo "OpenSRF started OK";
126         fi
127
128         return 0;
129 }
130
131
132 function stopMe {
133
134         echo "Stopping OpenSRF...";
135         "$BINDIR/opensrf_ctl" stop;
136         killall -9 opensrf-c;
137         sleep 1;
138         
139         echo "Stopping The Router...";
140         killall -9 "opensrf_router"
141         
142         sleep 1;
143         
144         echo "Stopping Chop Chop...";
145         killall -9 chopchop;
146         return 0;
147 }
148
149
150
151 [ "$1" = "stop" ] && stopMe && exit;
152 [ "$1" = "restart" ] && stopMe && makeMeGo && exit;
153 [ "$1" = "restartforce" ] && stopMe && makeMeGo 1 && exit;
154 [ "$1" = "start" ] && makeMeGo && exit;
155
156
157 usage;