Advertisement
Guest User

Untitled

a guest
Feb 21st, 2019
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.61 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. # Daemon to monitor mutagen status
  4.  
  5. # If already running, kill before starting again
  6. if [ -f ~/docker-daemon-mutagen.pid ]; then
  7. kill -9 `cat ~/docker-daemon-mutagen.pid` > /dev/null 2>&1
  8. rm ~/docker-daemon-mutagen.pid
  9. fi
  10.  
  11. # Save PID in file
  12. echo $$ > ~/docker-daemon-mutagen.pid
  13.  
  14. # Output status to notify that the daemon has launched
  15. terminal-notifier -sound default \
  16. -title 'Mutagen - Docker' \
  17. -message "Monitoring daemon started" \
  18. -sound ding
  19.  
  20. # Function to detect conflict status
  21. function is_mutagen_conflict_status() {
  22.  
  23. output=`mutagen list`
  24.  
  25. if (echo $output | grep -q "Conflicts"); then
  26. echo 'yes'
  27. elif (echo $output | grep -q "Error"); then
  28. echo 'yes'
  29. elif (echo $output | grep -q "Problem"); then
  30. echo 'yes'
  31. else
  32. echo 'no'
  33. fi
  34.  
  35. }
  36.  
  37. is_conflict=false
  38. fail_count=0
  39.  
  40. # Continuously loop to detect conflicts and output messages on changing status
  41. while :
  42. do
  43. conflictstatus=$(is_mutagen_conflict_status)
  44.  
  45. if [[ $is_conflict = false ]] && [[ $conflictstatus = 'yes' ]]; then
  46.  
  47. fail_count=$((fail_count + 1))
  48.  
  49. if (( $fail_count > 2 )); then
  50.  
  51. terminal-notifier -sound default \
  52. -title 'Mutagen - Docker' \
  53. -subtitle "❌ Conflict detected!" \
  54. -message "Run \`mutagen list\` to troubleshoot" \
  55. -sound basso
  56.  
  57. is_conflict=true
  58.  
  59. fi
  60.  
  61. fi
  62.  
  63. if [[ $is_conflict = true ]] && [[ $conflictstatus = 'no' ]]; then
  64. terminal-notifier -sound default \
  65. -title 'Mutagen - Docker' \
  66. -message "✅ Conflict resolved!" \
  67. -sound ding
  68.  
  69. is_conflict=false
  70.  
  71. fail_count=0
  72. fi
  73.  
  74. # Wait before checking again
  75. sleep 10
  76.  
  77. done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement