Guest User

Untitled

a guest
Jun 24th, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.05 KB | None | 0 0
  1. # checkqueue.py
  2. while True:
  3. check_queue()
  4. do_something()
  5.  
  6. # keepalivescript.sh
  7. if processidfile exists:
  8. if processid is running:
  9. exit, all ok
  10.  
  11. run checkqueue.py
  12. write processid to processidfile
  13.  
  14. # crontab
  15. */5 * * * * /path/to/keepalivescript.sh
  16.  
  17. until myserver; do
  18. echo "Server 'myserver' crashed with exit code $?. Respawning.." >&2
  19. sleep 1
  20. done
  21.  
  22. lf = open('/tmp/script.lock','w')
  23. if(fcntl.flock(lf, fcntl.LOCK_EX|fcntl.LOCK_NB) != 0):
  24. sys.exit('other instance already running')
  25. lf.write('%dn'%os.getpid())
  26. lf.flush()
  27.  
  28. if [ `flock -xn /tmp/script.lock -c 'echo 1'` ]; then
  29. echo 'it's not running'
  30. restart.
  31. else
  32. echo -n 'it's already running with PID '
  33. cat /tmp/script.lock
  34. fi
  35.  
  36. if ! test -f $PIDFILE || ! psgrep `cat $PIDFILE`; then
  37. restart_process
  38. # Write PIDFILE
  39. echo $! >$PIDFILE
  40. fi
  41.  
  42. while 1
  43. do
  44. /your/script
  45. sleep 1
  46. done
  47.  
  48. while 1
  49. do
  50. /your/script
  51. sleep 1
  52. done
  53.  
  54. pid=`jps -v | grep $INSTALLATION | awk '{print $1}'`
  55. echo $INSTALLATION found at PID $pid
  56. while [ -e /proc/$pid ]; do sleep 0.1; done
Add Comment
Please, Sign In to add comment