Skip to content

Instantly share code, notes, and snippets.

@stongo
Last active August 29, 2015 14:13
Show Gist options
  • Save stongo/aef53fdb79d727b7bb28 to your computer and use it in GitHub Desktop.
Save stongo/aef53fdb79d727b7bb28 to your computer and use it in GitHub Desktop.
NSQD and NSQLOOKUPD
[Unit]
Description=Nsqd
After=docker.service
Requires=docker.service
[Service]
TimeoutStartSec=0
ExecStartPre=-/usr/bin/docker kill nsqd
ExecStartPre=-/usr/bin/docker rm nsqd
ExecStartPre=/usr/bin/docker pull redis
ExecStart=/bin/bash -c '\
/usr/bin/docker run -rm --name=nsqd -p 4150:4150 -p 4151:4151 nsqio/nsqd --lookupd-tcp-address=$(/usr/bin/etcdctl get /nslookupd) --broadcast-address=${COREOS_PRIVATE_IPV4} \
'
ExecStop=/usr/bin/docker stop nsqd
[Unit]
Description=Nsqlookupd etcd registration
Requires=etcd.service
Requires=nsqlookupd.service
After=etcd.service
After=nsqlookupd.service
BindsTo=nsqlookupd.service
[Service]
EnvironmentFile=/etc/environment
ExecStart=/bin/bash -c '\
while true; do \
HTTP_PORT=4161; \
TCP_PORT=4060; \
curl -f ${COREOS_PRIVATE_IPV4}:$HTTP_PORT/ping; \
if [ $? -eq 0 ]; then \
etcdctl set /nsqlookupd ${COREOS_PRIVATE_IPV4}:$TCP_PORT --ttl 30; \
else \
etcdctl rm /nsqlookupd ${COREOS_PRIVATE_IPV4}; \
fi; \
sleep 30; \
done'
ExecStop=/usr/bin/etcdctl rm /nsqlookupd
Restart=on-failure
RestartSec=10s
[X-Fleet]
MachineOf=nsqlookupd.service
[Unit]
Description=Nsqlookupd
After=docker.service
Requires=docker.service
[Service]
TimeoutStartSec=0
ExecStartPre=-/usr/bin/docker kill nsqd
ExecStartPre=-/usr/bin/docker rm nsqd
ExecStartPre=/usr/bin/docker pull redis
ExecStart=/usr/bin/docker run -rm --name=nsqd -p 4160:4160 -p 4161:4161 nsqio/nsqlookupd
ExecStop=/usr/bin/docker stop nsqd
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment