Last active
April 6, 2017 20:29
-
-
Save andypotanin/83910a6477effe3f9e1186784c2a7206 to your computer and use it in GitHub Desktop.
curl -s -H "cache-control:no-cache" -H "pragma:no-cache" "https://gist.githubusercontent.com/andypotanin/83910a6477effe3f9e1186784c2a7206/raw/coreos.cloudinit.sh?v=1" | sudo bash;
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 | |
## | |
## curl -s -H "cache-control:no-cache" -H "pragma:no-cache" "https://gist.githubusercontent.com/andypotanin/83910a6477effe3f9e1186784c2a7206/raw/coreos.cloudinit.sh?v=1" | sudo bash; | |
METADATA_URL="http://169.254.169.254/computeMetadata/" | |
TMPFILE=$(mktemp /tmp/XXXXXX-cloud-init) | |
if [[ $? -ne 0 || ! -f "${TMPFILE}" ]]; then | |
echo "Failed to create temp file for user-data" >&2 | |
exit 1 | |
fi | |
trap "rm -f '${TMPFILE}'" EXIT | |
try_cloudinit() { | |
local id="$1" | |
local url="${METADATA_URL}v1/${id}/attributes/user-data" | |
echo "Trying to fetch $id user-data... from [${url}]" | |
curl --fail --silent --show-error \ | |
-H "X-Google-Metadata-Request: True" \ | |
-o "${TMPFILE}" "${url}" | |
ret=$? | |
if [[ $ret -ne 0 && $ret -ne 22 ]]; then | |
echo "curl failed with error code $ret" >&2 | |
return $ret | |
elif [[ $ret -eq 22 || ! -s "${TMPFILE}" ]]; then | |
echo "$id user-data is missing or empty, skipping" | |
return 0 | |
fi | |
echo ${TMPFILE}; | |
coreos-cloudinit --from-file="${TMPFILE}" | |
return $? | |
} | |
block-until-url "${METADATA_URL}" | |
try_cloudinit project && try_cloudinit instance |
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 | |
while read line; do | |
echo -e '{"hostname":"'$(hostname -s)'","payload":"'$(echo $line | base64)'"}' | curl --output -/dev/null -s -d @- "https://site:bb7baad3eb91b93fe6170baf80fd0794@dori-us-east-1.searchly.com/host-events/raw" | |
done < <(journalctl --follow --output=json) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment