Created
December 1, 2016 23:10
-
-
Save davidd2k/5e6a26633755f6a72aaf2fee86dbedec to your computer and use it in GitHub Desktop.
CoreOS - StarDock + SkyDNS starter script
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/sh | |
| # start it with | |
| # | |
| # docker stop $(docker ps -q); docker rm -f $(docker ps -a -q);docker rmi -f $(docker images -a -q); curl -L https://gist.github.com/FractalizeR/86549f16d2948b1b590a/raw/init.sh > init.sh && ./init.sh | |
| # Start only | |
| # curl -L https://gist.github.com/FractalizeR/86549f16d2948b1b590a/raw/init.sh > init.sh && ./init.sh | |
| source /etc/environment | |
| rm -f *.service | |
| docker pull skynetservices/skydns | |
| docker pull busybox | |
| sudo tee /home/core/skydns.service > /dev/null <<EOF | |
| [Unit] | |
| Description=SkyDNS Service | |
| After=docker.service | |
| [Service] | |
| EnvironmentFile=/etc/environment | |
| ExecStartPre=-/usr/bin/docker kill skydns | |
| ExecStartPre=-/usr/bin/docker rm skydns | |
| ExecStart=/usr/bin/docker run -p ${COREOS_PRIVATE_IPV4}:53:53/udp --name skydns skynetservices/skydns -machines ${COREOS_PRIVATE_IPV4}:4001 | |
| ExecStop=/usr/bin/docker stop skydns | |
| [Install] | |
| WantedBy=multi-user.target | |
| [X-Fleet] | |
| # Global=true | |
| X-ConditionMachineID=020ae0be724f4b1dbce2c016af2a407b | |
| EOF | |
| sudo tee /home/core/hello.service > /dev/null <<EOF | |
| [Unit] | |
| Description=Hello World Service | |
| After=docker.service | |
| After=skydns.service | |
| Requires=skydns.service | |
| [Service] | |
| EnvironmentFile=/etc/environment | |
| ExecStartPre=-/usr/bin/docker kill hello | |
| ExecStartPre=-/usr/bin/docker rm hello | |
| ExecStart=/usr/bin/docker run --name hello busybox /bin/sh -c "while true; do echo 'Test' ; sleep 3; test $? -gt 128 && break; done" | |
| ExecStop=/usr/bin/docker stop hello | |
| [X-Fleet] | |
| # Global=true | |
| X-ConditionMachineID=020ae0be724f4b1dbce2c016af2a407b | |
| EOF | |
| sudo tee /home/core/hello-announcer.service > /dev/null <<EOF | |
| [Unit] | |
| Description=Hello World Service Announcer | |
| After=docker.service | |
| After=skydns.service | |
| After=hello.service | |
| Requires=skydns.service | |
| Requires=hello.service | |
| BindsTo=hello.service | |
| [Service] | |
| EnvironmentFile=/etc/environment | |
| ExecStart=/bin/bash -c 'while true; do /usr/bin/etcdctl set /skydns/local/service/hello "{\"host\":\"${COREOS_PRIVATE_IPV4}\",\"priority\":20}"; sleep 20; done;' | |
| # ExecStart=curl -XPUT http://${COREOS_PRIVATE_IPV4}:4001/v2/keys/skydns/local/service/hello -d value="{\"host\":\"${COREOS_PRIVATE_IPV4}\",\"priority\":20}" | |
| ExecStop=/usr/bin/etcdctl rm /skydns/local/service/hello | |
| # ExecStop=curl -XDELETE http://${COREOS_PRIVATE_IPV4}:4001/v2/keys/skydns/local/service/hello | |
| [X-Fleet] | |
| # Global=true | |
| X-ConditionMachineID=020ae0be724f4b1dbce2c016af2a407b | |
| EOF | |
| sudo tee /home/core/pinger.service > /dev/null <<EOF | |
| [Unit] | |
| Description=Pinger Service | |
| After=skydns.service | |
| After=hello-announcer.service | |
| Requires=skydns.service | |
| Requires=hello-announcer.service | |
| BindsTo=hello.service | |
| [Service] | |
| EnvironmentFile=/etc/environment | |
| ExecStartPre=-/usr/bin/docker kill pinger | |
| ExecStartPre=-/usr/bin/docker rm pinger | |
| ExecStart=/usr/bin/docker run --name pinger --dns ${COREOS_PRIVATE_IPV4} busybox /bin/sh -c "while true; do ping hello.service.local ; sleep 3; test $? -gt 128 && break; done" | |
| ExecStop=/usr/bin/docker stop pinger | |
| [X-Fleet] | |
| # Global=true | |
| X-ConditionMachineID=020ae0be724f4b1dbce2c016af2a407b | |
| EOF | |
| # Tracing results | |
| set -o xtrace | |
| # Reinitializing services | |
| fleetctl destroy pinger.service | |
| fleetctl destroy hello-announcer.service | |
| fleetctl destroy hello.service | |
| fleetctl destroy skydns.service | |
| fleetctl submit skydns.service | |
| fleetctl submit hello.service | |
| fleetctl submit hello-announcer.service | |
| fleetctl submit pinger.service | |
| fleetctl load skydns.service | |
| fleetctl load hello.service | |
| fleetctl load hello-announcer.service | |
| fleetctl load pinger.service | |
| # SkyDNS setup | |
| /usr/bin/etcdctl mkdir /skydns | |
| /usr/bin/etcdctl rm /skydns/config | |
| curl -XPUT http://${COREOS_PUBLIC_IPV4}:4001/v2/keys/skydns/config \ | |
| -d value='{"dns_addr":"0.0.0.0:53", "nameservers": ["8.8.8.8:53","8.8.4.4:53"], "domain": "service.local"}' | |
| # Start services | |
| fleetctl start skydns.service | |
| fleetctl start hello.service | |
| fleetctl start hello-announcer.service | |
| fleetctl start pinger.service | |
| # Pausing | |
| sleep 3 | |
| # Checking status | |
| fleetctl status skydns.service | |
| fleetctl status hello.service | |
| fleetctl status hello-announcer.service | |
| fleetctl status pinger.service |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment