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.
18 # ---------------------------------------------------------------------------
19 # Make sure we're running as the correct user
20 # ---------------------------------------------------------------------------
21 [ $(whoami) != 'opensrf' ] && echo 'Must run as user "opensrf"' && exit;
26 echo "usage: $0 [OPTION]... -c <c_config> -a <action>";
28 echo "Mandatory parameters:";
29 echo -e " -a\t\taction to perform";
31 echo "Optional parameters:";
32 echo -e " -c\t\tfull path to C configuration file (opensrf_core.xml)";
33 echo -e " -d\t\tstore PID files in this directory";
34 echo -e " -l\t\taccept 'localhost' as the fully-qualified domain name";
36 echo "Actions include:";
37 echo -e "\tstart_router"
38 echo -e "\tstop_router"
39 echo -e "\trestart_router"
40 echo -e "\tstart_perl"
42 echo -e "\trestart_perl"
46 echo -e "\tstart_osrf"
48 echo -e "\trestart_osrf"
51 echo -e "\trestart_all"
54 echo " $0 -a restart_all";
55 echo " $0 -l -c opensrf_core.xml -a restart_all";
60 # Get root directory of this script
67 if [ -z "$BASEDIR" ] && [ -n "$p" ]; then
77 # ---------------------------------------------------------------------------
78 # Load the command line options and set the global vars
79 # ---------------------------------------------------------------------------
80 while getopts "a:d:c:lh" flag; do
82 "a") OPT_ACTION="$OPTARG";;
83 "c") OPT_CONFIG="$OPTARG";;
84 "d") OPT_PID_DIR="$OPTARG";;
85 "l") export OSRF_HOSTNAME="localhost";;
90 OSRF_CONFIG=`find $BASEDIR -name osrf_config`
92 [ -z "$OPT_CONFIG" ] && OPT_CONFIG=`$OSRF_CONFIG --sysconfdir`/opensrf_core.xml;
93 if [ ! -r "$OPT_CONFIG" ]; then
94 echo "Please specify the location of the opensrf_core.xml file using the -c flag";
97 [ -z "$OPT_PID_DIR" ] && OPT_PID_DIR=`$OSRF_CONFIG --localstatedir`/run;
98 [ -z "$OPT_ACTION" ] && usage;
100 PID_ROUTER="$OPT_PID_DIR/router.pid";
101 PID_OSRF_PERL="$OPT_PID_DIR/osrf_perl.pid";
102 PID_OSRF_C="$OPT_PID_DIR/osrf_c.pid";
105 # ---------------------------------------------------------------------------
106 # Utility code for checking the PID files
107 # ---------------------------------------------------------------------------
114 if [ $action == "start" ]; then
116 if [ -e $pidfile ]; then
118 echo "$item already started : $pid";
121 echo "Starting $item";
124 if [ $action == "stop" ]; then
126 if [ ! -e $pidfile ]; then
127 echo "$item not running";
132 echo "Stopping $item process $pid..."
143 # ---------------------------------------------------------------------------
144 # Start / Stop functions
145 # ---------------------------------------------------------------------------
148 function start_router {
149 do_action "start" $PID_ROUTER "OpenSRF Router";
150 opensrf_router $OPT_CONFIG routers
151 pid=$(ps ax | grep "OpenSRF Router" | grep -v grep | awk '{print $1}')
152 echo $pid > $PID_ROUTER;
156 function stop_router {
157 do_action "stop" $PID_ROUTER "OpenSRF Router";
161 function start_perl {
162 echo "Starting OpenSRF Perl";
163 opensrf-perl.pl --verbose --pid-dir $OPT_PID_DIR \
164 --config $OPT_CONFIG --action start_all --settings-startup-pause 3
169 echo "Stopping OpenSRF Perl";
170 opensrf-perl.pl --verbose --pid-dir $OPT_PID_DIR --config $OPT_CONFIG --action stop_all
177 if [ "_$host" == "_" ]; then
178 host=$(perl -MNet::Domain=hostfqdn -e 'print hostfqdn()');
181 do_action "start" $PID_OSRF_C "OpenSRF C (host=$host)";
182 opensrf-c $host $OPT_CONFIG opensrf;
183 pid=$(ps ax | grep "OpenSRF System-C" | grep -v grep | awk '{print $1}')
184 echo $pid > "$PID_OSRF_C";
189 do_action "stop" $PID_OSRF_C "OpenSRF C";
196 # ---------------------------------------------------------------------------
197 # Do the requested action
198 # ---------------------------------------------------------------------------
200 "start_router") start_router;;
201 "stop_router") stop_router;;
202 "restart_router") stop_router; start_router;;
203 "start_perl") start_perl;;
204 "stop_perl") stop_perl;;
205 "restart_perl") stop_perl; start_perl;;
208 "restart_c") stop_c; start_c;;
209 "start_osrf") start_perl; start_c;;
210 "stop_osrf") stop_perl; stop_c;;
211 "restart_osrf") stop_perl; stop_c; start_perl; start_c;;
212 "stop_all") stop_c; stop_perl; stop_router;;
213 "start_all") start_router; start_perl; start_c;;
214 "restart_all") stop_c; stop_perl; stop_router; start_router; start_perl; start_c;;