I'm trying to use a shell script to start my calibre-server, and to respawn it if it crashes (which it does frequently.)
Here's the script so far:
Code:
#! /bin/bash
# $Author$
# $Date$
# $Header$
# $Id$
# $Locker$
# $Name$
# $RCSfile$
# $Revision$
# $Source$
# $State$
# $Log$
#
# Program: /usr/local/keep-calibre-server-running
# Program Homepage: None
# Author: Russell W. Behne (rwbehne1@gmail.com)
# Author's Homepage: Homepage: http://behne.ddns.net
#
# For use with: calibre-server
# Purpose: To start then respawn calibre-server when it crashes.
# Usage: Call from an entry in /etc/init.d/after.local: /usr/local/keep-calibre-server-running &
instances=`ps ax | grep "calibre-server"| grep -v grep | wc -l`
if [ $instances == 0 ]; then
while true; \
do /usr/bin/calibre-server --daemonize --port 8787 --with-library /home/Calibre/MASTER ; \
done
else
exit 1
fi
It doesn't seem to be working, so I wrote the following script to test to quickly see if the server is running, and how many instances:
Code:
# !/bin/bash
# $Author$
# $Date$
# $Header$
# $Id$
# $Locker$
# $Name$
# $RCSfile$
# $Revision$
# $Source$
# $State$
# $Log$
#
# Program: /usr/local/is-calibre-running
# Program Homepage: None
# Author: Russell W. Behne (rwbehne1@gmail.com)
# Author's Homepage: Homepage: http://behne.ddns.net
#
# For use with: calibre-server respawning script named "keep-calibre-running"
# Purpose: To test to see if calibre-server is running, and how many instances there are.
# Usage: Call from the command line with is-calibre-running
echo Instances of calibre-server running: `ps ax | grep "calibre-server"| grep -v grep | wc -l`
After starting the
keep-calibre-server-running script calibre-server
should be running just 1 instance.
Next, I run the
is-calibre-running script to see what it says, and it tells me that there are multiple instances of the server running (up to about 60!) and the number changes each time I run that script.
This is telling me that for some reason more than one instance is starting, and they are crashing - respawning too fast. I don't understand what's going wrong, or why it's spawning multiple instances, too fast. It should spawn only one instance, then do nothing until the server stops for whatever reason, then it should loop back and respawn only one new instance, in an endless loop, ad nauseaum. Unfortunately the script doesn't seem to be stopping and waiting when it should be.
Can anyone help get this working?