Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

How do I read a pid file in cfengine 3 and restart that process if it isn't running?

share|improve this question

2 Answers 2

In cfengine 2, I used something like:

processes:
  "httpd" restart "/etc/init.d/apache restart"

In cfengine 3, restarting of processes must be coded as a separate commands.

processes:
   "httpd"
     restart_class => "start_httpd";

commands:
  start_httpd::
    "/etc/init.d/apache restart";

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.

share|improve this answer

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.

You can download this code snippet here.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.