monitor.sh 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. #!/bin/bash
  2. ADDRESS="[324:71e:281a:9ed3::ace]"
  3. PORT="8888"
  4. URI="http://tinyproxy.stats"
  5. ACTION="systemctl restart tinyproxy"
  6. status() {
  7. ./monitor.expect > /dev/null
  8. if [[ $? == "111" ]]; then
  9. return 1
  10. else
  11. return 0
  12. fi
  13. }
  14. ping() {
  15. TMP=/tmp/monitor-bash-file
  16. rm $TMP &> /dev/null
  17. curl -s --proxy $ADDRESS:$PORT $URI > $TMP &
  18. sleep 2
  19. file=$(cat $TMP | grep acetone)
  20. res=0
  21. if [[ $file == "" ]]; then
  22. res=0
  23. else
  24. res=1 # success
  25. fi
  26. rm $TMP &> /dev/null
  27. return $res
  28. }
  29. action() {
  30. $ACTION
  31. if [[ $? == 0 ]]; then
  32. echo Restart success
  33. else
  34. echo Restart failed
  35. fi
  36. }
  37. main() {
  38. cd $(dirname "$0")
  39. socket
  40. result=$?
  41. if [[ $result == 1 ]]; then
  42. echo Socket works!
  43. ping
  44. result=$?
  45. if [[ $result == 1 ]]; then
  46. echo Proxy works!
  47. else
  48. echo Proxy offline...
  49. action
  50. fi
  51. else
  52. echo Socket offline...
  53. action
  54. fi
  55. kill -9 $$ # Завершение во имя убийства фоновых процессов
  56. }
  57. main