Table of Contents
                             
                        
                        cfe_internal/core/watchdog/watchdog.cf
                                Table of Contents
                            
                            agent bundles
cfe_internal_core_watchdog
Prototype: cfe_internal_core_watchdog(state)
Description: Configure external watchdog processes to keep cf-execd running
Arguments:
state: (enabled|disabled) The state to keep the watchdog configuration in
Implementation:
bundle agent cfe_internal_core_watchdog(state)
{
  meta:
    "description"
      string => "Configure external watchdog processes (like cron, or monit) to
                 make sure that cf-execd is always running";
  classes:
      "invalid_state"
        not => regcmp("(enabled|disabled)", "$(state)");
      "have_cron_d"
        expression => isdir("/etc/cron.d");
      "use_cfe_internal_core_watchdog_cron_d"
        expression => "have_cron_d._stdlib_path_exists_pgrep";
      # We use the aix specific watchdog implementation when it's aix and we are
      # not using the cron.d implementation.
      "use_cfe_internal_core_watchdog_aix"
        expression => "!use_cfe_internal_core_watchdog_cron_d.aix";
  methods:
    use_cfe_internal_core_watchdog_cron_d::
      "any" usebundle => cfe_internal_core_watchdog_cron_d( $(state) );
    use_cfe_internal_core_watchdog_aix::
      "any" usebundle => cfe_internal_core_watchdog_aix( $(state) );
  reports:
    DEBUG|DEBUG_cfe_internal_core_watchdog::
      "DEBUG $(this.bundle): Watchdog '$(state)'";
      "DEBUG $(this.bundle): Invalid state '$(state)' only enabled|disabled allowed"
        ifvarclass => "invalid_state";
    !(use_cfe_internal_core_watchdog_cron_d|aix)::
      "WARNING $(this.bundle): Currently only supports /etc/cron.d on systems that have pgrep in the the stdlib paths bundle and AIX hosts.";
}
cfe_internal_core_watchdog_aix
Prototype: cfe_internal_core_watchdog_aix(state)
Description: Manage watchdog state on aix
Arguments:
state: enabled|disabled- When enabled a cron job will be present to start cf-execd if it's not running.
 - When disabled cron jobs ending with 
# CFEngine watchdogwill not be present. 
Implementation:
bundle agent cfe_internal_core_watchdog_aix(state)
{
  classes:
    any::
      # Define a class for whatever the desired state is
      "$(state)"
        expression => "any";
  vars:
      "my_statedir" string => "$(sys.statedir)/MPF/$(this.bundle)";
  commands:
      # We need to know about the current crontab before making any changes
      "/usr/bin/crontab -l > $(my_statedir)/root-crontab"
        handle => "aix_crontab_get_state",
        if => isdir( "$(my_statedir)" ),
        contain => in_shell_and_silent;
  files:
    enabled::
      # We need a place to track state for processing changes to cron entries
      # with proper signaling.
      "$(my_statedir)/."
        create => "true";
      # The watchdog script takes care of detecting conditions and launching
      # necessary components.
      "$(sys.bindir)/watchdog"
        create => "true",
        template_method => "mustache",
        perms => mog( "700", "root", "system" ),
        edit_template => "$(this.promise_dirname)/templates/watchdog.mustache";
      # When enabled we make sure there is a cron entry to execute the watchdog
      # script.
      # NOTE The text `# CFEngine watchdog` is used to locate the specific entry in cron when disabling
      "$(my_statedir)/root-crontab"
        create => "true",
        edit_line => lines_present( "* * * * * $(sys.bindir)/watchdog >/dev/null 2>&1 # CFEngine watchdog"),
        classes => results( "bundle", "root_crontab" ),
        depends_on => { "aix_crontab_get_state" };
    disabled::
      "$(my_statedir)/root-crontab"
        edit_line => delete_lines_matching(".*# CFEngine watchdog"),
        classes => results( "bundle", "root_crontab" ),
        depends_on => { "aix_crontab_get_state" };
  commands:
    root_crontab_repaired::
      # We use crontab to load the desired entries so that crond will be
      # signaled and the changes will be respected.
      "/usr/bin/crontab $(my_statedir)/root-crontab";
}
cfe_internal_core_watchdog_cron_d
Prototype: cfe_internal_core_watchdog_cron_d(state)
Description: Use a cron job installed in /etc/cron.d to watch and make sure that cf-execd is always running.
Arguments:
state: (enabled|disabled) The state to keep the watchdog configuration in. Enabled manages the cron job, disabled removes it.
Implementation:
bundle agent cfe_internal_core_watchdog_cron_d(state)
{
  classes:
    any::
      # Define a class for whatever the desired state is
      "$(state)"
        expression => "any";
  vars:
    any::
      "template"
        string => "$(this.promise_dirname)/../../../templates/cfengine_watchdog.mustache";
      "cron_d_watchdog" string => "/etc/cron.d/cfengine_watchdog";
  files:
    enabled::
      "$(cron_d_watchdog)"
        create => "true";
      "$(cron_d_watchdog)"
        edit_template => "$(template)",
        handle => "cfe_internal_core_watchdog_enable_cron_d_file_content",
        template_method => "mustache";
    disabled::
      "$(cron_d_watchdog)"
        delete => tidy;
}
