Skip to content

Instantly share code, notes, and snippets.

@Pothulapati
Created May 2, 2023 10:57
Show Gist options
  • Save Pothulapati/be074b61deacd11e7a1d94db04b9a963 to your computer and use it in GitHub Desktop.
Save Pothulapati/be074b61deacd11e7a1d94db04b9a963 to your computer and use it in GitHub Desktop.
#!/bin/bash
# script that reads configuration from VM tags using cloud-init
# updates the dragonfly configuration file
# and restarts the dragonfly service
# todo: make this work on GCP, and use the same script for both
# get `df-args` tag
curl http://169.254.169.254/latest/meta-data/tags/instance/df-args > /etc/dragonfly/df-args
# save default configuration if it does not exist
if [ ! -f /etc/dragonfly/df-args.default ]; then
cp /etc/dragonfly/dragonfly.conf /etc/dragonfly/df-args.default
fi
# replace commas with new lines
sed -i 's/,/\n/g' /etc/dragonfly/df-args
# check if this is changed from the previous run
if ! cmp -s /etc/dragonfly/df-args /etc/dragonfly/df-args.prev; then
echo "Instance tags changed, updating configuration"
# take default and add the new args
cat /etc/dragonfly/df-args.default /etc/dragonfly/df-args > /etc/dragonfly/dragonfly.conf
# restart the service
systemctl restart dragonfly.service
# save the current tags
cp /etc/dragonfly/df-args /etc/dragonfly/df-args.prev
else
echo "Instance tags did not change, skipping configuration update"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment