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:l:h" flag; do
46 "a") OPT_ACTION="$OPTARG";;
47 "c") OPT_CONFIG="$OPTARG";;
48 "d") OPT_PID_DIR="$OPTARG";;
49 "l") export OSRF_HOSTNAME="localhost";;
55 [ -z "$OPT_PID_DIR" ] && OPT_PID_DIR=/tmp;
56 [ -z "$OPT_ACTION" ] && usage;
58 PID_ROUTER="$OPT_PID_DIR/router.pid";
59 PID_OSRF_PERL="$OPT_PID_DIR/osrf_perl.pid";
60 PID_OSRF_C="$OPT_PID_DIR/osrf_c.pid";
63 # ---------------------------------------------------------------------------
64 # Utility code for checking the PID files
65 # ---------------------------------------------------------------------------
72 if [ $action == "start" ]; then
74 if [ -e $pidfile ]; then
76 echo "$item already started : $pid";
79 echo "Starting $item";
82 if [ $action == "stop" ]; then
84 if [ ! -e $pidfile ]; then
85 echo "$item not running";
90 echo "Stopping $item : $pid";
91 kill -s INT $pid 2> /dev/null;
93 kill -9 $pid 2> /dev/null;
102 # ---------------------------------------------------------------------------
103 # Start / Stop functions
104 # ---------------------------------------------------------------------------
107 function start_router {
108 do_action "start" $PID_ROUTER "OpenSRF Router";
109 opensrf_router $OPT_CONFIG router
110 pid=$(ps ax | grep "OpenSRF Router" | grep -v grep | awk '{print $1}')
111 echo $pid > $PID_ROUTER;
115 function stop_router {
116 do_action "stop" $PID_ROUTER "OpenSRF Router";
120 function start_perl {
121 do_action "start" $PID_OSRF_PERL "OpenSRF Perl";
122 perl -MOpenSRF::System="$OPT_CONFIG" -e 'OpenSRF::System->bootstrap()' &
124 pid=$(ps ax | grep "OpenSRF System" | grep -v grep | grep -v "System-C"| awk '{print $1}')
125 echo $pid > $PID_OSRF_PERL;
130 do_action "stop" $PID_OSRF_PERL "OpenSRF Perl";
137 if [ "_$host" == "_" ]; then
138 host=$(perl -MNet::Domain=hostfqdn -e 'print hostfqdn()');
141 do_action "start" $PID_OSRF_C "OpenSRF C (host=$host)";
142 opensrf-c $host $OPT_CONFIG opensrf;
143 pid=$(ps ax | grep "OpenSRF System-C" | grep -v grep | awk '{print $1}')
144 echo $pid > "$PID_OSRF_C";
149 do_action "stop" $PID_OSRF_C "OpenSRF C";
150 killall -9 opensrf-c # hack for now to force kill all C services
157 # ---------------------------------------------------------------------------
158 # Do the requested action
159 # ---------------------------------------------------------------------------
161 "start_router") start_router;;
162 "stop_router") stop_router;;
163 "restart_router") stop_router; start_router;;
164 "start_perl") start_perl;;
165 "stop_perl") stop_perl;;
166 "restart_perl") stop_perl; start_perl;;
169 "restart_c") stop_c; start_c;;
170 "start_osrf") start_perl; start_c;;
171 "stop_osrf") stop_perl; stop_c;;
172 "restart_osrf") stop_perl; stop_c; start_perl; start_c;;
173 "stop_all") stop_c; stop_perl; stop_router;;
174 "start_all") start_router; start_perl; start_c;;
175 "restart_all") stop_c; stop_perl; stop_router; start_router; start_perl; start_c;;