7 # ---------------------------------------------------------------------------
8 # Make sure we're running as the correct user
9 # ---------------------------------------------------------------------------
10 [ $(whoami) != 'opensrf' ] && echo 'Must run as user "opensrf"' && exit;
15 echo "usage: $0 [OPTION]... -c <c_config> -a <action>";
17 echo "Mandatory parameters:";
18 echo -e " -a\t\taction to perform";
20 echo "Optional parameters:";
21 echo -e " -c\t\tfull path to C configuration file (opensrf_core.xml)";
22 echo -e " -d\t\tstore PID files in this directory";
23 echo -e " -l\t\taccept 'localhost' as the fully-qualified domain name";
25 echo "Actions include:";
26 echo -e "\tstart_router"
27 echo -e "\tstop_router"
28 echo -e "\trestart_router"
29 echo -e "\tstart_perl"
31 echo -e "\trestart_perl"
35 echo -e "\tstart_osrf"
37 echo -e "\trestart_osrf"
40 echo -e "\trestart_all"
43 echo " $0 -a restart_all";
44 echo " $0 -l -c opensrf_core.xml -a restart_all";
49 # Get root directory of this script
56 if [ -z "$BASEDIR" ] && [ -n "$p" ]; then
66 # ---------------------------------------------------------------------------
67 # Load the command line options and set the global vars
68 # ---------------------------------------------------------------------------
69 while getopts "a:d:c:lh" flag; do
71 "a") OPT_ACTION="$OPTARG";;
72 "c") OPT_CONFIG="$OPTARG";;
73 "d") OPT_PID_DIR="$OPTARG";;
74 "l") export OSRF_HOSTNAME="localhost";;
79 [ -z "$OPT_CONFIG" ] && OPT_CONFIG="$BASEDIR/conf/opensrf_core.xml";
80 if [ ! -r "$OPT_CONFIG" ]; then
81 echo "Please specify the location of the opensrf_core.xml file using the -c flag";
84 [ -z "$OPT_PID_DIR" ] && OPT_PID_DIR=/tmp;
85 [ -z "$OPT_ACTION" ] && usage;
87 PID_ROUTER="$OPT_PID_DIR/router.pid";
88 PID_OSRF_PERL="$OPT_PID_DIR/osrf_perl.pid";
89 PID_OSRF_C="$OPT_PID_DIR/osrf_c.pid";
92 # ---------------------------------------------------------------------------
93 # Utility code for checking the PID files
94 # ---------------------------------------------------------------------------
101 if [ $action == "start" ]; then
103 if [ -e $pidfile ]; then
105 echo "$item already started : $pid";
108 echo "Starting $item";
111 if [ $action == "stop" ]; then
113 if [ ! -e $pidfile ]; then
114 echo "$item not running";
119 echo "Stopping $item : $pid";
120 kill -s INT $pid 2> /dev/null;
122 kill -9 $pid 2> /dev/null;
131 # ---------------------------------------------------------------------------
132 # Start / Stop functions
133 # ---------------------------------------------------------------------------
136 function start_router {
137 do_action "start" $PID_ROUTER "OpenSRF Router";
138 opensrf_router $OPT_CONFIG router
139 pid=$(ps ax | grep "OpenSRF Router" | grep -v grep | awk '{print $1}')
140 echo $pid > $PID_ROUTER;
144 function stop_router {
145 do_action "stop" $PID_ROUTER "OpenSRF Router";
149 function start_perl {
150 do_action "start" $PID_OSRF_PERL "OpenSRF Perl";
151 perl -MOpenSRF::System="$OPT_CONFIG" -e 'OpenSRF::System->bootstrap()' &
153 pid=$(ps ax | grep "OpenSRF System" | grep -v grep | grep -v "System-C"| awk '{print $1}')
154 echo $pid > $PID_OSRF_PERL;
159 do_action "stop" $PID_OSRF_PERL "OpenSRF Perl";
166 if [ "_$host" == "_" ]; then
167 host=$(perl -MNet::Domain=hostfqdn -e 'print hostfqdn()');
170 do_action "start" $PID_OSRF_C "OpenSRF C (host=$host)";
171 opensrf-c $host $OPT_CONFIG opensrf;
172 pid=$(ps ax | grep "OpenSRF System-C" | grep -v grep | awk '{print $1}')
173 echo $pid > "$PID_OSRF_C";
178 do_action "stop" $PID_OSRF_C "OpenSRF C";
179 killall -9 opensrf-c # hack for now to force kill all C services
186 # ---------------------------------------------------------------------------
187 # Do the requested action
188 # ---------------------------------------------------------------------------
190 "start_router") start_router;;
191 "stop_router") stop_router;;
192 "restart_router") stop_router; start_router;;
193 "start_perl") start_perl;;
194 "stop_perl") stop_perl;;
195 "restart_perl") stop_perl; start_perl;;
198 "restart_c") stop_c; start_c;;
199 "start_osrf") start_perl; start_c;;
200 "stop_osrf") stop_perl; stop_c;;
201 "restart_osrf") stop_perl; stop_c; start_perl; start_c;;
202 "stop_all") stop_c; stop_perl; stop_router;;
203 "start_all") start_router; start_perl; start_c;;
204 "restart_all") stop_c; stop_perl; stop_router; start_router; start_perl; start_c;;