Forum: Cfengine Help
Subject: Re: How to extract values (not keys) from an array to slist?
Author: [email protected]
Link to topic: https://cfengine.com/forum/read.php?3,21174,21200#msg-21200

Disregard the code in the example I posted before...  I've been modifying this 
policy a lot in the past day trying to get something functional.

Here's the example that actually uses the arrays.


 5      bundle agent rhel6_services
     6  {
     7  vars:
     8          redhat_6::
     9                  # running_service is what the cmd output is in the 
output of ps -ef in the process table.
    10                  # services we want running.
    11                  "running_service"                       slist   =>      
{ "ntpd", "mdadm", };
    12                                                                          
        
    13  
    14                  # services we dont want running.  this is what we would 
find in the output of ps -ef in the process table.
    15                  "stop_service"                          slist   =>      
{ "/usr/sbin/atd", "/usr/sbin/abrtd",};
    16  
    17                  # running_service_name is what the service is refered 
to via the chkconfig or service command.
    18                  # every entry from running_service needs to have an 
entry here.  Its what gets referenced in chkconfig and service cmds.
    19                  "running_service_name"                  string  =>      
"ntpd-mike";
    20                  "running_service_name"                  string  =>      
"mdmonitor";
    21  
    22                  "all_running_services_process_name"             slist   
=>      getindices("running_service_name");
    23                  "all_running_services_service_name"             slist   
=>      @(running_service[$all_running_services_process_name]);
    24  
    25                  # stopped_service_name is what the service is refered 
to via the chkconfig or service command.
    26                  # every entry from stop_service needs to have an entry 
here.  Its what gets referenced in chkconfig and service cmnds.
    27                  "stopped_service_name"          string  =>      "atd";
    28                  "stopped_service_name"          string  =>      "abrtd";
    29  
    30                  "all_stopped_services"                  slist   =>      
getindices("stopped_service_name");
    31  
    32  
    33  processes:
    34          # Only raise these classes if we are on a RHEL6 host.  Once the 
class is defined, RHEL6 is an 
    35          # assumed prerequesite.  the running_service variable is 
expanded from an slist to an individual entry, and then
    36          # that individual entry is actually checked in the process 
table.  If its not found,
    37          # we raise the "restart" class.  This class gets executed upon 
in the commands section.  
    38          redhat_6::
    39                  "$(running_service)"
    40                          restart_class   =>      
canonify("$(running_service)_start");
    41  
    42          # If we found a service in the process table that we dont want 
running, then execute its stop function using service..
    43          redhat_6::
    44                  "$(stop_service)"
    45                          process_stop    =>      "/sbin/service 
$(stopped_service_name[$(stop_service)]) stop";
    46  
    47  commands:
    48          ################################# START SERVICES 
###############################################
    49          redhat_6::
    50                  "/sbin/service 
$(running_service_name[$(running_service)]) start"
    51                          ifvarclass      =>      
canonify("$(running_service)_start");
    52  
    53          # Since we had to start this process, make sure the symlinks 
are in place via chkconfig.
    54          #redhat_6::
    55                  #"/sbin/chkconfig 
$(running_service_name[$(running_service)]) on"
    56                          #ifvarclass     =>      
canonify("$(running_service)_start");
    57          ################################# START SERVICES 
###############################################
    58  
    59  methods:
    60          redhat_6::
    61                  "any"   usebundle       =>      
rh_chkconfig_on(${all_running_services_process_name});
    62  
    63  reports:
    64          redhat_6::
    65                  "cf3: RHEL6 service 
$(running_service_name[$(running_service)]) was restarted on $(sys.host)"
    66                          ifvarclass      =>      
canonify("$(running_service)_start");
    67  
    68          redhat_6::
    69                  "cf3: RHEL6 service 
$(stopped_service_name[$(stop_service)]) was disabled on $(sys.host)"
    70                          ifvarclass      =>      
canonify("$(stop_service)_stop");
    71  }
    72  ###################################################
    73  bundle agent rh_chkconfig_on(service)
    74  {
    75  classes:
    76          # Report if the class is enabled via chkconfig.
    77          "$(service)_enabled"    expression      =>      
returnszero("/sbin/chkconfig ${service}","noshell");
    78  
    79  reports:
    80          redhat_6::
    81                  "Service is ${service}";
    82                          
    83  }


_______________________________________________
Help-cfengine mailing list
[email protected]
https://cfengine.org/mailman/listinfo/help-cfengine

Reply via email to