-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e3a7508
commit 8e31dc4
Showing
2 changed files
with
30 additions
and
7 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
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}') | ||
maintenance_time={{ maintenance_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_last_time ]]; then | ||
if [ "$current_availability_zone" == "1a" ]; 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" == "1b" ]; 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" == "1c" ]; 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 | ||
|