Skip to content
This repository has been archived by the owner on Sep 30, 2020. It is now read-only.

Commit

Permalink
Replace bash userdata fetcher with systemd unit with autorestart
Browse files Browse the repository at this point in the history
  • Loading branch information
redbaron committed Jan 19, 2017
1 parent 163f1fd commit 9fce0cb
Showing 1 changed file with 44 additions and 28 deletions.
72 changes: 44 additions & 28 deletions config/templates/stack-template.json
Original file line number Diff line number Diff line change
Expand Up @@ -627,20 +627,28 @@
"PlacementTenancy": "{{.WorkerTenancy}}",
{{end}}
"UserData": { "Fn::Base64": { "Fn::Join" : ["\n", [
"#!/bin/bash",
"# userdata hash: {{ .UserDataWorker | sha1 }}",
" . /etc/environment",
"export COREOS_PRIVATE_IPV4 COREOS_PRIVATE_IPV6 COREOS_PUBLIC_IPV4 COREOS_PUBLIC_IPV6",
"REGION=$(curl -s http://169.254.169.254/latest/dynamic/instance-identity/document | jq -r '.region')",
"USERDATA_FILE=userdata-worker",
"/usr/bin/rkt run \\",
" --net=host \\",
" --volume=dns,kind=host,source=/etc/resolv.conf,readOnly=true --mount volume=dns,target=/etc/resolv.conf \\",
" --volume=awsenv,kind=host,source=/var/run/coreos,readOnly=false --mount volume=awsenv,target=/var/run/coreos \\",
" --trust-keys-from-https \\",
" {{.AWSCliImageRepo}}:{{.AWSCliTag}} -- aws s3 --region $REGION cp {{ .S3URI }}/{{ .ClusterName }}/$USERDATA_FILE /var/run/coreos/",
"exec /usr/bin/coreos-cloudinit --from-file /var/run/coreos/$USERDATA_FILE"
]]}}
"#cloud-config",
"coreos:",
" units:",
" - name: bypass-user-data-limit.service",
" command: start",
" content: |",
" [Unit]",
" Description=Fetch and execute cloud config from s3",
" [Service]",
" Environment=USERDATA_FILE=userdata-worker",
" EnvironmentFile=/etc/environment",
" EnvironmentFile=-/var/run/coreos/region.env",
" Restart=on-failure",
" ExecStartPre=/bin/sh -ec 'echo REGION=$$(curl -s http://169.254.169.254/latest/dynamic/instance-identity/document | jq -r .region) >/var/run/coreos/region.env'",
" ExecStartPre=/usr/bin/rkt run \\",
" --net=host \\",
" --volume=dns,kind=host,source=/etc/resolv.conf,readOnly=true --mount volume=dns,target=/etc/resolv.conf \\",
" --volume=awsenv,kind=host,source=/var/run/coreos,readOnly=false --mount volume=awsenv,target=/var/run/coreos \\",
" --trust-keys-from-https \\",
" {{.AWSCliImageRepo}}:{{.AWSCliTag}} -- aws s3 --region ${REGION} cp {{ .S3URI }}/{{ .ClusterName }}/${USERDATA_FILE} /var/run/coreos/",
" ExecStart=/usr/bin/coreos-cloudinit --from-file /var/run/coreos/${USERDATA_FILE}"
]]}}
},
"Type": "AWS::AutoScaling::LaunchConfiguration"
},
Expand Down Expand Up @@ -671,20 +679,28 @@
],
"PlacementTenancy": "{{ .ControllerTenancy }}",
"UserData": { "Fn::Base64": { "Fn::Join" : ["\n", [
"#!/bin/bash",
"# userdata hash: {{ .UserDataController | sha1 }}",
" . /etc/environment",
"export COREOS_PRIVATE_IPV4 COREOS_PRIVATE_IPV6 COREOS_PUBLIC_IPV4 COREOS_PUBLIC_IPV6",
"REGION=$(curl -s http://169.254.169.254/latest/dynamic/instance-identity/document | jq -r '.region')",
"USERDATA_FILE=userdata-controller",
"/usr/bin/rkt run \\",
" --net=host \\",
" --volume=dns,kind=host,source=/etc/resolv.conf,readOnly=true --mount volume=dns,target=/etc/resolv.conf \\",
" --volume=awsenv,kind=host,source=/var/run/coreos,readOnly=false --mount volume=awsenv,target=/var/run/coreos \\",
" --trust-keys-from-https \\",
" {{.AWSCliImageRepo}}:{{.AWSCliTag}} -- aws s3 --region $REGION cp {{ .S3URI }}/{{ .ClusterName }}/$USERDATA_FILE /var/run/coreos/",
"exec /usr/bin/coreos-cloudinit --from-file /var/run/coreos/$USERDATA_FILE"
]]}}
"#cloud-config",
"coreos:",
" units:",
" - name: bypass-user-data-limit.service",
" command: start",
" content: |",
" [Unit]",
" Description=Fetch and execute cloud config from s3",
" [Service]",
" Environment=USERDATA_FILE=userdata-controller",
" EnvironmentFile=/etc/environment",
" EnvironmentFile=-/var/run/coreos/region.env",
" Restart=on-failure",
" ExecStartPre=/bin/sh -ec 'echo REGION=$$(curl -s http://169.254.169.254/latest/dynamic/instance-identity/document | jq -r .region) >/var/run/coreos/region.env'",
" ExecStartPre=/usr/bin/rkt run \\",
" --net=host \\",
" --volume=dns,kind=host,source=/etc/resolv.conf,readOnly=true --mount volume=dns,target=/etc/resolv.conf \\",
" --volume=awsenv,kind=host,source=/var/run/coreos,readOnly=false --mount volume=awsenv,target=/var/run/coreos \\",
" --trust-keys-from-https \\",
" {{.AWSCliImageRepo}}:{{.AWSCliTag}} -- aws s3 --region ${REGION} cp {{ .S3URI }}/{{ .ClusterName }}/${USERDATA_FILE} /var/run/coreos/",
" ExecStart=/usr/bin/coreos-cloudinit --from-file /var/run/coreos/${USERDATA_FILE}"
]]}}
},
"Type": "AWS::AutoScaling::LaunchConfiguration"
},
Expand Down

0 comments on commit 9fce0cb

Please sign in to comment.