Forum: CFEngine Help
Subject: Define classes if a process is running or not
Author: loopx
Link to topic: https://cfengine.com/forum/read.php?3,26838,26838#msg-26838
Hi,
To make some promise, I need to define classes like this :
- XXX_running
- XXX_stopped
At the beginning, we was using (like for Cfengine2) the following module :
for process in $@ ; do
processname=$(echo $process | sed s/-//g );
if ps aux | grep $process | grep -qv grep ; then
echo "+${processname}_running";
echo "-${processname}_stopped";
else
echo "-${processname}_running";
echo "+${processname}_stopped";
fi
done
But, I've seen that it's possible to define classes with built-in methods of
Cfengine3. In the community lib, I've tried to use "if_else" but, it is always
"yes" which win and print the final report, even if the process is not running :
body classes if_else(yes,no)
{
promise_kept => { "$(yes)" };
promise_repaired => { "$(yes)" };
repair_failed => { "$(no)" };
repair_denied => { "$(no)" };
repair_timeout => { "$(no)" };
}
processes:
redhat_6::
"rhsmcertd"
classes => if_else("rhsmcertd_running",
"rhsmcertd_stopped"),
comment => "Check if process
'rhsmcertd' is running ; should be stopped ...";
reports:
redhat_6.rhsmcertd_running::
"WARNING> Service 'rhsmcertd' is running and should be
stopped ...";
redhat_6.rhsmcertd_stopped::
"DEBUG> Service 'rhsmcertd' is stopped and this is OK
...";
So, how should I do to only define a class if the process is running, and
another class if the process is not running ???
Thanks
_______________________________________________
Help-cfengine mailing list
[email protected]
https://cfengine.org/mailman/listinfo/help-cfengine