Sparrowdo automation. Part 5. Managing services and processes.

HI!

This time I want to tell you how to manage services and processes using sparrowdo.

Before this post a following list of topics was written by me:

As services are highly coupled with processes we will investigate them in one post.

Let's have an nginx web server gets installed on your system:

$ cat sparrowfile

use v6;

use Sparrowdo;

task_run  %(
  task => 'install nginx server',
  plugin => 'package-generic',
  parameters => %( list => 'nginx' )
);

We talked about package-generic plugin at this post. We use this plugin to install system packages.

install nginx server

Ok. This is very logical now having installed an nginx to make it "bootable", so next reboot of our system will pickup an nginx and make it sure it runs too. Some people call this autoload:

$ cat sparrowfile

use v6;

use Sparrowdo;

task_run %(
  task => 'enable nginx service',
  plugin => 'service',
  parameters => %( action => 'enable', service => 'nginx' )
);

task_run %(
  task => 'start nginx service',
  plugin => 'service',
  parameters => %( action => 'start', service => 'nginx' )
);

nginx-up-and-running

A service plugin makes it possible to enable and disabling Linux services, as well as starting and stopping them. It's very simple yet useful plugin for those who want to automate Linux services on target hosts.

At example here we not only make it nginx autoloadable enabling it, but also make it sure it starts. So good so far.

Well time goes and we need to ensure that nginx server is running. There are more than one way to do this.

The simplest one is to look up in a processes tree a process related to nginx master. This is what I usually do first when troubleshoot nginx server issues.

$ cat sparrowfile

use v6;

use Sparrowdo;

task_run  %(
  task => 'check my nginx master process',
  plugin => 'proc-validate',
  parameters => %(
    pid_file => '/var/run/nginx.pid',
    footprint => 'nginx.*master'
  )
);

nginx-master-process

A proc-validate plugin takes 2 parameters at input. The first one is the path to file where PID is written, and the second optional one - Perl regular expression to identify a process at process tree. Even providing only the first parameter is enough but I also set a footprint to make my example more explanatory.

Summary

We've learned how to manage Linux services with the help of sparrowdo. It's easy and it makes your routine tasks automated. And if you want to add some "audit" to your running services, which of course sounds reasonable for maintainers jobs the easiest way to start with is using simple proc-validate plugin.


See you soon at our next topic.

Have a fun in coding and automation.

-- Alexey Melezhik

Leave a comment

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)