Giter Site home page Giter Site logo

serf-template's Introduction

Serf Template

Template rendering with Serf.

Installation

$ git clone https://github.com/phamhongviet/serf-template.git
$ cd serf-template
$ go build

Usage

$ serf-template config-file

Instead of reading anything from stdin or environment variables, Serf Template get members' information from the RPC interface. Serf Temlate subscribe to member related events from RPC stream (member-join, member-failed, member-update, member-leave and member-reap).

Configuration

Example:

{
  "serf": "path/to/serf"
  "name": "regexp",
  "role": "regexp",
  "status": "regexp",
  "tags": {
    "key1": "value1",
    "key2": "value2",
    "key3": "value3"
  },
  "rpc-addr": "127.0.0.1:7373",
  "rpc-auth": "rpcauthtoken",
  "rpc-timeout": 1000,
  "templates": [
    {
    "src": "/path/to/template.tpl",
    "dest": "/path/to/result.file",
    "cmd": "service dummy restart"
    },
    {
    "src": "/path/to/src.file",
    "dest": "/path/to/dest.file",
    "cmd": "service dummier restart",
    }
  ]
}

Template File

Serf Template consumes template files in Go Template format. Template files are rendered with a list of members with Name, Addr, Port, Tags and Status.

Member structure example:

{
  "name": "web-1",
  "addr": "172.16.0.21",
  "port": 7946,
  "tags": {
    "webport": "8080",
    "app": "nginx",
    "role": "web"
  },
  "status": "failed",
}

Template file example:

{{ range . }}{{ if eq .Status "alive" }}
server {{.Name}} at {{.Addr}} with serf at {{.Port}} and {{.Tags.app}} at {{.Tags.webport}}
{{ end }}{{ end }}

The above template file would produce a file like this:

server web-1 at 172.16.0.21 with serf at 7946 and nginx at 8080
server web-2 at 172.16.0.22 with serf at 7946 and nginx at 8080
server web-3 at 172.16.0.23 with serf at 7946 and httpd at 80

serf-template's People

Contributors

phamhongviet avatar

Watchers

James Cloos 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.