Startup and shutdown scripts
authorJoe Atzberger <atz@esilibrary.com>
Tue, 22 Jun 2010 21:43:53 +0000 (21:43 +0000)
committerThomas Berezansky <tsbere@mvlc.org>
Tue, 22 Jun 2010 21:43:53 +0000 (21:43 +0000)
Adapted from the versions I wrote for Koha SIP

sip_run.sh [new file with mode: 0755]
sip_shutdown.sh [new file with mode: 0755]

diff --git a/sip_run.sh b/sip_run.sh
new file mode 100755 (executable)
index 0000000..f210617
--- /dev/null
@@ -0,0 +1,46 @@
+#!/bin/bash
+# 
+# A sample script for starting SIP.  
+# You probably want to specify new log destinations.
+#
+# Takes 3 optional arguments:
+# ~ SIPconfig.xml file to use
+# ~ file for STDOUT, default ~/sip.out
+# ~ file for STDERR, default ~/sip.err
+#
+# The STDOUT and STDERR files are only for the SIPServer process itself.
+# Actual SIP communication and transaction logs are handled by Syslog.
+#
+# Examples:
+#   sip_run.sh /path/to/SIPconfig.xml
+#   sip_run.sh ~/my_sip/SIPconfig.xml sip_out.log sip_err.log
+
+
+for x in HOME PERL5LIB; do
+       echo $x=${!x}
+       if [ -z ${!x} ] ; then 
+               echo ERROR: $x not defined;
+               exit 1;
+       fi;
+done;
+unset x;
+# cd $PERL5LIB/C4/SIP;
+echo;
+echo Running from `pwd`;
+
+sipserver='./SIPServer.pm';
+sipconfig=${1:-`pwd`/SIPconfig.xml};
+outfile=${2:-$HOME/sip.out};
+errfile=${3:-$HOME/sip.err};
+
+if [ ! -r $sipconfig ] ; then
+    echo "ERROR: Required SIP Configuration file not found at '$sipconfig'" >&2;
+    exit 1;
+fi
+if [ ! -r $sipserver ] ; then
+    echo "ERROR: Target SIPServer not found at '$sipserver'" >&2;
+    exit 1;
+fi
+echo "Calling (backgrounded):";
+echo "perl -I./ $sipserver $sipconfig >>$outfile 2>>$errfile";
+perl -I./ $sipserver $sipconfig >>$outfile 2>>$errfile &
diff --git a/sip_shutdown.sh b/sip_shutdown.sh
new file mode 100755 (executable)
index 0000000..60608e0
--- /dev/null
@@ -0,0 +1,19 @@
+#!/bin/bash
+
+[ -r $HOME/.bash_profile ] && $HOME/.bash_profile
+
+# this is brittle: the primary server must have the lowest PPID
+# this is brittle: ps behavior is very platform-specific, only tested on Debian Etch
+
+target="SIPServer";
+PROCPID=$(ps x -o pid,ppid,args --sort ppid | grep "$target" | grep -v grep | head -1 | awk '{print $1}');
+
+if [ ! $PROCPID ] ; then
+    echo "No processes found for $target";
+    exit;
+fi
+
+echo "SIP Processes for this user ($USER):";
+ps x -o pid,ppid,args --sort ppid | grep "$target" | grep -v grep ;
+echo "Killing process #$PROCPID";
+kill $PROCPID;