Last active
August 14, 2019 04:10
-
-
Save lucwj/083190f1cdf6e46df860e977258c93ca to your computer and use it in GitHub Desktop.
Shell Snippets
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
check_service_completed() { | |
service_name=$1 | |
state=$(docker service ps $service_name | awk 'FNR == 2 {print $6}') | |
if [ "$state" = "no such service: $service_name" ]; then | |
state="Complete" | |
fi | |
if [ "$state" = "Complete" ]; then | |
echo "Y" | |
else | |
echo "N" | |
fi | |
} |
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
for p in "${parts[@]}"; do | |
file=${p} | |
IFS='_' read -r -a segments <<<"$file" | |
m=${segments[0]} | |
deploy_service "$m/$file.yml" | |
done |
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
#!/bin/bash | |
input_file=$1 | |
if [ -z "$input_file" ]; then | |
echo "No file mentioned. Please run 'bash run.sh fileName.txt'" | |
exit 0 | |
fi | |
FILES=() | |
while IFS= read -r line || [[ "$line" ]]; do | |
FILES+=("$line") | |
done <$input_file | |
# Number of items in group | |
g=25 | |
deploy_service() { | |
docker stack deploy -c /root/stacks/vts-import-historical-data/$1 vts-ihs | |
} | |
check_service_completed() { | |
service_name=$1 | |
state=$(docker service ps $service_name | awk 'FNR == 2 {print $6}') | |
if [ "$state" = "no such service: $service_name" ]; then | |
state="Complete" | |
fi | |
if [ "$state" = "Complete" ]; then | |
echo "Y" | |
else | |
echo "N" | |
fi | |
} | |
for ((i = 0; i < ${#FILES[@]}; i += g)); do | |
parts=("${FILES[@]:i:g}") | |
echo "" | |
echo ">> Running: ${parts[*]}" | |
for p in "${parts[@]}"; do | |
file=${p} | |
IFS='_' read -r -a segments <<<"$file" | |
m=${segments[0]} | |
deploy_service "$m/$file.yml" | |
done | |
while true; do | |
check="Y" | |
for p in "${parts[@]}"; do | |
file=${p} | |
service_name="vts-ihs_$file" | |
is_completed=$(check_service_completed $service_name) | |
if [ "$is_completed" = "N" ]; then | |
check="N" | |
break | |
fi | |
done | |
if [ "$check" = "Y" ]; then | |
echo "Done: ${parts[*]}" | |
break | |
fi | |
sleep 5 | |
done | |
done | |
echo "Done!" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Loop in array. 💃