--- /dev/null
+#!/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