Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # checkqueue.py
- while True:
- check_queue()
- do_something()
- # keepalivescript.sh
- if processidfile exists:
- if processid is running:
- exit, all ok
- run checkqueue.py
- write processid to processidfile
- # crontab
- */5 * * * * /path/to/keepalivescript.sh
- until myserver; do
- echo "Server 'myserver' crashed with exit code $?. Respawning.." >&2
- sleep 1
- done
- lf = open('/tmp/script.lock','w')
- if(fcntl.flock(lf, fcntl.LOCK_EX|fcntl.LOCK_NB) != 0):
- sys.exit('other instance already running')
- lf.write('%dn'%os.getpid())
- lf.flush()
- if [ `flock -xn /tmp/script.lock -c 'echo 1'` ]; then
- echo 'it's not running'
- restart.
- else
- echo -n 'it's already running with PID '
- cat /tmp/script.lock
- fi
- if ! test -f $PIDFILE || ! psgrep `cat $PIDFILE`; then
- restart_process
- # Write PIDFILE
- echo $! >$PIDFILE
- fi
- while 1
- do
- /your/script
- sleep 1
- done
- while 1
- do
- /your/script
- sleep 1
- done
- pid=`jps -v | grep $INSTALLATION | awk '{print $1}'`
- echo $INSTALLATION found at PID $pid
- while [ -e /proc/$pid ]; do sleep 0.1; done
Add Comment
Please, Sign In to add comment