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.
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' )
);
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'
)
);
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