-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6072 from pvisweswar/SAAS-14342/autorestart_of_ec…
…2_servers adding script to auto restart task
- Loading branch information
Showing
3 changed files
with
52 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
src/commcare_cloud/ansible/roles/devops_scripts/templates/autoreboot.sh.j2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#!/bin/bash | ||
|
||
current_availability_zone=$(ec2metadata --availability-zone | awk -F'-' '{print $3}' | cut -c2-) | ||
maintenance_start_time={{ maintenance_start_time }} | ||
maintenance_end_time={{ maintenance_end_time }} | ||
current_time=$(date +%R) | ||
uptime_days=$(uptime | awk '/days?/ {print $3; next}; {print 0}') | ||
|
||
if [ $uptime_days -ge 90 ] && [[ $current_time > $maintenance_start_time ]] && [[ $current_time < $maintenance_end_time ]]; then | ||
if [ "$current_availability_zone" == "a" ]; then | ||
logger '[Maintenance] Rebooting server as uptime is greater than or equal to ninety days in az:A' | ||
echo "Starting reboot" | ||
shutdown -r +1 | ||
elif [ "$current_availability_zone" == "b" ]; then | ||
logger '[Maintenance] Rebooting server as uptime is greater than or equal to ninety days in az:B' | ||
echo "Starting reboot" | ||
shutdown -r +30 | ||
elif [ "$current_availability_zone" == "c" ]; then | ||
logger '[Maintenance] Rebooting server as uptime is greater than or equal to ninety days in az:C' | ||
echo "Starting reboot" | ||
shutdown -r +60 | ||
fi | ||
fi |