Forum: CFEngine Help Subject: controlling redhat-style startup services via chkconfig Author: matt_garman Link to topic: https://cfengine.com/forum/read.php?3,24162,24162#msg-24162
Hi, I'm trying to create a promise that makes sure startup services are enabled on CentOS (RHEL) servers via the "chkconfig" program. In particular, I'm looking at neilhwatson's example and this similar question from ErikOonk. Here is what I have in a file called "util.cf": bundle agent rh_chkconfig_status(s) { classes: "${s}_enabled" expression => returnszero("/sbin/chkconfig ${s}", "noshell"); reports: all:: "service ${s} is enabled", ifvarclass => "${s}_enabled"; "service ${s} is NOT enabled", ifvarclass => "!${s}_enabled"; } And here is "check_service_enabled.cf": body common control { bundlesequence => { "check_service_enabled" }; inputs => { "util.cf" }; } bundle agent check_service_enabled { methods: redhat|centos|SuSE:: "any" usebundle => rh_chkconfig_status("ntpd"); } If I try to run this via "cf-agent -K -f ./check_service_enabled.cf", it outputs nothing. Running it verbosely, for the reports promises, it says: cf3> Skipping whole next promise (service ntpd is enabled), as context all is not relevant cf3> (snip) cf3> Skipping whole next promise (service ntpd is NOT enabled), as context all is not relevant As far as I can tell, this is copied verbatim from neilhwatson's example (to which I linked above). However, I can fix this by making a one-line change to "util.cf": bundle agent rh_chkconfig_status(s) { classes: "${s}_enabled" expression => returnszero("/sbin/chkconfig ${s}", "noshell"); reports: redhat|centos|SuSE:: # changed this from all:: "service ${s} is enabled", ifvarclass => "${s}_enabled"; "service ${s} is NOT enabled", ifvarclass => "!${s}_enabled"; } And now it works! When I run it, I get "R: service ntpd is enabled", as expected. I don't understand why this is. Question 2, which is related. Now I want to get a bit fancier: ntpd isn't the only service I care about, so I want to use an slist for some implicit iteration on this rh_chkconfig_status() bundle. So "util.cf" stays the same, and I introduce this file, "classes.cf": bundle common g { classes: "need_ntp" expression => "any"; } At some point, the "need_ntp" expression will be more sophisticated, but trying to keep it as simple as possible for now. And then I change "check_service_enabled.cf" to look like this: body common control { bundlesequence => { "check_service_enabled" }; inputs => { "classes.cf", "util.cf" }; } bundle agent check_service_enabled { vars: need_ntp:: "service" slist => { "ntpd", "named" }; !need_ntp:: "service" slist => { "named" }; methods: redhat|centos|SuSE:: "any" usebundle => rh_chkconfig_status(${service}); reports: need_ntp:: "need NTP"; !need_ntp:: "do NOT need NTP"; } Output is exactly this: R: service named is enabled R: need NTP Notice anything? Even though we are part of the "need_ntp" class, it doesn't report "service ntpd is enabled" like I expect. In fact, it looks like it's using the slist with only "named" defined. What am I missing? Thanks, Matt _______________________________________________ Help-cfengine mailing list Help-cfengine@cfengine.org https://cfengine.org/mailman/listinfo/help-cfengine