Forum: Cfengine Help
Subject: Re: Populating slist from an execresult
Author: howardk
Link to topic: https://cfengine.com/forum/read.php?3,18222,18225#msg-18225

After a little head banging here is the result:
Needed to changed the sed delimiters to # instead of / (don't know why), then 
the string populated. Next needed to change the splitstring delimiter to \s for 
regex matching. Does what it should now. Enjoy.

######################################################
#
# cf-process.cf: Checks the processes defined "on" in runlevel 3 and starts 
those not running 
#
######################################################
#
# Every policy must have a bundlesequence

body common control
{
version => "1.0";
bundlesequence => { "service_check" };
}

#

bundle agent service_check
{

vars:
     "service_list" string =>  execresult("/bin/ls 
/etc/rc.d/rc3.d/S*|/usr/bin/sed -e 
s#\/etc\/rc.d\/rc3.d\/S[0-9][0-9]##","useshell");
     "services" slist => splitstring( ${service_list},"\s","100");

##########
methods:

  # perform the actual check and restart on services included in the list above

  "any"  usebundle => enable_service("$(services)");

}

###############################################################################

bundle agent enable_service(name)
{
 vars:
  "status" string => execresult("/sbin/chkconfig $(name)", "useshell");

 classes:
  "on"  expression => regcmp(".*on","$(status)");
  "off" expression => regcmp(".*off","$(status)");
  on::
  "running" expression => returnszero("/sbin/service $(name) status","noshell");

 commands:
  on.!running::
     "/sbin/service $(name) restart",
       comment => "Restart $(name) service";

 reports:
  on.!running::
     "Restarted $(name) service.";
  off::
     "$(name) has been already disabled. Don't need to perform any actions.";

}

_______________________________________________
Help-cfengine mailing list
Help-cfengine@cfengine.org
https://cfengine.org/mailman/listinfo/help-cfengine

Reply via email to