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 process $pid..."
130 # ---------------------------------------------------------------------------
131 # Start / Stop functions
132 # ---------------------------------------------------------------------------
135 function start_router {
136 do_action "start" $PID_ROUTER "OpenSRF Router";
137 opensrf_router $OPT_CONFIG routers
138 pid=$(ps ax | grep "OpenSRF Router" | grep -v grep | awk '{print $1}')
139 echo $pid > $PID_ROUTER;
143 function stop_router {
144 do_action "stop" $PID_ROUTER "OpenSRF Router";
148 function start_perl {
149 do_action "start" $PID_OSRF_PERL "OpenSRF Perl";
150 perl -MOpenSRF::System="$OPT_CONFIG" -e 'OpenSRF::System->bootstrap()' &
152 pid=$(ps ax | grep "OpenSRF System" | grep -v grep | grep -v "System-C"| awk '{print $1}')
153 echo $pid > $PID_OSRF_PERL;
158 do_action "stop" $PID_OSRF_PERL "OpenSRF Perl";
165 if [ "_$host" == "_" ]; then
166 host=$(perl -MNet::Domain=hostfqdn -e 'print hostfqdn()');
169 do_action "start" $PID_OSRF_C "OpenSRF C (host=$host)";
170 opensrf-c $host $OPT_CONFIG opensrf;
171 pid=$(ps ax | grep "OpenSRF System-C" | grep -v grep | awk '{print $1}')
172 echo $pid > "$PID_OSRF_C";
177 do_action "stop" $PID_OSRF_C "OpenSRF C";
184 # ---------------------------------------------------------------------------
185 # Do the requested action
186 # ---------------------------------------------------------------------------
188 "start_router") start_router;;
189 "stop_router") stop_router;;
190 "restart_router") stop_router; start_router;;
191 "start_perl") start_perl;;
192 "stop_perl") stop_perl;;
193 "restart_perl") stop_perl; start_perl;;
196 "restart_c") stop_c; start_c;;
197 "start_osrf") start_perl; start_c;;
198 "stop_osrf") stop_perl; stop_c;;
199 "restart_osrf") stop_perl; stop_c; start_perl; start_c;;
200 "stop_all") stop_c; stop_perl; stop_router;;
201 "start_all") start_router; start_perl; start_c;;
202 "restart_all") stop_c; stop_perl; stop_router; start_router; start_perl; start_c;;