checkifup.sh 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. #!/usr/bin/env bash
  2. #FUCKIT=$(ps -C "gdb ./login" -o pid=)
  3. ## This pulls the 1st result Not needed now, but just in case
  4. #FUCKME=${FUCK%%[[:space:]]*}
  5. ####### LOGINSERVER CHECK ########
  6. CURR=$(date +"Date : %m/%d/%Y Time : %I:%M:%S")
  7. FUCKIT=$(pgrep -f "SCREEN -Sdm EQ2Login gdb -ex run ./login")
  8. FUCKME=$(pgrep -f "SCREEN -Sdm EQ2World gdb -ex run ./eq2world")
  9. SERVER=127.0.0.1
  10. PORT=9100
  11. SERVDIR=/home/eq2emu
  12. </dev/tcp/$SERVER/$PORT > /dev/null
  13. if [ "$?" -ne 0 ]; then
  14. echo "[Login] Connection to $SERVER on port $PORT failed"
  15. echo "Killing login server process and restarting. PID of Login was ${FUCKIT}"
  16. kill -9 ${FUCKIT}
  17. cd $SERVDIR
  18. screen -Sdm EQ2Login gdb -ex run ./login
  19. BOOM=$(pgrep -f "SCREEN -Sdm EQ2Login gdb -ex run ./login")
  20. echo "Killed and restarted login, new PID (of Screen Session) is ${BOOM}"
  21. ## Send the date/time this occured to a log
  22. echo "[ $CURR ] We restarted login. Could not connect." >> /var/log/eq2emurestart.log
  23. # exit 1
  24. #fi
  25. #if [ "$?" -eq 1 ]; then
  26. else
  27. echo "[Login] Connection to $SERVER on port $PORT succeeded Nothing to do - Existing PID: ${FUCKIT}"
  28. #test code here
  29. #echo "Your PID For LOGIN is $FUCKIT"
  30. # exit 0
  31. fi
  32. ########## WORLDSERVER CHECK
  33. PORT=9001
  34. #</dev/udp/$SERVER/$PORT > /dev/null
  35. nc -z -u $SERVER $PORT
  36. if [ "$?" -ne 0 ]; then
  37. echo "[World] Connection to $SERVER on port $PORT failed"
  38. echo "Killing world server process and restarting. PID of World was ${FUCKME}"
  39. kill -9 ${FUCKME}
  40. cd $SERVDIR
  41. screen -Sdm EQ2World gdb -ex run ./eq2world
  42. BOOMER=$(pgrep -f "SCREEN -Sdm EQ2World gdb -ex run ./eq2world")
  43. echo "Killed and restarted world, new PID (of Screen Session) is ${BOOMER}"
  44. echo "[ $CURR ] We restarted world. Could not connect." >> /var/log/eq2emurestart.log
  45. exit 1
  46. else
  47. echo "[World] Connection to $SERVER on port $PORT succeeded Nothing to do - Existing PID: ${FUCKME}"
  48. #test code here
  49. #echo "Your PID For LOGIN is $FUCKME"
  50. exit 0
  51. fi