One simple solution would be to define an array that maps service to process... What I show below is a quick kludge (if /etc/init.d/bind fails, then try /etc/init.d/bind9), but you could be neater and make something that uses isvariable(). Or you could simply define an array element for *every* service, and build your service slist by using getindices, and then just always use the array values as the name of the file to reference...
vars: "service" slist => { "ssh", "snmpd", "apache2", "bacula-fd", "denyhosts", }; "exception[bind]" string => "bind9"; commands: "${daemon_path}/${service}" comment => "Executing command '${daemon_path}/${service} start'", ifvarclass => "${service}_up", classes => if_notkept("$(service)_restart_failed"), args => "restart"; "${daemon_path}/${exception[$(service)]}" comment => "Executing exception command '${daemon_path}/${exception[$(service)]} start'", ifvarclass => "${service}_restart_failed", args => "restart"; body classes if_notkept(x) { repair_failed => { "$(x)" }; repair_denied => { "$(x)" }; repair_timeout => { "$(x)" }; } On Oct 8, 2010, at 9:29 AM, no-re...@cfengine.com wrote: > Forum: Cfengine Help > Subject: problem restarting services > Author: cell > Link to topic: https://cfengine.com/forum/read.php?3,18669,18669#msg-18669 > > Hi, > > I've got problem with restarting some services. If the name of service > (/etc/init.d/service) and running process is the same, then everything is > working fine. But when name of service is /etc/init.d/bind9 and running > process is only 'bind', then I don't know how to restart it, because I have > name of services in slist and for every service in slist I look in the > process table and if it's not there then I restart that service. > > I am using this code for restarting: > > bundle agent restart > { > vars: > "service" slist => { "ssh", "snmpd", "apache2", "bacula-fd", > "denyhosts", }; > "daemon_path" string => "/etc/init.d"; > > processes: > "${service}" > comment => "Counting amount of processes for '${service}'", > process_count => up("${service}"); > > commands: > "${daemon_path}/${service}" > comment => "Executing command '${daemon_path}/${service} > start'", > ifvarclass => "${service}_up", > args => "restart"; > } > > body process_count up(s) { > match_range => "0,0"; > in_range_define => { "${s}_up" }; > ifelapsed => "1"; > } > > > Is there a way to manage it some way? I know other way how to restart those > services, but I don't want to write for every service it's own promise. I > would like to keep it tide like is shown in the code above. > > So my question is how to restart services which have different names as their > processes without making special promises for them. > > thanks for any suggestions > > _______________________________________________ > Help-cfengine mailing list > Help-cfengine@cfengine.org > https://cfengine.org/mailman/listinfo/help-cfengine _______________________________________________ Help-cfengine mailing list Help-cfengine@cfengine.org https://cfengine.org/mailman/listinfo/help-cfengine