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=`which osrf_config`
91 [ -z "$OSRF_CONFIG" ] && OSRF_CONFIG=`find $BASEDIR -name osrf_config`
93 [ -z "$OPT_CONFIG" ] && OPT_CONFIG=`$OSRF_CONFIG --sysconfdir`/opensrf_core.xml;
94 if [ ! -r "$OPT_CONFIG" ]; then
95 echo "Please specify the location of the opensrf_core.xml file using the -c flag";
98 [ -z "$OPT_PID_DIR" ] && OPT_PID_DIR=`$OSRF_CONFIG --localstatedir`/run;
99 [ -z "$OPT_ACTION" ] && usage;
101 PID_ROUTER="$OPT_PID_DIR/router.pid";
102 PID_OSRF_PERL="$OPT_PID_DIR/osrf_perl.pid";
103 PID_OSRF_C="$OPT_PID_DIR/osrf_c.pid";
106 # ---------------------------------------------------------------------------
107 # Utility code for checking the PID files
108 # ---------------------------------------------------------------------------
115 if [ $action == "start" ]; then
117 if [ -e $pidfile ]; then
119 echo "$item already started : $pid";
122 echo "Starting $item";
125 if [ $action == "stop" ]; then
127 if [ ! -e $pidfile ]; then
128 echo "$item not running";
133 echo "Stopping $item process $pid..."
144 # ---------------------------------------------------------------------------
145 # Start / Stop functions
146 # ---------------------------------------------------------------------------
149 function start_router {
150 do_action "start" $PID_ROUTER "OpenSRF Router";
151 opensrf_router $OPT_CONFIG routers
152 pid=$(ps ax | grep "OpenSRF Router" | grep -v grep | awk '{print $1}')
153 echo $pid > $PID_ROUTER;
157 function stop_router {
158 do_action "stop" $PID_ROUTER "OpenSRF Router";
162 function start_perl {
163 echo "Starting OpenSRF Perl";
164 opensrf-perl.pl --verbose --pid-dir $OPT_PID_DIR \
165 --config $OPT_CONFIG --action start_all --settings-startup-pause 3
170 echo "Stopping OpenSRF Perl";
171 opensrf-perl.pl --verbose --pid-dir $OPT_PID_DIR --config $OPT_CONFIG --action stop_all
178 if [ "_$host" == "_" ]; then
179 host=$(perl -MNet::Domain=hostfqdn -e 'print hostfqdn()');
182 do_action "start" $PID_OSRF_C "OpenSRF C (host=$host)";
183 opensrf-c $host $OPT_CONFIG opensrf;
184 pid=$(ps ax | grep "OpenSRF System-C" | grep -v grep | awk '{print $1}')
185 echo $pid > "$PID_OSRF_C";
190 do_action "stop" $PID_OSRF_C "OpenSRF C";
197 # ---------------------------------------------------------------------------
198 # Do the requested action
199 # ---------------------------------------------------------------------------
201 "start_router") start_router;;
202 "stop_router") stop_router;;
203 "restart_router") stop_router; start_router;;
204 "start_perl") start_perl;;
205 "stop_perl") stop_perl;;
206 "restart_perl") stop_perl; start_perl;;
209 "restart_c") stop_c; start_c;;
210 "start_osrf") start_perl; start_c;;
211 "stop_osrf") stop_perl; stop_c;;
212 "restart_osrf") stop_perl; stop_c; start_perl; start_c;;
213 "stop_all") stop_c; stop_perl; stop_router;;
214 "start_all") start_router; start_perl; start_c;;
215 "restart_all") stop_c; stop_perl; stop_router; start_router; start_perl; start_c;;