8 # NOTE: Eventually, there will be one OpenSRF config file format
9 # When this happens, we will only need a single OPT_CONFIG variable
13 echo "usage: $0 -d <pid_dir> -p <perl_config> -c <c_config> -a <action>";
15 echo "Actions include:"
16 echo -e "\tstart_router"
17 echo -e "\tstop_router"
18 echo -e "\trestart_router"
19 echo -e "\tstart_perl"
21 echo -e "\trestart_perl"
25 echo -e "\tstart_osrf"
27 echo -e "\trestart_osrf"
30 echo -e "\trestart_all"
36 # ---------------------------------------------------------------------------
37 # Load the command line options and set the global vars
38 # ---------------------------------------------------------------------------
39 while getopts "p:c:a:d:h" flag; do
41 "a") OPT_ACTION="$OPTARG";;
42 "c") OPT_C_CONFIG="$OPTARG";;
43 "p") OPT_PERL_CONFIG="$OPTARG";;
44 "d") OPT_PID_DIR="$OPTARG";;
50 [ -z "$OPT_PID_DIR" ] && OPT_PID_DIR=/tmp;
51 [ -z "$OPT_ACTION" ] && usage;
53 PID_ROUTER="$OPT_PID_DIR/router.pid";
54 PID_OSRF_PERL="$OPT_PID_DIR/osrf_perl.pid";
55 PID_OSRF_C="$OPT_PID_DIR/osrf_c.pid";
59 # ---------------------------------------------------------------------------
60 # Utility code for checking the PID files
61 # ---------------------------------------------------------------------------
68 if [ $action == "start" ]; then
70 if [ -e $pidfile ]; then
72 echo "$item already started : $pid";
75 echo "Starting $item";
78 if [ $action == "stop" ]; then
80 if [ ! -e $pidfile ]; then
81 echo "$item not running";
86 echo "Stopping $item : $pid";
96 # ---------------------------------------------------------------------------
97 # Start / Stop functions
98 # ---------------------------------------------------------------------------
101 function start_router {
102 do_action "start" $PID_ROUTER "OpenSRF Router";
103 opensrf_router $OPT_C_CONFIG router
104 pid=$(ps ax | grep "OpenSRF Router" | grep -v grep | awk '{print $1}')
105 echo $pid > $PID_ROUTER;
109 function stop_router {
110 do_action "stop" $PID_ROUTER "OpenSRF Router";
114 function start_perl {
115 do_action "start" $PID_OSRF_PERL "OpenSRF Perl";
116 perl -MOpenSRF::System="$OPT_PERL_CONFIG" -e 'OpenSRF::System->bootstrap()' &
118 echo $pid > $PID_OSRF_PERL;
124 do_action "stop" $PID_OSRF_PERL "OpenSRF Perl";
130 do_action "start" $PID_OSRF_C "OpenSRF C";
131 opensrf-c $(hostname -f) $OPT_C_CONFIG opensrf;
132 pid=$(ps ax | grep "OpenSRF System-C" | grep -v grep | awk '{print $1}')
133 echo $pid > "$PID_OSRF_C";
138 do_action "stop" $PID_OSRF_C "OpenSRF C";
139 killall -9 opensrf-c # hack for now to force kill all C services
146 # ---------------------------------------------------------------------------
147 # Do the requested action
148 # ---------------------------------------------------------------------------
150 "start_router") start_router;;
151 "stop_router") stop_router;;
152 "restart_router") stop_router; start_router;;
153 "start_perl") start_perl;;
154 "stop_perl") stop_perl;;
155 "restart_perl") stop_perl; start_perl;;
158 "restart_c") stop_c; start_c;;
159 "start_osrf") start_perl; start_c;;
160 "stop_osrf") stop_perl; stop_c;;
161 "restart_osrf") stop_perl; stop_c; start_perl; start_c;;
162 "stop_all") stop_c; stop_perl; stop_router;;
163 "start_all") start_router; start_perl; start_c;;
164 "restart_all") stop_c; stop_perl; stop_router; start_router; start_perl; start_c;;