Skip to content

Instantly share code, notes, and snippets.

@mssio
Last active March 1, 2016 19:32
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save mssio/1b949d0952aaf69c2543 to your computer and use it in GitHub Desktop.
Save mssio/1b949d0952aaf69c2543 to your computer and use it in GitHub Desktop.
Nginx Load Balancer Service For Core OS

#Nginx Load Balancer Service For Core OS

Create a directory to manage using fleetctl for this service:

$ mkdir static

Create this file in static/nginx_lb.service

[Unit]
Description=Nginx load balancer for web server backends

# Requirements
Requires=etcd.service
Requires=docker.service

# Dependency ordering
After=etcd.service
After=docker.service

[Service]
# Let the process take awhile to start up (for first run Docker containers)
TimeoutStartSec=0

# Change killmode from "control-group" to "none" to let Docker remove
# work correctly.
KillMode=none

# Get CoreOS environmental variables
EnvironmentFile=/etc/environment

# Pre-start and Start
## Directives with "=-" are allowed to fail without consequence
ExecStartPre=-/usr/bin/docker kill nginx_lb
ExecStartPre=-/usr/bin/docker rm nginx_lb
ExecStartPre=/usr/bin/docker pull mssio/nginx_lb_node
ExecStart=/usr/bin/docker run --name nginx_lb -p ${COREOS_PUBLIC_IPV4}:80:80 \
mssio/nginx_lb_node /usr/local/bin/confd-watch

# Stop
ExecStop=/usr/bin/docker stop nginx_lb

[X-Fleet]
X-Conflicts=nginx.service
X-Conflicts=node@*.service

Finally just run this command from shell and you Load Balancer should be up and run perfectly

$ fleetctl start instances/*

PS:

  1. You should change mssio/nginx_lb_node with your own node application image
  2. Based on tutorial in Digital Ocean
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment