Last active
December 14, 2015 23:19
-
-
Save eadasiak/da6c065b5dbd566207a0 to your computer and use it in GitHub Desktop.
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
[Unit] | |
Description=Update master_list for DCOS services | |
[Service] | |
Type=simple | |
StandardOutput=journal | |
StandardError=journal | |
EnvironmentFile=/etc/environment | |
EnvironmentFile=/opt/mesosphere/environment | |
ExecStart=/home/core/mesos-systemd/dcos/util/dcos-gen-masterlist.sh /opt/mesosphere/etc/master_list |
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 | |
# This script uses the IP addresses assigned to the master's autoscaling group to populate the master_list entries. | |
# It should be run from each master via the included systemd units/timers | |
pkg=dcos-gen-masterlist | |
AWS_REGION=$(curl -s http://169.254.169.254/latest/meta-data/placement/availability-zone | sed 's/[a-z]$//') | |
if [ -z "$1" ]; then | |
echo "$pkg: master_list file not specified. Use fully qualified path as an arument (e.g., $pkg /opt/mesosphere/etc/master_list)" | |
exit 1 | |
fi | |
ec2_instance_id=$(curl -s http://169.254.169.254/latest/meta-data/instance-id) | |
ec2_instance_ip=$(curl -s http://169.254.169.254/latest/meta-data/local-ipv4) | |
asg_name=$(docker run behance/utility:latest aws autoscaling describe-auto-scaling-groups --region ${AWS_REGION} \ | |
| jq --raw-output ".[] | map(select(.Instances[].InstanceId | contains(\"$ec2_instance_id\"))) | .[].AutoScalingGroupName") | |
master_list_ips=$(docker run behance/utility:latest aws ec2 describe-instances --region ${AWS_REGION} --instance-ids \ | |
$(docker run behance/utility:latest aws autoscaling describe-auto-scaling-groups --region ${AWS_REGION} --auto-scaling-group-name $asg_name | jq .AutoScalingGroups[0].Instances[].InstanceId | xargs) \ | |
| jq -r '.Reservations[].Instances | map("\\\"" + .NetworkInterfaces[].PrivateIpAddress + "\\\"")[]') | |
output=$(echo \"[${master_list_ips}]\" | sed -r s/\ /,/g) | |
echo ${output} > $1 |
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
[Unit] | |
Description=Periodically update master_list | |
[Timer] | |
OnBootSec=0min | |
OnUnitActiveSec=1min |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment