3 # This program is free software; you can redistribute it and/or
4 # modify it under the terms of the GNU General Public License
5 # as published by the Free Software Foundation; either version 2
6 # of the License, or (at your option) any later version.
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details.
13 # Strictness to avoid folly
18 exec_prefix=@exec_prefix@
25 # ---------------------------------------------------------------------------
26 # Make sure we're running as the correct user
27 # ---------------------------------------------------------------------------
28 [ $(whoami) != 'opensrf' ] && echo 'Must run as user "opensrf"' && exit;
34 usage: $0 [OPTION]... -c <c_config> -a <action>
39 Optional parameters:";
40 -c full path to C configuration file (opensrf_core.xml)
41 -d store PID files in this directory
42 -l accept 'localhost' as the fully-qualified domain name
66 $0 -l -c opensrf_core.xml -a restart_all
71 # ---------------------------------------------------------------------------
72 # Load the command line options and set the global vars
73 # ---------------------------------------------------------------------------
74 while getopts "a:d:c:lh" flag; do
76 "a") OPT_ACTION="$OPTARG";;
77 "c") OPT_CONFIG="$OPTARG";;
78 "d") OPT_PID_DIR="$OPTARG";;
79 "l") export OSRF_HOSTNAME="localhost";;
84 OSRF_CONFIG="@bindir@/osrf_config"
85 [ ! -f "$OSRF_CONFIG" ] && OSRF_CONFIG=`which osrf_config`
87 [ -z "$OPT_CONFIG" ] && OPT_CONFIG=`$OSRF_CONFIG --sysconfdir`/opensrf_core.xml;
88 if [ ! -r "$OPT_CONFIG" ]; then
89 echo "Please specify the location of the opensrf_core.xml file using the -c flag";
92 [ -z "$OPT_PID_DIR" ] && OPT_PID_DIR=`$OSRF_CONFIG --localstatedir`/run;
93 [ -z "$OPT_ACTION" ] && usage;
95 PID_ROUTER="$OPT_PID_DIR/router.pid";
96 PID_OSRF_PERL="$OPT_PID_DIR/osrf_perl.pid";
97 PID_OSRF_C="$OPT_PID_DIR/osrf_c.pid";
100 # ---------------------------------------------------------------------------
101 # Utility code for checking the PID files
102 # ---------------------------------------------------------------------------
109 if [ $action = "start" ]; then
111 if [ -e $pidfile ]; then
113 echo "$item already started : $pid";
116 echo "Starting $item";
119 if [ $action = "stop" ]; then
121 if [ ! -e $pidfile ]; then
122 echo "$item not running";
127 if [ -n "$pid" ]; then
128 echo "Stopping $item process $pid..."
140 # ---------------------------------------------------------------------------
141 # Start / Stop functions
142 # ---------------------------------------------------------------------------
146 do_action "start" $PID_ROUTER "OpenSRF Router";
147 opensrf_router $OPT_CONFIG routers
148 sleep 2; # give the router procs time to fork and appear in ps
149 pid=$(ps ax | grep "OpenSRF Router" | grep -v grep | awk '{print $1}')
150 echo $pid > $PID_ROUTER;
155 do_action "stop" $PID_ROUTER "OpenSRF Router";
160 [ ! $($OSRF_CONFIG | grep OSRF_PYTHON) ] && return;
161 echo "Starting OpenSRF Python";
163 [ "$OSRF_HOSTNAME" = "localhost" ] && OPT_LOCAL="-l"
164 opensrf.py -d -p $OPT_PID_DIR -f $OPT_CONFIG -a start_all $OPT_LOCAL
169 [ ! $($OSRF_CONFIG | grep OSRF_PYTHON) ] && return;
170 echo "Stopping OpenSRF Python";
172 [ "$OSRF_HOSTNAME" = "localhost" ] && OPT_LOCAL="-l"
173 opensrf.py -p $OPT_PID_DIR -f $OPT_CONFIG -a stop_all $OPT_LOCAL
179 echo "Starting OpenSRF Perl";
180 opensrf-perl.pl --verbose --pid-dir $OPT_PID_DIR \
181 --config $OPT_CONFIG --action start_all --settings-startup-pause 3
186 echo "Stopping OpenSRF Perl";
187 opensrf-perl.pl --verbose --pid-dir $OPT_PID_DIR --config $OPT_CONFIG --action stop_all
194 if [ "_$host" = "_" ]; then
195 host=$(perl -MNet::Domain=hostfqdn -e 'print hostfqdn()');
198 do_action "start" $PID_OSRF_C "OpenSRF C (host=$host)";
199 opensrf-c $host $OPT_CONFIG opensrf "$PID_OSRF_C";
204 do_action "stop" $PID_OSRF_C "OpenSRF C";
211 # ---------------------------------------------------------------------------
212 # Do the requested action
213 # ---------------------------------------------------------------------------
215 "start_router") start_router;;
216 "stop_router") stop_router;;
217 "restart_router") stop_router; start_router;;
218 "start_perl") start_perl;;
219 "stop_perl") stop_perl;;
220 "restart_perl") stop_perl; start_perl;;
221 "start_python") start_python;;
222 "stop_python") stop_python;;
223 "restart_python") stop_python; start_python;;
226 "restart_c") stop_c; start_c;;
227 "start_osrf") start_perl; start_c; start_python;;
228 "stop_osrf") stop_python; stop_c; start_perl;;
229 "restart_osrf") stop_python; stop_c; stop_perl; start_perl; start_c; start_python;;
230 "stop_all") stop_python; stop_c; stop_perl; stop_router;;
231 "start_all") start_router; start_perl; start_c; start_python;;
232 "restart_all") stop_python; stop_c; stop_perl; stop_router; start_router; start_perl; start_c; start_python;;