Giter Site home page Giter Site logo

haproxy-confd's Introduction

confd

Build Status

confd is a lightweight configuration management tool focused on:

  • keeping local configuration files up-to-date by polling etcd or Consul and processing template resources.
  • reloading applications to pick up new config file changes

Community

Quick Start

Before we begin be sure to download and install confd.

Add keys to etcd

This guide assumes you have a working etcd server up and running and the ability to add new keys. Using the etcdctl command line tool add the following keys and values to etcd:

etcdctl set /myapp/database/url db.example.com
etcdctl set /myapp/database/user rob

Alternatively, Consul can be used a Key/Value store.

Create the confdir

The confdir is where template resource configs and source templates are stored. The default confdir is /etc/confd. Create the confdir by executing the following command:

sudo mkdir -p /etc/confd/{conf.d,templates}

You don't have to use the default confdir location. For example you can create the confdir under your home directory. Then you tell confd to use the new confdir via the -confdir flag.

mkdir -p ~/confd/{conf.d,templates}

Create a template resource config

Template resources are defined in TOML config files under the confdir conf.d directory (i.e. ~/confd/conf.d/*.toml).

Create the following template resource config and save it as ~/confd/conf.d/myconfig.toml.

[template]
src = "myconfig.conf.tmpl"
dest = "/tmp/myconfig.conf"
keys = [
  "/myapp/database/url",
  "/myapp/database/user",
]

Create the source template

Source templates are plain old Golang text templates, and are stored under the confdir templates directory. Create the following source template and save it as ~/confd/templates/myconfig.conf.tmpl

# This a comment
[myconfig]
database_url = {{ .myapp_database_url }}
database_user = {{ .myapp_database_user }}

Processing template resources

confd supports two modes of operation, daemon and onetime mode. In daemon mode, confd runs in the foreground processing template resources every 5 mins by default. For this tutorial we are going to use onetime mode.

Assuming your etcd server is running at http://127.0.0.1:4001 you can run the following command to process the ~/confd/conf.d/myconfig.toml template resource:

confd -verbose -onetime -node 'http://127.0.0.1:4001' -confdir ~/confd

Output:

2013-11-03T18:00:47-08:00 confd[21294]: NOTICE Starting confd
2013-11-03T18:00:47-08:00 confd[21294]: NOTICE etcd nodes set to http://127.0.0.1:4001
2013-11-03T18:00:47-08:00 confd[21294]: INFO Target config /tmp/myconfig.conf out of sync
2013-11-03T18:00:47-08:00 confd[21294]: INFO Target config /tmp/myconfig.conf has been updated

The dest config should now be in sync with the template resource configuration.

cat /tmp/myconfig.conf

Output:

# This a comment
[myconfig]
database_url = db.example.com
database_user = rob

Next steps

Checkout the docs directory for more docs and usage examples.

haproxy-confd's People

Contributors

armon avatar billhathaway avatar bketelsen avatar chancez avatar kelseyhightower avatar rjocoleman avatar robbyt avatar stone avatar tscheepers avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.