stop_all
start_all
restart_all
+ smart_clear - Clear all PID files that don't refer to a process
+ clear_pid - Clear all PID files
Examples:
$0 -a restart_all
PID_ROUTER="$OPT_PID_DIR/router.pid";
PID_OSRF_PERL="$OPT_PID_DIR/osrf_perl.pid";
+PID_OSRF_PYTHON="$OPT_PID_DIR/osrf_python.pid";
PID_OSRF_C="$OPT_PID_DIR/osrf_c.pid";
if [ -e $pidfile ]; then
pid=$(cat $pidfile);
- echo "$item already started : $pid";
- return 0;
+ reported=$(ps ax | grep "$item" | grep -v grep | awk '{print $1}' | awk '{ printf "%s ", $0 }')
+
+ if [ "$pid " = "$reported" ]; then
+ echo "$item already started : $pid";
+ return 0;
+ else
+ echo "$item not started, but PID file exists, removing file and starting";
+ rm $pidfile;
+ return 0;
+ fi;
fi;
echo "Starting $item";
fi;
start_python() {
[ ! $($OSRF_CONFIG | grep OSRF_PYTHON) ] && return;
echo "Starting OpenSRF Python";
+
+ if [ -e $PID_OSRF_PYTHON ]; then #If python is started already (or it thinks so).
+ cat << EOF
+Python processes are either already running, or were not correctly shut down.
+Now clearing any stale PID files and restarting Perl processes.
+EOF
+ smart_clear;
+ fi;
+
OPT_LOCAL=""
[ "$OSRF_HOSTNAME" = "localhost" ] && OPT_LOCAL="-l"
for service in `opensrf.py -a list_all $OPT_LOCAL`; do
opensrf.py -p $OPT_PID_DIR -f $OPT_CONFIG -d -a start -s $service $OPT_LOCAL
+ [ "$?" = "0" ] && echo "Python Started" > $PID_OSRF_PYTHON; #Dummy pid file, removed when a proper shutdown happens.
done
return 0;
}
stop_python() {
[ ! $($OSRF_CONFIG | grep OSRF_PYTHON) ] && return;
echo "Stopping OpenSRF Python";
+ [ -e $PID_OSRF_PYTHON ] && rm $PID_OSRF_PYTHON;
OPT_LOCAL=""
[ "$OSRF_HOSTNAME" = "localhost" ] && OPT_LOCAL="-l"
opensrf.py -p $OPT_PID_DIR -f $OPT_CONFIG -a stop_all $OPT_LOCAL
start_perl() {
echo "Starting OpenSRF Perl";
+
+ if [ -e $PID_OSRF_PERL ]; then #If perl is started already (or it thinks so)
+ cat << EOF
+Perl processes are either already running, or were not correctly shut down.
+Now clearing any stale PID files and restarting Perl processes.
+EOF
+ smart_clear;
+ fi;
+
opensrf-perl.pl --verbose --pid-dir $OPT_PID_DIR \
--config $OPT_CONFIG --action start_all --settings-startup-pause 3
+ [ "$?" = "0" ] && echo "Perl Started" > $PID_OSRF_PERL; #Dummy pid file, removed when a proper shutdown happens.
return 0;
}
stop_perl() {
echo "Stopping OpenSRF Perl";
opensrf-perl.pl --verbose --pid-dir $OPT_PID_DIR --config $OPT_CONFIG --action stop_all
+ [ -e $PID_OSRF_PERL ] && rm $PID_OSRF_PERL;
sleep 1;
return 0;
}
stop_c() {
do_action "stop" $PID_OSRF_C "OpenSRF C";
+ [ -e $PID_OSRF_C ] && rm $PID_OSRF_C;
sleep 1;
return 0;
}
+clear_pid() {
+ echo "Clearing PID files...";
+ cd $OPT_PID_DIR;
+ [ 0 -lt ls | wc -l ] && rm -v *.pid;
+ return 0;
+}
+smart_clear() {
+ echo "Smart clearing PID files...";
+ for line in $(find $OPT_PID_DIR -name *.pid -type f)
+ do
+ running="false";
+ for p in $(cat $line)
+ do
+ [ 0 -lt $(ps ax | grep "$p" | grep -v grep | wc -l) ] && running="true";
+ done
+
+ if [ $running = "false" ]; then
+ rm $line;
+ echo "Removing stale PID file: $line";
+ fi;
+ done
+
+ return 0;
+}
# ---------------------------------------------------------------------------
# Do the requested action
"stop_all") stop_python; stop_c; stop_perl; stop_router;;
"start_all") start_router; start_perl; start_c; start_python;;
"restart_all") stop_python; stop_c; stop_perl; stop_router; start_router; start_perl; start_c; start_python;;
+ "clear_pid") clear_pid;;
+ "smart_clear") smart_clear;;
*) usage;;
esac;