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 -d <pid_dir> -c <c_config> -a <action>";
17 echo "Actions include:"
18 echo -e "\tstart_router"
19 echo -e "\tstop_router"
20 echo -e "\trestart_router"
21 echo -e "\tstart_perl"
23 echo -e "\trestart_perl"
27 echo -e "\tstart_osrf"
29 echo -e "\trestart_osrf"
32 echo -e "\trestart_all"
35 echo " $0 -c opensrf_core.xml -a restart_all";
41 # ---------------------------------------------------------------------------
42 # Load the command line options and set the global vars
43 # ---------------------------------------------------------------------------
44 while getopts "c:a:d:h" flag; do
46 "a") OPT_ACTION="$OPTARG";;
47 "c") OPT_CONFIG="$OPTARG";;
48 "d") OPT_PID_DIR="$OPTARG";;
54 [ -z "$OPT_PID_DIR" ] && OPT_PID_DIR=/tmp;
55 [ -z "$OPT_ACTION" ] && usage;
57 PID_ROUTER="$OPT_PID_DIR/router.pid";
58 PID_OSRF_PERL="$OPT_PID_DIR/osrf_perl.pid";
59 PID_OSRF_C="$OPT_PID_DIR/osrf_c.pid";
62 # ---------------------------------------------------------------------------
63 # Utility code for checking the PID files
64 # ---------------------------------------------------------------------------
71 if [ $action == "start" ]; then
73 if [ -e $pidfile ]; then
75 echo "$item already started : $pid";
78 echo "Starting $item";
81 if [ $action == "stop" ]; then
83 if [ ! -e $pidfile ]; then
84 echo "$item not running";
89 echo "Stopping $item : $pid";
90 kill -s INT $pid 2> /dev/null;
92 kill -9 $pid 2> /dev/null;
101 # ---------------------------------------------------------------------------
102 # Start / Stop functions
103 # ---------------------------------------------------------------------------
106 function start_router {
107 do_action "start" $PID_ROUTER "OpenSRF Router";
108 opensrf_router $OPT_CONFIG router
109 pid=$(ps ax | grep "OpenSRF Router" | grep -v grep | awk '{print $1}')
110 echo $pid > $PID_ROUTER;
114 function stop_router {
115 do_action "stop" $PID_ROUTER "OpenSRF Router";
119 function start_perl {
120 do_action "start" $PID_OSRF_PERL "OpenSRF Perl";
121 perl -MOpenSRF::System="$OPT_CONFIG" -e 'OpenSRF::System->bootstrap()' &
123 echo $pid > $PID_OSRF_PERL;
129 do_action "stop" $PID_OSRF_PERL "OpenSRF Perl";
136 if [ "_$host" == "_" ]; then
137 host=$(perl -MNet::Domain=hostfqdn -e 'print hostfqdn()');
140 do_action "start" $PID_OSRF_C "OpenSRF C (host=$host)";
141 opensrf-c $host $OPT_CONFIG opensrf;
142 pid=$(ps ax | grep "OpenSRF System-C" | grep -v grep | awk '{print $1}')
143 echo $pid > "$PID_OSRF_C";
148 do_action "stop" $PID_OSRF_C "OpenSRF C";
149 killall -9 opensrf-c # hack for now to force kill all C services
156 # ---------------------------------------------------------------------------
157 # Do the requested action
158 # ---------------------------------------------------------------------------
160 "start_router") start_router;;
161 "stop_router") stop_router;;
162 "restart_router") stop_router; start_router;;
163 "start_perl") start_perl;;
164 "stop_perl") stop_perl;;
165 "restart_perl") stop_perl; start_perl;;
168 "restart_c") stop_c; start_c;;
169 "start_osrf") start_perl; start_c;;
170 "stop_osrf") stop_perl; stop_c;;
171 "restart_osrf") stop_perl; stop_c; start_perl; start_c;;
172 "stop_all") stop_c; stop_perl; stop_router;;
173 "start_all") start_router; start_perl; start_c;;
174 "restart_all") stop_c; stop_perl; stop_router; start_router; start_perl; start_c;;