#!/bin/bash # # Simple rc script for controlling the system # Only works on linux because of 'ps' syntax # function usage { echo "usage: $0 [start|stop|restart|status] "; exit; } function startSystem { i=$(whoami) && [ "$i" != "opensrf" ] && echo "Must be run as user 'opensrf'. Exiting..." && exit; case $1 in "start") [ -z "$2" ] && usage; perl -MOpenSRF::System="$2" -e 'OpenSRF::System->bootstrap()' & sleep 5; $0 status; echo; ;; "startprofile") [ -z "$2" ] && usage; OPENSRF_PROFILE=1 perl -MOpenSRF::System="$2" -e 'OpenSRF::System->bootstrap()' & sleep 5; $0 status; echo; ;; "stop") PID=$(ps ax | grep -i "opensrf system" | grep -v grep | awk '{print $1}'); if [ -z "$PID" ]; then echo "OpenSRF System is not running"; exit; else echo "Killing System...$PID"; kill -s INT $PID; fi echo "Done"; ;; "status") PID=$(ps ax | grep -i "opensrf system" | grep -v grep | awk '{print $1}'); if [ -z "$PID" ]; then echo "OpenSRF System is not running"; exit 0; fi echo "OpenSRF System is running"; exit 1; ;; "restart") [ -z "$2" ] && usage; $0 stop; $0 start $2; ;; *) usage; ;; esac } startSystem $*;