-
Notifications
You must be signed in to change notification settings - Fork 20
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
restart fetch only when it is idling #548
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
42f55c4
restart fetcfh only when it is idling
FuhuXia 3112c74
update: combine gather + fetch restart logic
nickumia-reisys 67a1bc5
Merge branch 'main' into restart-fetch
nickumia-reisys 503f888
new: use restart-app-instance to restart some instances
nickumia-reisys da0153c
Merge branch 'restart-fetch' of github.com:GSA/catalog.data.gov into …
nickumia-reisys 7f96cdc
fix: typo
nickumia-reisys fe84a8f
fix: script return value
nickumia-reisys 3f0b006
Merge branch 'main' into restart-fetch
jbrown-xentity 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 was deleted.
Oops, something went wrong.
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,47 @@ | ||
#!/bin/bash | ||
|
||
# Custom script to ensure harvester processes are safe to restart | ||
# Based on | ||
# - https://github.com/GSA/data.gov/issues/3796 | ||
# - https://github.com/GSA/data.gov/issues/3962 | ||
|
||
# Input either catalog-gather or catalog-fetch | ||
app_to_restart=$1 | ||
|
||
################### | ||
# Utility Functions | ||
# Get the number of lines in the log (int) | ||
log_count () { cf logs --recent $app_to_restart | wc -l; } | ||
|
||
# Get the time of the last line in the log (int) | ||
current_time=$(date --utc +%s) | ||
log_last_time () { | ||
date --utc --date="$(cf logs --recent $app_to_restart | tail -n 1 | awk '{split($0,time," "); print time[1]}')" +%s | ||
} | ||
|
||
# Restart if CPU usage is < 1 | ||
cpu_restart () { | ||
instances=$(cf app $app_to_restart | grep '^instances:' | sed 's/.*\///') | ||
i=0 | ||
cf app $app_to_restart | tail -n $instances | awk '{ split($4,cpu,"."); print cpu[1]}' | while read -r cpu ; do | ||
if [[ $cpu < 1 ]]; then | ||
cf restart-app-instance $app_to_restart $i | ||
fi | ||
i=$(($i + 1)) | ||
done; | ||
} | ||
|
||
############ | ||
# Main Logic | ||
# Check the age of the last log | ||
# If there are only two lines, there are no logs | ||
if [[ $((`log_count` > 2)) == '1' ]]; then | ||
# if the timestamp is younger than 15 mins from start of script | ||
if [[ $((current_time - `log_last_time` < 900)) == '1' ]]; then | ||
echo "Logs are too new! Not going to restart" | ||
exit 0 | ||
fi | ||
fi | ||
|
||
# if CPU status shows it is not busy, we do the restart | ||
$(cpu_restart) |
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.
where do we get
$cpu
from?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.
The
while read -r cpu
iterates through the previous command and makes the iteration available through thecpu
variable.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.
Thanks! I feel like this line might benefit from a comment explaining the pipes.