From 1f534cd8113d24acfff28e2ee17543aa6d220282 Mon Sep 17 00:00:00 2001 From: erickson Date: Mon, 28 Aug 2006 14:16:19 +0000 Subject: [PATCH] init-style script for openils - has code for SIP startup git-svn-id: svn://svn.open-ils.org/ILS/trunk@5732 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- Open-ILS/examples/oils_ctl.sh | 118 ++++++++++++++++++++++++++++++++++ 1 file changed, 118 insertions(+) create mode 100755 Open-ILS/examples/oils_ctl.sh diff --git a/Open-ILS/examples/oils_ctl.sh b/Open-ILS/examples/oils_ctl.sh new file mode 100755 index 0000000000..2e9270d9a8 --- /dev/null +++ b/Open-ILS/examples/oils_ctl.sh @@ -0,0 +1,118 @@ +#!/bin/bash + +OPT_ACTION="" +OPT_SIP_CONFIG="" +OPT_PID_DIR="" +SIP_DIR="/opt/SIP/SIPServer"; + +# --------------------------------------------------------------------------- +# Make sure we're running as the correct user +# --------------------------------------------------------------------------- +[ $(whoami) != 'opensrf' ] && echo 'Must run as user "opensrf"' && exit; + + +function usage { + echo ""; + echo "usage: $0 -d -s -a "; + echo ""; + echo "Actions include:" + echo -e "\tstart_sip" + echo -e "\tstop_sip" + echo -e "\trestart_sip" + echo ""; + exit; +} + + +# --------------------------------------------------------------------------- +# Load the command line options and set the global vars +# --------------------------------------------------------------------------- +while getopts "a:d:s:" flag; do + case $flag in + "a") OPT_ACTION="$OPTARG";; + "s") OPT_SIP_CONFIG="$OPTARG";; + "d") OPT_PID_DIR="$OPTARG";; + "h"|*) usage;; + esac; +done + + +[ -z "$OPT_PID_DIR" ] && OPT_PID_DIR=/tmp; +[ -z "$OPT_ACTION" ] && usage; + +PID_SIP="$OPT_PID_DIR/oils_sip.pid"; + + +# --------------------------------------------------------------------------- +# Utility code for checking the PID files +# --------------------------------------------------------------------------- +function do_action { + + action="$1"; + pidfile="$2"; + item="$3"; + + if [ $action == "start" ]; then + + if [ -e $pidfile ]; then + pid=$(cat $pidfile); + echo "$item already started : $pid"; + return 0; + fi; + echo "Starting $item"; + fi; + + if [ $action == "stop" ]; then + + if [ ! -e $pidfile ]; then + echo "$item not running"; + return 0; + fi; + + pid=$(cat $pidfile); + echo "Stopping $item : $pid"; + kill -s INT $pid; + rm -f $pidfile; + + fi; + + return 0; +} + + +# --------------------------------------------------------------------------- +# Start / Stop functions +# --------------------------------------------------------------------------- + + +function start_sip { + do_action "start" $PID_SIP "OILS SIP Server"; + DIR=$(pwd); + cd $SIP_DIR; + nohup perl SIPServer.pm "$OPT_SIP_CONFIG" & + pid=$!; + cd $DIR; + ps ax | grep "$pid"; + echo $pid > $PID_SIP; + return 0; +} + +function stop_sip { + do_action "stop" $PID_SIP "OILS SIP Server"; + return 0; +} + + + +# --------------------------------------------------------------------------- +# Do the requested action +# --------------------------------------------------------------------------- +case $OPT_ACTION in + "start_sip") start_sip;; + "stop_sip") stop_sip;; + "restart_sip") stop_sip; start_sip;; + *) usage;; +esac; + + + -- 2.43.2