Thursday, December 18, 2014

Supervisor (python supervisord) email alerts

The program supervisor written in python is used to supervise long running processes. In case that a long running process will stop (crash) supervisor will detect it and will restart it, you will get entries into the log files however unless you have a log aggregation tool or you login into the server or have some other monitoring tool you will not know that your process has crashed.

However there is hope :) - you can setup an event listener into supervisor which can email you in case that a process has exit. To do so you will need to install a python package superlance This is how the setup is done.

# install superlance
$ sudo pip install superlance  # if you don't have pip install try easy_install 

# configure supervisor to send events to crashmail

$ sudo vim /etc/supervisor/supervisord.conf  # change according to your setup

command=crashmail -a -m root@localhost

$ sudo supervisor stop && sudo supervisor start
# done :)

In the example above if a process will crash (exit) an event will be sent to crashmail which in turn will email to root@localhost - of course you can change the email address, crashmail uses actually sendmail to send email (postfix and qmail come with a sendmail like program so no worries).
Also the email alert will be sent out for any program that crashed but if you want to filter out you can choose just the program you want by specifying -p program_name instead if -a, for more info you can see Crashmail section on the superlance docs.

Friday, November 21, 2014

Gitlab(Rails) gem loader error

I was trying to make a simple bash pre-receive hook into Gitlab and got one of this

# pre-receive hook

`knife node show`

# Error
/usr/local/lib/ruby/gems/1.9.1/gems/bundler-1.3.5/lib/bundler/rubygems_integration.rb:214:in `block in replace_gem': chef is not part of the bundle. Add it to Gemfile. (Gem::LoadError)

Initially I thought I can change the hook to ruby and will fix it but after I tried all 6 ways to
execute a command according to and no luck I looked further into the gem specs for Rails and it looks like you can't load a gem that is not
declared into the Gemfile for your application.

So - what options you have really ? Install all gems and their dependencies into the Rails application Gemfile just to execute a
command ?! Well there is a different way sudo to the rescue :)

# pre-receive hook

`sudo -u USER_THAT_RUNS_THE_APP knife node show`

# also you need to make sure into sudoers that the USER_THAT_RUNS_THE_APP has the right to execute without tty
Defaults:USER_THAT_RUNS_THE_APP !requiretty

Sunday, September 14, 2014

Vim - find occurrences in files.

Vim is the editor for anybody using the cli on daily bases. One useful feature it has is the find/grep into files. Obviously you can exit or suspend vim and do a find or grep however not many know that vim has this built in. You can simply use vimgrep and the likes - for more info

Tuesday, March 25, 2014

Vim setup for Chef(Opscode) Cookbooks

I've started programming seriously Chef cookbooks by a while but always felts is something missing ... Well I didn't have

  • jump to definition for any Chef dsl
  • auto completion
  • syntax highlight

Recently I found a solution for this, this is my vim setup(just as easy you can do it in Sublime Text as well) These are the tools in my setup

  • vim
  • vim-chef
  • ripper-tags (by my surprise ctags doesn't work well with ruby files ...)

To setup is as simple as

# vim with pathogen
$ git clone ~/.vim/bundle/vim-chef
$ sudo /opt/chef/embedded/bin/gem install gem-ripper-tags
$ knife cookbook create test_coobook -o .
# create tags - there are better ways to do it - see gem-tags for example
$ ripper-tags -R /opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.10.4 -f tags
$ ctags -R -f tags_project
:set tags=tags,tags_project 
# done 

Sunday, March 2, 2014

Getting started with the new AWS tools

AWS replaced their java based tool with a neat python package for linux (didn't try the windows based ones yet ...). Why are these tools nice ?! - written in python - support from one tool for all services - wizard configuration To get started

# use virtualenv or global
# this example shows virtualenv

$ mkdir AWS
$ virtualenv AWS 
$ source AWS/bin/activate

# install the tools from pypi

$ pip install awscli
# configure

$ aws configure
AWS Access Key ID [None]: XXXXXX
AWS Secret Access Key [None]: XXXXXX
Default region name [None]: us-west-1
Default output format [None]: json

$ aws ec2 describe-regions
    "Regions": [
            "Endpoint": "", 
            "RegionName": "eu-west-1"
            "Endpoint": "", 
            "RegionName": "sa-east-1"
            "Endpoint": "", 
            "RegionName": "us-east-1"
            "Endpoint": "", 
            "RegionName": "ap-northeast-1"
            "Endpoint": "", 
            "RegionName": "us-west-2"
            "Endpoint": "", 
            "RegionName": "us-west-1"
            "Endpoint": "", 
            "RegionName": "ap-southeast-1"
            "Endpoint": "", 
            "RegionName": "ap-southeast-2"

# Done!

For more info the project is hosted at The reference table Aws tools references and the home page at