Skip to content

Instantly share code, notes, and snippets.

@arithx
Created October 30, 2018 20:00
Show Gist options
  • Save arithx/dae948f3d9558c8863ac55cba3391eb4 to your computer and use it in GitHub Desktop.
Save arithx/dae948f3d9558c8863ac55cba3391eb4 to your computer and use it in GitHub Desktop.
# /etc/systemd/system/checkin.service
[Unit]
Description=Azure Check-In
[Service]
ExecStart=/bin/bash /var/checkin.sh
[Install]
WantedBy=multi-user.target
WIRESERVER="168.63.129.16"
r=$(curl -X GET -H 'x-ms-version: 2012-11-30' "http://$WIRESERVER/machine?comp=goalstate")
container_id=$(echo "$r" | grep "<ContainerId>" | sed "s,[[:space:]]\|</*ContainerId>,,g")
instance_id=$(echo "$r" | grep "<InstanceId>" | sed "s,[[:space:]]\|</*InstanceId>,,g")
HEALTH=$(cat << EOF
<?xml version="1.0" encoding="utf-8"?>
<Health xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<GoalStateIncarnation>1</GoalStateIncarnation>
<Container>
<ContainerId>$container_id</ContainerId>
<RoleInstanceList>
<Role>
<InstanceId>$instance_id</InstanceId>
<Health>
<State>Ready</State>
</Health>
</Role>
</RoleInstanceList>
</Container>
</Health>
EOF
)
curl -X POST -H 'x-ms-version: 2012-11-30' -H "x-ms-agent-name: WALinuxAgent" -H "Content-Type: text/xml;charset=utf-8" -d "$HEALTH" http://$WIRESERVER/machine?comp=health
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment