Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

share|improve this question

In cfengine 2, I used something like:

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

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

     restart_class => "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 {
        "services" slist => { "apache2", "mysql" };
        "init_scripts_path" string => "/etc/init.d"; 

            comment => "Check if the processes for '$(services)'",
            restart_class => "restart_$(services)";

        "${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


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.