This will define the class "start_httpd" if httpd is not running. Then will run the init script to make sure it starts. See the cf3 reference manual for a deeper explanation of how the restart_class works.
Instead of looking at the PID file directly, I'd try to let Cfengine 3 manage your selected service/process. For Cfengine 3 you can use the following code (it might not be perfect, but it works):
body common control {
version => "1.0";
bundlesequence => { "check_services" };
}
bundle agent check_services {
vars:
"services" slist => { "apache2", "mysql" };
"init_scripts_path" string => "/etc/init.d";
processes:
"$(services)"
comment => "Check if the processes for '$(services)'",
restart_class => "restart_$(services)";
commands:
"${init_scripts_path}/${services} start"
comment => "Restarting the service",
ifvarclass => "restart_${services}";
}
Please note that I wrote this Cfengine 3 script for an Ubuntu client, so you might have to adapt it to your needs and distribution.
In cfengine 2, I used something like:
In cfengine 3, restarting of processes must be coded as a separate commands.
This will define the class "start_httpd" if httpd is not running. Then will run the init script to make sure it starts. See the cf3 reference manual for a deeper explanation of how the restart_class works.
Instead of looking at the PID file directly, I'd try to let Cfengine 3 manage your selected service/process. For Cfengine 3 you can use the following code (it might not be perfect, but it works):
Please note that I wrote this Cfengine 3 script for an Ubuntu client, so you might have to adapt it to your needs and distribution.
You can download this code snippet here.