-
Notifications
You must be signed in to change notification settings - Fork 41
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
adding script to auto restart task #6072
Merged
AmitPhulera
merged 37 commits into
dimagi:master
from
pvisweswar:SAAS-14342/autorestart_of_ec2_servers
Jan 31, 2024
Merged
Changes from 15 commits
Commits
Show all changes
37 commits
Select commit
Hold shift + click to select a range
9c76ae8
adding script to auto restart task
pvisweswar 915f345
correcting the syntax
pvisweswar e3a7508
changes in the script
pvisweswar 8e31dc4
updating autoreboot script
pvisweswar 5569179
Delete uptime.sh.j2 file
pvisweswar 9e080a5
updating staging maintainance_window
pvisweswar a79292c
updating the script
pvisweswar f1b78b3
Update autoreboot.sh.j2
pvisweswar 1f5dc67
Update public.yml
pvisweswar 6f32e9e
fixing the script
pvisweswar 8607867
Update public.yml by removing spaces after equal to
pvisweswar 3ff3bd4
Update main.yml with 'when' condition
pvisweswar 827b4bb
change in main.yml file for when condition
pvisweswar 44fe6ae
Update main.yml file
pvisweswar 8b08da5
Update public.yml file
pvisweswar cb5321a
modifying the command in the script
pvisweswar efe717e
changing conditions in the script
pvisweswar 7098d3a
adding script to auto restart task
pvisweswar 101142c
correcting the syntax
pvisweswar 3cebb69
changes in the script
pvisweswar 93f944a
updating autoreboot script
pvisweswar efa7265
Delete uptime.sh.j2 file
pvisweswar 56eed59
updating staging maintainance_window
pvisweswar c47ce35
updating the script
pvisweswar bbbbdad
Update autoreboot.sh.j2
pvisweswar 5e9e99c
Update public.yml
pvisweswar 1a5466b
fixing the script
pvisweswar 4df6cb0
Update public.yml by removing spaces after equal to
pvisweswar ea35a6b
Update main.yml with 'when' condition
pvisweswar 7747219
change in main.yml file for when condition
pvisweswar b86a6ee
Update main.yml file
pvisweswar 7079ebf
Update public.yml file
pvisweswar f83fec2
modifying the command in the script
pvisweswar 367eac7
changing conditions in the script
pvisweswar 5af5861
Merge remote-tracking branch 'dimagi/master' into SAAS-14342/autorest…
pvisweswar 7743f5b
Merge branch 'SAAS-14342/autorestart_of_ec2_servers' of https://githu…
pvisweswar 82b0aaa
updated the crontab to trigger the script on Tuesday, Wednesday, and …
pvisweswar File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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}') | ||
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" == "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 |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This would be more general if you pull of just
a
instead of1a
, because the1
is part of the regionThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
modified the command as suggested above ec2metadata --availability-zone | awk -F'-' '{print $3}' | cut -c2-
It uses cut to remove the character from the output -c, --characters=LIST select only these characters. In our case it pulling of just a from 1a.