System V Evergreen start/stop/status user/ldw/ubuntu_system_v_start_stop_status_scripts
authorLiam Whalen <whalen.ld@gmail.com>
Sat, 8 Mar 2014 00:01:33 +0000 (16:01 -0800)
committerLiam Whalen <whalen.ld@gmail.com>
Sat, 8 Mar 2014 00:01:33 +0000 (16:01 -0800)
These scripts add the ability to start and stop Evergreen via the
command 'service openils start' and 'service openils stop'.  To do this,
place ubuntu-precise/openils in /etc/init.d/ and make sure it has 755
for its permissions.  Then, move ubuntu-precies/start-openils and
ubunut-precies/stop-openils to /usr/local/sbin/ and make sure they have
755 as well.

Finally, give the openils service runlevel priorites.  You can do this
with the following command: 'update-rd.d openils defaults 88 13'

I have tested this with master on Ubunut 12.04.  It is also working,
with modifications on Sitka's 2.4 systems.

Signed-off-by: Liam Whalen <whalen.ld@gmail.com>
Open-ILS/examples/ubuntu-precise/openils [new file with mode: 0755]
Open-ILS/examples/ubuntu-precise/start-openils [new file with mode: 0755]
Open-ILS/examples/ubuntu-precise/stop-openils [new file with mode: 0755]

diff --git a/Open-ILS/examples/ubuntu-precise/openils b/Open-ILS/examples/ubuntu-precise/openils
new file mode 100755 (executable)
index 0000000..ffa3d08
--- /dev/null
@@ -0,0 +1,88 @@
+#!/bin/sh
+
+### BEGIN INIT INFO
+# Provides:          OpenSRF/Evergreen
+# Required-Start:    $local_fs $remote_fs $network $syslog $named
+# Required-Stop:     $local_fs $remote_fs $network $syslog $named
+# Default-Start:     2 3 4 5
+# Default-Stop:      0 1 6
+# Short-Description: Start/Stop OpenSRF
+### END INIT INFO
+
+DAEMON=/openils/bin/osrf_ctl.sh
+OPENILS_PID_DIR=/openils/var/run/opensrf/
+
+test -x $DAEMON || exit 5
+
+COUNT=0
+
+case $1 in
+  start)
+    while [ $COUNT -ne 3 ] 
+    do  
+      EJABBERD_STATUS=`ejabberdctl status`
+      if [ `echo $EJABBERD_STATUS | grep -e "status: started" | wc -l` -eq 1 ] 
+      then
+        echo "ejabberd status: $EJABBERD_STATUS"
+        #stop apache
+        #We are not checking to see if apache is running before stopping it 
+        #because it is not harmful to stop apache when it is not running.
+        #However, if the speed of starting openils is ever an issue then
+        #we should add a check to see if apache is running before stopping it
+        service apache2 stop
+        sleep 2
+        rm -f /srv/openils/var/run/opensrf/*.pid
+        su -c '/usr/local/sbin/start-openils' opensrf
+        sleep 2
+        #start apache
+        service apache2 start
+        break
+      fi  
+      sleep 5
+      COUNT=`expr $COUNT + 1`
+    done
+    ;;  
+  stop)
+    #we do not have to stop apache before stopping openils
+    su -c '/usr/local/sbin/stop-openils' opensrf
+    ;;  
+  restart|force-reload)
+    $0 stop && sleep 2 && $0 start
+      ;;  
+  try-restart)
+    if $0 status >/dev/null; then
+      $0 restart
+    else
+      exit 0
+    fi  
+    ;;  
+  reload)
+    exit 3
+    ;;  
+  status)
+    echo "Status of openils"
+    LIST_OF_OPENILS_PIDS=`ls $OPENILS_PID_DIR`;
+    for openils_pid_file in $LIST_OF_OPENILS_PIDS
+    do  
+      #check that the pid is running
+      PID=`cat $OPENILS_PID_DIR$openils_pid_file`
+      EVERYTHING_RUNNING=1;
+      if [ -n "$PID" ]; then
+        echo "$openils_pid_file is running (pid $PID)."
+      else
+        echo "$openils_pid_file is NOT running."
+        $EVERYTHING_RUNNING=0
+      fi  
+    done
+
+    if [ $EVERYTHING_RUNNING -eq 1 ]; then
+      exit 0
+    else
+      exit 1
+    fi  
+    ;;  
+  *)  
+    echo "Usage: $0 {start|stop|restart|try-restart|force-reload|status}"
+    exit 2
+    ;;  
+esac
diff --git a/Open-ILS/examples/ubuntu-precise/start-openils b/Open-ILS/examples/ubuntu-precise/start-openils
new file mode 100755 (executable)
index 0000000..a888efa
--- /dev/null
@@ -0,0 +1,5 @@
+#!/bin/bash
+export PATH=/openils/bin:$PATH
+export PERL5LIB=/usr/local/share/perl:$PERL5LIB
+/openils/bin/osrf_ctl.sh -l -a start_all
+exit 0
diff --git a/Open-ILS/examples/ubuntu-precise/stop-openils b/Open-ILS/examples/ubuntu-precise/stop-openils
new file mode 100755 (executable)
index 0000000..649d535
--- /dev/null
@@ -0,0 +1,5 @@
+#!/bin/bash
+export PATH=/openils/bin:$PATH
+export PERL5LIB=/usr/local/share/perl:$PERL5LIB
+/openils/bin/osrf_ctl.sh -l -a stop_all
+exit 0