Guest User

Untitled

a guest
Jun 23rd, 2018
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.28 KB | None | 0 0
  1. #!/bin/sh
  2. # Copyright 2010 Lekensteyn
  3. # This script is public domain and comes with NO WARRANTY of any kind
  4. #
  5. # Events handler (handles build queue, attacks, etc)
  6. if test `id -u` -eq 0;then
  7. sudo -u nobody -- "$0"
  8. exit
  9. fi
  10. running=true
  11. trap 'running=false' 1 2 3 15
  12. cd "$(dirname "$0")/.."
  13. BASEDIR="`pwd`"
  14. PIDFILE="$BASEDIR/tmp/event_second.pid"
  15. killed=
  16. # if a pidfile still exist (unclean shutdown), kill that pid and wait
  17. # 2 seconds for it to catch our signal
  18. test -f "$PIDFILE" && kill -15 "`cat "$PIDFILE"`" >/dev/null && killed=1
  19. printf $$ > "$PIDFILE"
  20. test -n "$killed" && sleep 2
  21. cd htdocs/welt2/daemons
  22. run(){
  23. test -f "$PIDFILE" || exit 2
  24. sleep 1
  25. if test ! -S "$BASEDIR/tmp/mysql.sock";then
  26. echo 'MySQL is not running.'
  27. return
  28. fi
  29. # start PHP, run build queues, attacks, etc
  30. env -i LD_LIBRARY_PATH="$BASEDIR/lib" "$BASEDIR/php/php" event.php &
  31. pid=$!
  32. # check if we still should run (if we have not been killed)
  33. while $running;do
  34. # is PHP not running anymore? Restart it
  35. if ! kill -0 $pid 2>/dev/null >/dev/null;then
  36. run
  37. return
  38. fi
  39. # and wait a second as we do not have to check realtime
  40. sleep 1
  41. done
  42. # kill PHP
  43. kill -15 $pid 2>/dev/null >/dev/null
  44. }
  45. run
  46. detect_pid=`cat "$PIDFILE"`
  47. test "$detect_pid" = $$ && rm -f "$PIDFILE"
Add Comment
Please, Sign In to add comment