On Fri, Sep 16, 2011 at 4:44 PM, Jerome Yanga <[email protected]> wrote:
> Hi!
>
> I am trying to replicate the following commands in a promise. I have tried
> the restart_class but I cannot seem to get it working the way I have
> described below.
>
> service snmpd start/restart
> chkconfig snmpd on
>
> I want it to restart snmpd if it is already running and start it if it is
> stopped.
Why, please? (I want to understand the use case.)
Ok, so you want to:
Check if the process is running, and based on that set a class PROCESS_RUNNING
if PROCESS_RUNNING, then restart it
if not PROCESS_RUNNING, then start it
Right?
Try this on for size (tested with sendmail daemon, it does work):
bundle agent example
{
processes:
".*"
process_count => anyprocs,
process_select => proc_finder;
commands:
process_running::
"/bin/echo restart command";
process_not_running::
"/bin/echo start command";
}
########################################################
body process_select proc_finder
{
command => "sendmail: .*"; # (Anchored) regular expression matching
the command/cmd field of a process
process_result => "command";
}
########################################################
body process_count anyprocs
{
match_range => "0,0"; # Integer range for acceptable number of matches
for this process
out_of_range_define => { "process_running" }; # List of classes to
define if the matches are out of range
in_range_define => { "process_not_running" }; # List of classes to
define if the matches are in range.
}
_______________________________________________
Help-cfengine mailing list
[email protected]
https://cfengine.org/mailman/listinfo/help-cfengine