Skip to content

Instantly share code, notes, and snippets.

@marcoceppi
Created June 11, 2015 20:19
Show Gist options
  • Save marcoceppi/d6c44258c9a8719b242e to your computer and use it in GitHub Desktop.
Save marcoceppi/d6c44258c9a8719b242e to your computer and use it in GitHub Desktop.
How to prompt the user on which service to take an action on
#!/bin/bash
to_siege=`action-get service` # could be unit instead, but service seems better
siege_rid=""
rids="$(relation-ids website)"
if [ $(echo $rids | wc -l ) -eq 0 ]; then
action-fail "Siege is not related to anything, can not benchmark nothing"
fi
for rid in "$rids"; do # not sure if rids needs to be quoted...
unit=$(relation-list -r $rid | head -n1)
service=${unit%%/*}
if [ $service == $to_siege ]; then
siege_rid=$rid
break
fi
done
if [ -z "$siege_id" ] && [ $(relation-ids website | wc -l) -gt 1 ]; then
action-fail "Unable to determine which source to siege"
fi
if [ -z "$siege_id" ]; then
siege_id="$rids"
fi
urls=""
for unit in $(relation-list -r $rid); do
urls="$urls\nhttp://$(unit-get -r $rid private-address $unit)"
done
# Write urls to a urls.txt file and use it to hit all heads
# do siege with the URLS.txt set
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment