项目作者: tchamberlin

项目描述 :
Easy management of circus instances across multiple users and hosts
高级语言: Python
项目地址: git://github.com/tchamberlin/barnum.git
创建时间: 2020-02-10T20:21:19Z
项目社区:https://github.com/tchamberlin/barnum

开源协议:MIT License

下载


Barnum

Easily manage multiple Circus instances across multiple hosts.

Configuration

Structure

Barnum currently relies on a very specific directory structure in order to discover Circus hosts:

  1. tree /users/user1/circus
  2. ├── host1
  3. ├── circus.ini
  4. ├── circus.log
  5. ├── watcher1.stderr.log
  6. └── watcher1.stdout.log
  7. └── init_circus -> /users/$USER/circus/init_circus

In other words, it expects that every user that is running a Circus instance will have a ~/circus directory, and that this each child directory thereof will contain a circus.ini folder. Each circus.ini file it discovered will be parsed to determine its endpoint, and the host will be derived from the name its parent. Then, ssh commands will be built from this information, and used to delegate commands across multiple users/hosts simultaneously (threaded).

Config File

You will also need a config file, so that barnum knows what to search for.

Create circus_users.yaml in the same directory as barnum.py. Its contents should look something like this:

  1. ---
  2. - user1
  3. - user2

Operations

barnum

Perform Circus operations across multiple hosts

System Overview

  1. $ python barnum.py --verbose
  2. barnum: Circus is configured on the following hosts: host1, host2
  3. barnum: Processing host1
  4. barnum: Processing host2
  5. barnum: bailey cmd: ssh -q host1 bailey --verbose
  6. barnum: bailey cmd: ssh -q host2 bailey --verbose
  7. bailey: Derived circus user user1 from /etc/systemd/system/circus_user1_host2.service
  8. bailey: circus cmd: circusctl --endpoint tcp://host2:8385 status
  9. bailey: Derived circus user user2 from /etc/systemd/system/circus_user2_host1.service
  10. bailey: circus cmd: circusctl --endpoint tcp://host1:5775 status
  11. bailey: Derived circus user user3 from /etc/systemd/system/circus_user3_host2.service
  12. bailey: circus cmd: circusctl --endpoint tcp://host2:5555 status
  13. --- HOST1 ---
  14. --------------------------------------------------------------------------------
  15. circus_user2_host1.service enabled active (running)
  16. watcher1: active
  17. ================================================================================
  18. --- HOST2 ---
  19. --------------------------------------------------------------------------------
  20. circus_user1_host2.service enabled active (running)
  21. watcher2: active
  22. --------------------------------------------------------------------------------
  23. circus_user3_host2.service enabled active (running)
  24. watcher3: active
  25. --------------------------------------------------------------------------------
  26. circus_user4_host2.service disabled inactive (dead)
  27. No circus expected
  28. ================================================================================

What’s happening here:

  1. For each user in circus_users.yaml, derive the hosts it has circus instances on from the directory structure described above
  2. For every host:
    1. SSH to host_n
    2. Use sysctl list-unit-files to determine all circus unit files
    3. Examine each unit file to determine the user it is for
    4. Call bailey for each user on host_n

Manage All Circus Instances on Given Host

Get status of all Circus instances run on host1:

  1. $ python barnum.py host1 --verbose
  2. Circus is configured on the following hosts: host1
  3. Processing user1@host1
  4. bailey cmd: ssh -q host1 /path/to/bailey user1 --verbose
  5. circus cmd: circusctl --endpoint tcp://host1:5775 status
  6. ---
  7. watcher1: active

What’s happening here:

  1. SSH to host1
  2. Use sysctl list-unit-files to determine all circus unit files
  3. Examine each unit file to determine the user it is for
  4. For each user:
    1. Construct path to circus config file based on given user and host
    2. Parse config file to determine circus endpoint
    3. Call bailey for derived endpoint

Manage Specific Circus Instance on Given Host

Get status of Circus instance run by user1@host1.

  1. $ python barnum.py user1@host1 --verbose
  2. Circus is configured on the following hosts: host1
  3. Processing user1@host1
  4. bailey cmd: ssh -q host1 bailey user1 --verbose
  5. circus cmd: circusctl --endpoint tcp://host1:5775 status
  6. ---
  7. watcher1: active

What’s happening here:

  1. SSH to host1
  2. Construct path to circus config file based on given user and host
  3. Parse config file to determine circus endpoint
  4. Call bailey for derived endpoint

Sending Commands to Bailey/Circus

There are two advanced use cases here:

  1. Send commands to bailey
  2. Send commands to circus
  3. Send commands to both bailey and circus

It is useful to experiment with these using --dry-run, in order to prevent things from getting broken. For example,

  1. $ python barnum.py user1@host1 --verbose --dry-run
  2. barnum: Processing user1@host1
  3. ---
  4. DRY RUN; would execute: ssh -q host1 bailey user1 --verbose
Send commands to bailey

This would print the help message for every bailey instance:

$ python barnum.py -- --help

To send specific circus commands to each bailey instance, you’ll need to use something like the following:

$ python barnum.py user1@host1 --verbose -- -- stats

Everything following the -- will be sent directly to bailey, without any changes. bailey will then send everything after the second -- directly to circus (more on that below).

bailey

Perform Circus operations on a single hosts (but possibly multiple users)

Manage All Circus Instances on Current Host

Get status of all Circus instances run on current host (host1):

  1. $ bailey --verbose
  2. --- host1 ---
  3. --------------------------------------------------------------------------------
  4. circus_user1_host1.service disabled inactive (dead)
  5. No circus expected
  6. --------------------------------------------------------------------------------
  7. bailey: Derived circus user user1 from /etc/systemd/system/circus_user1_host1.service
  8. bailey: circus cmd: circusctl --endpoint tcp://host1:5755 status
  9. circus_user1_host1.service enabled active (running)
  10. watcher1: active
  11. ================================================================================

What’s happening here:

  1. Use sysctl list-unit-files to determine all circus unit files
  2. Examine each unit file to determine the user it is for
  3. For each user:
    1. Construct path to circus config file based on given user and host
    2. Parse config file to determine circus endpoint
    3. Call bailey for derived endpoint

Manage Specific Circus Instance on Current Host

Get status of Circus instance run by user1@host1 (given user at current host).

  1. $ bailey user1 --verbose
  2. bailey: circus cmd: circusctl --endpoint tcp://host1:5555 status
  3. watcher1: active

What’s happening here:

  1. Construct path to circus config file based on given user and host
  2. Parse config file to determine circus endpoint
  3. Call bailey for derived endpoint
Send commands to circus

To send specific circus commands, you’ll need to use something like the following:

$ python barnum.py user1@host1 --verbose -- stats

Everything following the -- will be sent directly to circus, without any changes