Giter Site home page Giter Site logo

lsyncd_update's Introduction

lsyncd_update

An automatic layncd update tool. This tool is used to create an lsyncd configuration file when new Rackspace Cloud Servers are created. It uses metadata key/value pairs to determine if a server should be added into the lsyncd configuration file.

usage: lsyncd_update.py [-h] [-r REGION] [-mk META_KEY] [-mv META_VALUE]
                        [-l LSYNCD_FILE] [-t LSYNCD_TEMPLATE]
                        [-c CREDENTIALS_FILE] [-p LOG_DIRECTORY] [-v]

optional arguments:
  -h, --help            show this help message and exit
  -r REGION, --region REGION
                        Region where your lsyncd configuration group is
                        (defaults to 'LON') [ORD, DFW, LON, SYD]
  -mk META_KEY, --metakey META_KEY
                        Matadata key to search for that identifies lsyncd is
                        installed
  -mv META_VALUE, --metavalue META_VALUE
                        Metadata value of your lsyncd configuration group
  -l LSYNCD_FILE, --lsyncdconf LSYNCD_FILE
                        The location of your lsyncd configuration file
  -t LSYNCD_TEMPLATE, --template LSYNCD_TEMPLATE
                        The location of your lsyncd configuration template
  -c CREDENTIALS_FILE, --credfile CREDENTIALS_FILE
                        The location of your pyrax configuration file
  -p LOG_DIRECTORY, --logpath LOG_DIRECTORY
                        The directory to create log files in
  -v, --verbose         Turn on debug verbosity

####PREREQUISITS:

  1. Lsyncd installed on master server
  2. Public SSH key added to authorized_keys file in server image or inject it as personality
  3. Meta data key/value pairs on servers created

####INSTALLATION:

  1. Download lsyncd.update.py
git clone https://github.com/duncanmurray/lsyncd_update.git \
&& cp lsyncd_update/lsyncd.template /etc/lsyncd.template \
&& cp lsyncd_update/lsyncd_update.py /usr/local/sbin/lsyncd_update.py
  1. Download and install pyrax
pip install pyrax
  1. Create pyrax configuration file "~/.rackspace_cloud_credentials"
[rackspace_cloud]
username = myusername
api_key = 01234567890abcdef
  1. Create cronjob to run lsyncd_update.py
*/2 * * * * /usr/local/sbin/lsyncd_update.py -v

Or better yet use flock until this script it turned into a deamon.

*/2 * * * * /usr/bin/flock -n /var/lock/lsyncd_update.py.lock -c "/usr/local/sbin/lsyncd_update.py -v"
  1. Don't forget to rotate your logs if you havn't already. A sample lsyncd log rotation script for /etc/logrotate.d/lsyncd.
/var/log/lsyncd/*log {
    missingok
    notifempty
    sharedscripts
    postrotate
    if [ -f /var/lock/lsyncd ]; then
      /sbin/service lsyncd restart > /dev/null 2>/dev/null || true
    fi
    endscript
}

####OPTIONS EXPLANATION:

Although no options are required to be passed to the program the defaults can be over ridden with the below flags.

######-h, --help Shows a help message about the commands options

######-r , --region Select the Rackspace data center of the servers you want to automatically update an lsyncd configuration file for.

######-mk , --metakey Set the metadata key that is common to all your cloud servers in the same working group. For example this could be WebServers. The default if none is provided is MyGroup0_lsyncd.

######-mv , --metavalue Set the metadata value that is paired with the key that you provided. The default value if none is provided is lsyncd_slave.

######-l , --lsyncdconf Set the location where you want to write your lsyncd configuration. This can be different depending on the operating system. The default location is /etc/lsyncd.lua.

######-t , --template Set the location of your lsyncd configuration template. Since this program was designed to work with multiple versions of lsyncd, you must provide a file that stores the lsyncd settigns and the sync blocks to use. This allows you to setup multiple directories to watch. The settings block starts when a line is found containing only SETTINGS_START. The end of the settings block is defines by a line containing SETTINGS_END. The sync block starts when a line is found containing SYNC_START and ends with a line containing only SYNC_END. The program will search for IPREPLACE in the sync block and replace it with he IP of each active server. You only need to create one sync block for each directory watched and the script will populate the lsyncd configuration file with one for each active server. The default location of the lsyncd template file is "/etc/lsyncd.template"

######-c , --credfile Set the location of your pyrax credentials file. This will store your username and API key that is associated with your account. The default location is ~/.rackspace_cloud_credentials.

-p , --logpath

Set the directory to log output from the script to. It must exist and be writable by the user running the script. The default location in /var/log/lsyncd/.

######-v, --verbose Turn on verbosity. By default logs are written to both the terminal and /var/log/lsyncd_update.py.log. Turning on verbose output changes the logging level from WARNING to DEBUG.

lsyncd_update's People

Contributors

duncanmurray avatar

Watchers

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