Skip to content

Instantly share code, notes, and snippets.

@joshuarubin
Last active August 29, 2015 14:17
Show Gist options
  • Save joshuarubin/8aa771b2e41e8c6936db to your computer and use it in GitHub Desktop.
Save joshuarubin/8aa771b2e41e8c6936db to your computer and use it in GitHub Desktop.
etcd 2.0 systemd unit file
[Unit]
Description=etcd
After=docker.service
[Service]
User=core
PermissionsStartOnly=true
EnvironmentFile=/etc/environment
Restart=always
RestartSec=10s
Environment="ETCD_VERSION=v2.0.5"
Environment="ETCD_DISCOVERY=https://discovery.etcd.io/<YOUR_ETCD_DISCOVERY_URL>"
ExecStartPre=-/usr/bin/docker kill %p
ExecStartPre=-/usr/bin/docker rm %p
ExecStartPre=/usr/bin/sudo /usr/bin/mkdir -p /var/lib/%p
ExecStartPre=/usr/bin/sudo /usr/bin/chown -R core:core /var/lib/%p
ExecStartPre=/usr/bin/sudo /usr/bin/chattr -R +C /var/lib/%p
ExecStartPre=/usr/bin/docker pull quay.io/coreos/etcd:${ETCD_VERSION}
ExecStart=/usr/bin/docker run \
--rm \
-p 4001:4001 \
-p 7001:7001 \
--name %p \
-v /var/lib/%p:/data \
-v /usr/share/ca-certificates/:/etc/ssl/certs \
quay.io/coreos/etcd:${ETCD_VERSION} \
-name %m \
-discovery ${ETCD_DISCOVERY} \
-data-dir /data \
-advertise-client-urls http://${COREOS_PRIVATE_IPV4}:4001 \
-listen-client-urls http://0.0.0.0:4001 \
-initial-advertise-peer-urls http://${COREOS_PRIVATE_IPV4}:7001 \
-listen-peer-urls http://0.0.0.0:7001
ExecStop=/usr/bin/docker stop %p

Steps to upgrade to etcd 2.0:

  1. Disable the built in etcd in coreos.
    This is likely done by modifying the user-data aka cloud config file and commenting out the coreos.etcd section and the coreos.etcd.units.etcd.service section.
  2. Install the new etcd.service file.
    This can go in /etc/systemd/system/ or it can be put in the user-data in the coreos.etcd.units.etcd.service section after a content: | label.
  3. It is very important to use a NEW discovery url in this file and that the old discovery url is not reused.
  4. Choose the correct size parameter when going to https://discovery.etcd.io/new?size=3. The optimal size is between 3 and 9 according to CoreOS.
  5. If running in vagrant, run vagrant provision and then vagrant reload.
  6. In AWS, in order to edit the user-data the machine must have been turned off, so start it up again.
  7. The new version of etcd should stat up and upgrade the on disk data in /var/lib/etcd to the new format.
  8. Check the discovery url to see if the entry for that machine is there, if not, it must be entered manually using a curl command like this:
    curl -L https://discovery.etcd.io/<CLUSTER_ID>/<MACHINE_ID> -XPUT -d value=http://<INTERNAL_IP>:7001. Machine id is listed on each machine at /etc/machine-id
    Note that no ttl should be set.
  9. etcd may need to be restarted after all the machines have been added to the discovery system, before the cluster actually comes up.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment