Getting Started with CoreOS [29 Nov 2016, ENG]


fleetctl



$ vi [email protected]

[Unit]
Description=Hello World template unit
After=docker.service
Requires=docker.service

[Service]
ExecStartPre=-/usr/bin/docker kill %p-%i
ExecStartPre=-/usr/bin/docker rm %p-%i
ExecStart=/usr/bin/docker run --name %p-%i busybox /bin/sh -c "while true; do echo Hello World; sleep 1; done"
ExecStop=/usr/bin/docker stop %p-%i
Restart=on-failure


$ fleetctl start hello@1
$ fleetctl start hello@2


$ vi [email protected]


[Unit]
Description=Announce Hello Service
BindsTo=hello@%i.service
After=hello@%i.service

[Service]
ExecStart=/bin/sh -c "while true; do etcdctl set /services/hello/%i $(docker inspect -f '' hello-%i) --ttl 60;sleep 45;done"
ExecStop=/usr/bin/etcdctl rm /services/hello/svc@%i

[X-Fleet]
MachineOf=hello@%i.service


$ fleetctl start hello-discovery@1
$ fleetctl start hello-discovery@2


$ fleetctl list-units
UNIT				MACHINE				ACTIVE	SUB
[email protected]	422b9f3c.../172.17.8.102	active	running
[email protected]	5e438c8c.../172.17.8.101	active	running
[email protected]			422b9f3c.../172.17.8.102	active	running
[email protected]			5e438c8c.../172.17.8.101	active	running


$ etcdctl ls /services/hello
/services/hello/2
/services/hello/1


$ etcdctl get /services/hello/1
172.18.0.2


$ etcdctl get /services/hello/2
172.18.0.2


$ fleetctl destroy hello-discovery@2

ждем 60 сек

$ etcdctl ls /services/hello
/services/hello/1