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 [email protected]
$ fleetctl start [email protected]


$ vi [email protected]


[Unit]
Description=Announce Hello Service
[email protected]%i.service
[email protected]%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/[email protected]%i

[X-Fleet]
[email protected]%i.service


$ fleetctl start [email protected]
$ fleetctl start [email protected]


$ 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 [email protected]

ждем 60 сек

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