document.write('
Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. #!/bin/bash
  2.  
  3. set -u
  4. set -e
  5.  
  6. HOSTNAME="$(bigpipe system hostname show | awk \'{print $6}\')"
  7.  
  8. MAIL_BIN=`which mail`
  9. EMAIL_TO="user@domain.tld"
  10. EMAIL_SUBJECT="$HOSTNAME REBOOT"
  11.  
  12. TIME=`date "+%Y%m%d-%H:%M:%S"`
  13.  
  14. UPTIME_SECONDS="$(cat /proc/uptime | awk \'{printf "%.0f\\n", $1}\')"
  15. MAX_UPTIME="259200"
  16.  
  17. SHUTDOWN_BIN=$(which shutdown)
  18.  
  19. RESULT_FILE=/home/admin/reboot-cron-job-result
  20.  
  21. if [ -e $RESULT_FILE ] ; then
  22.     echo "Found an old $RESULT_FILE, removing..."
  23.     rm -f $RESULT_FILE
  24. fi
  25.  
  26. echo "Starting pre-reboot checks on $HOSTNAME as of $TIME..."
  27. echo "Starting pre-reboot checks on $HOSTNAME as of $TIME..." >> $RESULT_FILE
  28.  
  29. # Check whether current unit is in active or standby mode
  30. if [[ $(bigpipe failover show) == *active* ]]; then
  31.     echo "Unit is active..."
  32.     echo "Unit is active..." >> $RESULT_FILE
  33.     FAILOVER_STATE="ACTIVE"
  34. else
  35.     echo "I\'m standby..."
  36.     echo "I\'m standby..." >> $RESULT_FILE
  37.     FAILOVER_STATE="STANDBY"
  38. # exit 0
  39. fi
  40.  
  41. # Check if peer is alive (ping)
  42. if ping -c 1 -w 5 peer &>/dev/null ; then
  43.     echo "Peer is up..."
  44.     echo "Peer is up..." >> $RESULT_FILE
  45.     PEER_STATE="UP"
  46. else
  47.     echo "Peer is down..."
  48.     echo "Peer is down..." >> $RESULT_FILE
  49.     PEER_STATE="DOWN"
  50. # exit 0
  51. fi
  52.  
  53. # Check uptime
  54. if [ "$UPTIME_SECONDS" -le "$MAX_UPTIME" ] ; then
  55.     echo "Uptime of $UPTIME_SECONDS seconds is less than or equal to the maximum of $MAX_UPTIME seconds"
  56.     echo "Uptime of $UPTIME_SECONDS seconds is less than or equal to the maximum of $MAX_UPTIME seconds" >> $RESULT_FILE
  57.     UPTIME_CHECK="GOOD"
  58. else
  59.     echo "Uptime of $UPTIME_SECONDS seconds is greater than the maxium of $MAX_UPTIME seconds"
  60.     echo "Uptime of $UPTIME_SECONDS seconds is greater than the maxium of $MAX_UPTIME seconds" >> $RESULT_FILE
  61.     UPTIME_CHECK="BAD"
  62. fi
  63.  
  64. # Checking Config Sync Status
  65. if [[ $(bigpipe config sync show) == *Synchronized* ]] ; then
  66.     echo "Active/Standby Configuration is synchronized"
  67.     echo "Active/Standby Configuration is synchronized" >> $RESULT_FILE
  68.     CONFIG_SYNC_STATE="SYNCHRONIZED"
  69. else
  70.     echo "Active/Standby Configuration is NOT synchronised"
  71.     echo "Active/Standby Configuration is NOT synchronised" >> $RESULT_FILE
  72.     CONFIG_SYNC_STATE="UNSYNCHRONIZED"
  73. fi
  74.  
  75.  
  76. MESSAGE="$TIME ## $HOSTNAME is $FAILOVER_STATE unit, peer is $PEER_STATE, config sync is $CONFIG_SYNC_STATE ##"
  77.  
  78. if [[ $FAILOVER_STATE == \'ACTIVE\' && $PEER_STATE == \'UP\' && $UPTIME_CHECK == \'BAD\' ]] ; then
  79.  
  80.     # Run config sync if the configurations are not synchronized, test again after, exit if still unsynch\'d
  81.     if [ $CONFIG_SYNC_STATE == \'UNSYNCHRONIZED\' ] ; then
  82.         echo "Synchronizing the configuration..."
  83.         echo "Synchronizing the configuration..." >> $RESULT_FILE
  84.         bigpipe config sync all
  85.  
  86.         if [[ ! $(bigpipe config sync show) == *Synchronized* ]] ; then
  87.             echo "Configuration still not synchronized, bailing out..."
  88.             echo "Configuration still not synchronized, bailing out..." >> $RESULT_FILE
  89.             exit 0
  90.         fi
  91.         echo "Configuration sync successful..."
  92.         echo "Configuration sync successful..." >> $RESULT_FILE
  93.     fi
  94.  
  95.     echo "$MESSAGE rebooting!! "
  96.     echo "$MESSAGE rebooting!!" >> $RESULT_FILE
  97.     logger -t BIGIP-ADMIN-SCRIPT -p local0.notice "$MESSAGE rebooting!!"
  98.     $MAIL_BIN -s "$EMAIL_SUBJECT" "$EMAIL_TO" < $RESULT_FILE
  99.  
  100.     # reboot
  101.     # shutdown -r now
  102.     $SHUTDOWN_BIN -r now
  103.  
  104.     echo "I would have rebooted but this was a test"
  105.     echo "I would have rebooted but this was a test" >> $RESULT_FILE
  106.     logger -t BIGIP-ADMIN-SCRIPT -p local0.notice "I would have rebooted but this was a test"
  107.  
  108. else
  109.  
  110.     echo "$MESSAGE nothing to do... "
  111.     echo "$MESSAGE nothing to do..." >> $RESULT_FILE
  112.     logger -t BIGIP-ADMIN-SCRIPT -p local0.notice "$MESSAGE doing nothing"
  113.     $MAIL_BIN -s "$EMAIL_SUBJECT" "$EMAIL_TO" < $RESULT_FILE
  114.  
  115. fi
');