Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/garethr/serf-master
A small python framework for writing Serf handlers
https://github.com/garethr/serf-master
Last synced: 13 days ago
JSON representation
A small python framework for writing Serf handlers
- Host: GitHub
- URL: https://github.com/garethr/serf-master
- Owner: garethr
- License: mit
- Created: 2013-12-23T13:45:52.000Z (almost 11 years ago)
- Default Branch: master
- Last Pushed: 2015-05-30T20:56:04.000Z (over 9 years ago)
- Last Synced: 2024-10-23T06:09:11.927Z (22 days ago)
- Language: Python
- Size: 303 KB
- Stars: 125
- Watchers: 11
- Forks: 20
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Serf Master
[![Build
Status](https://secure.travis-ci.org/garethr/serf-master.png)](http://travis-ci.org/garethr/serf-master)
[![Coverage
Status](https://coveralls.io/repos/garethr/serf-master/badge.png?branch=master)](https://coveralls.io/r/garethr/serf-master?branch=master)
[![Code
Health](https://landscape.io/github/garethr/serf-master/master/landscape.png)](https://landscape.io/github/garethr/serf-master/master)[Serf](http://www.serfdom.io/) is a very nice service discovery and
orchestration framework which allows you to write scripts to react to
different events across your infrastructure. However most of the
examples are simple shell scripts with lots of logic embedded in them.
Combine that with per host configuration around registering event
handlers and it's easy to build a fiddly, hard to reason about
enviroment. It doesn't have to be that way.Serf is the framework, what you built on top of it matters. I wanted
something with the following properties:* Testable. I should be able to unit test the entire configuration.
* Single package. All hosts should get the same code, with the code
deciding what runs where.
* Single event handler. I'd rather deal with logic about user events or
roles within my code, rather than parameters to serf.
* Make handlers sharable. You can simply extend `SerfHandler` and
package up your own handlers, say `serf_master_haproxy`.Serf Master tries to do this, presented as a very small Python framework
with no dependencies. Here's an example:## An example
Imagine a cluster with a number of database servers and web servers. The
database servers have the Serf role of `db` and the web servers the Serf
role of `web`. We want the web servers to react whenever a new server is
added to the cluster (maybe to tell a load balancer to reload?) and we
want to be able to trigger a deploy. For the database servers we want to
be able to trigger a backup custom event.```python
#!/usr/bin/env python
from serf_master import SerfHandler, SerfHandlerProxyclass WebHandler(SerfHandler):
def deploy(self):
# run commands here to do with deploymentdef member_join(self):
# maybe rebalance the load balancerclass DatabaseHandler(SerfHandler):
def backup(self):
# run commands here to do with backupsif __name__ == '__main__':
handler = SerfHandlerProxy()
handler.register('web', WebHandler())
handler.register('db', DatabaseHandler())
handler.run()
```The important parts are:
```python
handler.register('web', WebHandler())
```This says if the Serf role is `web` then use the `WebHandler` class for
any events.```python
def member_join(self):
```This says for the `member-join` serf event we should execute the code
we write here.See the unit tests for examples of now this can be tested.
## Configuration
Using this with Serf is simple, just wire up all the event handlers to
your script like so:```bash
serf agent -event-handler /opt/your/script.py
```Although you could restrict the events which are managed by this handler
the whole point of serf-master is to move the handler definition into
code and away from command line flags.## Installation
Serf Master is available on
[PyPi](https://pypi.python.org/pypi/serf_master) and can be installed
with:pip install serf_master