October 2016 Archives

sparrow remote tasks - way to package your scripts and configurations.

Idea behind a sparrow is quite simple. You have a script, you package it as sparrow plugin and you can re-use it somewhere else.

Give me list of available plugins:

$ sparrow plg search    

type    name

public  app-cpm
public  bash
public  bitbucket-repo
public  check-tomcat-deploy
public  chemaxon-check
public  cpan-package
public  df-check
public  directory
public  docker-engine
public  file
public  foo-generic
public  foo-test
public  git-async-push
public  git-base
public  git-svn-export
public  gitprep
public  group
public  http-status
public  logdog
public  minion-check
public  module-release
public  mongodb
public  nano-setup
public  net-ping
public  nginx-check
public  nginx-example
public  outth-mysql-cookbook
public  package-generic
public  perl-app
public  perlbrew
public  proc-validate
public  ruby-test
public  sendmail
public  service
public  sph-check
public  ssh-sudo-check
public  ssh-sudo-try
public  sshd-check
public  stale-proc-check
public  svn-to-git-submodules
public  swat-nginx
public  swat-pintod
public  swat-test
public  templater
public  user
private package-generic-dev

This plugin makes a trivial nano.rc file configuration:

$ sparrow plg install nano-setup

Project is just a container for plugins to group them logically:

$ sparrow project create utils

Task is a plugin with parameters, in other words task bind plugin with parameters to project:

$ sparrow task add utils nano-rc nano-setup
$ sparrow task ini utils nano-rc
   tabsize 2

Now let's run our task:

$ sparrow task run utils nano-rc

<nano-rc>

/ started

rc file generated from template
rc file updated
ok      scenario succeeded
ok      [b] output match 'rc file generated from template'
ok      [b] output match 'rc file updated'
STATUS  SUCCEED

You can even override task parameters via command line:

 $ sparrow task run utils nano-rc --param tabsize=4

So sparrow plugins are packed scripts, but I want to package my configuration ...

A task initialization process could be the same if we want to reuse not only scripts but configuration. Every time I ssh on new server I want to apply the same nano.rc as it good for me. Here are remote sparrow tasks:

$ sparrow remote task upload utils/nano-rc 'my nano.rc setup'
task updated
task ini data updated OK

I have just uploaded a nano-rc task and it's configuration to my SparrowHub account. Now having this I could ssh to another server and re-apply my task:

$ ssh some-server
$ sparrow remote task run  utils/nano-rc


task meta data saved to /home/vagrant/sparrow/cache/meta/utils/nano-rc.json ...
public@nano-setup is uptodate (0.1.0)
project utils already exists - nothing to do here ...
task utils/nano-rc already exists, update task parameters
task - set plugin to public@nano-setup
task utils/nano-rc successfully created
loaded test suite ini from /home/vagrant/sparrow/cache/meta/utils/nano-rc.ini OK

<nano-rc>

/ started

rc file generated from template
rc file updated
ok      scenario succeeded
ok      [b] output match 'rc file generated from template'
ok      [b] output match 'rc file updated'
STATUS  SUCCEED

Pretty handy, huh?

Once remote task gets run for the first time , later you can run it as local sparrow task :

 $ sparrow task run utils nano-rc

Ok, if I find my task quite common I even can share it with others:

$ sparrow remote task share  utils/nano-rc
task nano-rc shared OK
now everyone could see it!

Everyone now can run my task:

$ sparrow remote task run melezhik@utils/nano-rc

The list of available remote tasks could be fetched like this:

$ sparrow remote task public-list 

2016-10-24 12:59:06 melezhik@packages/toplist | install my favorite packages
2016-10-24 12:58:22 melezhik@utils/nano-rc | my nano.rc setup

The list of private remote tasks related to your account is taken as:

$ sparrow remote task list

You may take other actions on your remote tasks:

$ sparrow remote task hide app/secure # to hide task from others ( make it private )
$ sparrow remote task remove app/secure # to remove task

Further steps

Follow sparrow docs on remote tasks API. Or create useful task and share with others!

At the end of my post is a simple but illuminative example of remote task to install my favorite packages:

$ sparrow project create packages
$ sparrow task add packages toplist package-generic
$ sparrow task ini packages toplist
    list       nano mc ncdu telnet tree 

$ sparrow remote task upload packages/toplist 'installs my favorite packages'

Regards

Alexey Melezhik

SparrowHub Plugins Request

A quick search at github on something like Perl/Bash scripts gives me a lot of results.

As developers we more think about modules and libraries when talk about software reuse. But in our day-to-day life scripts still take a vital part. Scripts like little, but useful commands to get our job done. This is why people from many programming languages/environments tend to create a places for such a tools called repositories, so other could easily find, install and run scripts or utilities. To list a few:

Well. A SparrowHub is a attempt to make a such effort in Perl communities to create a repository of useful automation scripts. Sparrow is Perl friendly in many ways:

  • it is written on Perl
  • it gets installed as CPAN module
  • it respects carton/cpanfile dependency management for your scripts
  • it supports Config::General format for script configuration ( among JSON, YAML and command line parameters )

Well let me now turn to the essential point of my post.

I know there are a plenty of cool software written by Perl community we know as CPAN, and many, many Perl modules get shipped with some useful scripts, even more some module's are only public interface - some command line scripts. So why not to upload such a script into a repository so other could use it? I know not all the cases are good fit, but let me outline some criteria if your script could be a good candidate to be uploaded as sparrow plugin:

  • you have some command line tools based on existed Perl/CPAN/Bash scripts and want to share it somehow with others or even keep it for yourself so to repeat script installation / execution process in the same way every time you setup a new server.

  • script takes a lot of input parameters or parameters with the structure is hard to be expressed in command line manner ( Hashes, Lists, Groups, so on ).

  • you need to add some middle-ware steps to your script logic , but don't want to add this into scripts source code.

  • you need to build a more complex tool based on your low level script/utility.

  • script possibly gets run often and / or on multiple servers.

  • script requires some extra checks so one could run it safely.

  • script is a generic tool acting differently depending on input parameters.

So if this sounds like about your scripts, you may start playing with SparrowHub. After all it's just distribution platform, having minimal impact at your script code:

  • You write/already have a script ( plus some dependencies software like CPAN module )
  • You upload script / or script based tool to SparrowHub as sparrow plugin
  • Others may find, install and run your script ( via SparrowHub ).

If this sounds interesting there are simple `how to contribute' steps:

  • Get registered at SparrowHub
  • Convert your script into sparrow plugin
  • Upload new sparrow plugin

In case you still have a questions or need help on converting your scripts into sparrow plugin, please:

Finally, if you feel like you have no time to dive into new things and study docs, but you are still interested in the subject, just let me know ( creating an issue at sparrow/github ) about script you wish add sparrowhub to and I will try to do it soon.

Regards.

Alexey Melezhik

Monitoring minion workers/tasks using Sparrow

Hi! This is small post concerning sparrow plugin to monitor minion workers. I had some post on this recently, but now I have made some improvements at existed plugin, so I am writing a new one ...

On my production server I use Minion to send emails to my clients. For some reasons there are faults on executing minion tasks or even minion workers get stopped sometimes for reasons unknown. As sending emails is a vital part of the service registration system I need to know if everything goes bad with my email system. Here is minon-check sparrow plugin to risqué.

Install sparrow

$ cpanm Sparrow

Install sparrow plugin

$ sparrow index update # get latest plugins index from Sparrowhub
$ sparrow plg install minion-check # install plugin

Set plugin up

$ sparrow project create webapp # create a projects to hold web applications tasks
$ sparrow task add webapp minion-health minion-check # this is 
# minion health task which is "tied" to minion-check plugin

$ EDITOR=nano  sparrow task ini webapp minion-health # set task parameters. 
# on my server this will be:

# I use carton install, so:
command = cd /path/to/your/mojo/app && carton exec ./app.pl minion

# sets worker footprint to lookup at processes list
worker_cmd = minion worker

A few comments on plugin setup here:

  • A command parameter define a system command to handle your minion jobs/tasks , An app.pl is Mojolicious application to run my web application, so I set my minion command as mojolicious command.

  • A worker_cmd parameter is just a string to look up inside a process list, to identify that minion worker is alive. A simple stings minion worker works for me.

Let's run a task and see the output:

$ sparrow task run webapp minion-health


<minion-tasks>

/modules/check-worker/ started

look up {{{minion worker}}} at proccess list ...
web-app       2748  0.3  3.4 202704 35216 pts/0    S    23:17   0:00 perl ./app.pl minion worker -m production -I 15 -j 2
done
ok      scenario succeeded
ok      output match 'done'

/modules/last-task/ started

Q=0
ok      scenario succeeded
ok      output match /Q=(1|0)/

/ started

no failed tasks found
ok      0 failed jobs found
STATUS  SUCCEED

So what sparrow plugin minion-check does?

  • check if your minion worker(s) is running.

  • check if you have no tasks marked as FAILED for the given period of time. ( I do not set it up explicitly here, but for default it uses 10 minutes interval , for details follow minion-check documentation ).

Finally I setup cron job to run a sparrow plugin every 10 minutes:

$ sparrow task run webapp minion-health --cron

A --cron flag makes sparrow client silent unless any errors happen during execution.


Regards.

Alexey Melezhik

About melezhik

user-pic Dev & Devops --- Then I beheld all the work of God, that a man cannot find out the work that is done under the sun: because though a man labour to seek it out, yet he shall not find it; yea further; though a wise man think to know it, yet shall he not be able to find it. (Ecclesiastes 8:17)