Skip to content

Script: nodervisor_auto_register

Bruno Galindro da Costa edited this page May 31, 2015 · 1 revision

nodervisor_auto_register

Use this script to auto add hosts and groups to Nordervisor that are running on AWS EC2 instances based on a tag. So, to mapping all instances that has supervisor installed, you must first add a tag (like 'supervisor') where the value of it is the port of supervisor http service. Example: supervisor = 9009

This must be passed as a parameter to script for it be capable to search for EC2 instances where have the supervisor service installed.

Note: you must remove the http authentication from supervisor configuration of instances (/etc/supervisord.conf), or the Nodervisor will not be capable to grab information from the instance.

Note 2: the mapped instances must has a Name tag.

Script Actions

You must execute the script chosing two actions: add or delete.

add

This action is obvious: it will add hosts to Nodervisor that has the specified tag. The name of the host is constructed concatenating the Name tag of the instance with the instance id. Before add the host to database, nodervisor_auto_register will create a group for it based on its tag name. Let's see it in pratice:

You have two webservers running in an autoscaling environment. Booth of then has these tags: Name=WEBSERVER, supervisor=9009. When you run the script with add action, it will:

  • Check if the group WEBSERVER exists. If not, the script will create it
  • Add the instances to the group WEBSERVER with the names WEBSERVER-i-xxxxxx and WEBSERVER-i-yyyyyy
  • Restart Nodervisor service for it read database changes

delete

The delete action will get all hosts from Nodervisor database, and will check if they exists in EC2. If they are not found, the script will remove them from Nodervisor database. If the last host was removed from a group, the group will be deleted too.

How to use

usage: nodervisor_auto_register [-h]
                                [-r {us-east-1,cn-north-1,ap-northeast-1,eu-west-1,ap-southeast-1,ap-southeast-2,us-west-2,us-gov-west-1,us-west-1,eu-central-1,sa-east-1}]
                                -a {add,delete} [-c CONFIG] -t TAG -d
                                NODERVISORDB [-s NODERVISORSERVICE]

Nodervisor auto-registration

optional arguments:
  -h, --help            show this help message and exit
  -r {us-east-1,cn-north-1,ap-northeast-1,eu-west-1,ap-southeast-1,ap-southeast-2,us-west-2,us-gov-west-1,us-west-1,eu-central-1,sa-east-1}, --region {us-east-1,cn-north-1,ap-northeast-1,eu-west-1,ap-southeast-1,ap-southeast-2,us-west-2,us-gov-west-1,us-west-1,eu-central-1,sa-east-1}
                        AWS Region
  -a {add,delete}, --action {add,delete}
                        Action to execute
  -c CONFIG, --config CONFIG
                        Config file
  -t TAG, --tag TAG     Tag for search
  -d NODERVISORDB, --nodervisordb NODERVISORDB
                        Nodervisor database file
  -s NODERVISORSERVICE, --nodervisorservice NODERVISORSERVICE
                        Nodervisor service name
  • -c/--config: The config file is used only to control logging behaviour
  • -r/--region: The region to search for launch configurations. Default region is set on galintools.json
  • -a/--action: This is the action to execute: add or delete hosts from database
  • -t/--tag: This is the tag where script will use to search for instances where needs to be monitored
  • -d/--nodervisordb: Absolute path of nodervisor database file (nodervisor.sqlite)
  • -s/--nodervisorservice: Nodervisor service name for execute a restart at script ends. Default is nodervisor. You could install this upstart config file for start/stop Nodervisor service:
# nodervisor.conf

description "Nodervisor startup script"

start on started networking
stop on runlevel [016]


limit nofile 1000000 1000000


script
  # CHANGE THIS TO YOUR INSTALLATION PATH
  mkdir -p /var/www/nodervisor
  cd /var/www/nodervisor
  
  npm start
end script

respawn

Examples

  • Search for instances with tag 'supervisor' where database file is located on /var/www/nodervisor/nodervisor.sqlite and add them to Nodervisor
$ nodervisor_auto_register -a add -t supervisor -d /var/www/nodervisor/nodervisor.sqlite 
  • Search for instances with tag 'supervisor' where database file is located on /var/www/nodervisor/nodervisor.sqlite and delete them to Nodervisor if they are not found in AWS EC2
$ nodervisor_auto_register -a delete -t supervisor -d /var/www/nodervisor/nodervisor.sqlite