Hi all
I am having problem at selecting processes.
The plan of action is:
- count how many ntpd seem to be running
- if zero, then start ntpd
- if more than one, kill all processes matching ntpd, then
start ntpd again
I didn't find a way to use just one promise to express this, so I tried
with two and process_select with a number of different regexes. But it's
not working. The last one, which is still failing, is like the following:
bundle agent ntp
{
[. . .]
processes:
"one_ntpd_max"
process_select => select_ntpd,
process_count => one_ntpd_max ;
"run_one_ntpd"
process_select => select_ntpd,
process_count => run_one_ntpd ;
commands:
start_ntpd::
"/etc/init.d/ntp"
args => "start" ;
restart_ntpd::
"/etc/init.d/ntp"
args => "restart" ;
kill_all_ntpd::
"/usr/bin/pkill"
args => "-f ntpd" ;
reports:
start_ntpd::
"Attempted to start ntpd (no process found)" ;
restart_ntpd::
"Attempted to REstart ntpd (configuration file changed)" ;
kill_all_ntpd::
"Too many ntpd processes found, killing them all" ;
[ . . . ]
body classes restart_ntpd {
promise_repaired => { "restart_ntpd" } ;
}
body process_count one_ntpd_max {
match_range => irange("0","1") ;
out_of_range_define => { "kill_all_ntpd","start_ntpd" } ;
}
body process_count run_one_ntpd {
match_range => irange("0","0") ;
in_range_define => { "start_ntpd" } ;
}
body process_select select_ntpd {
command => ".*\bntpd\b.*" ;
process_result => "command" ;
}
What happens according to "reports::" is that process_count always
matches 0, so start_ntpd is always set and cfengine tries to start an
already running ntpd.
I verified that my regex should is actually matching the whole COMMAND
field:
> # /bin/ps -eo user,pid,ppid,pgid,pcpu,pmem,vsz,pri,rss,nlwp,stime,time,args |
> perl -lne '@field = split(/\s+/,$_,13) ; print $field[12]' | perl -ne
> '/.*\bntpd\b.*/ && print'
> /usr/sbin/ntpd -p /var/run/ntpd.pid -g -u 104:106
I also tried without \b's, or matching "/ntpd" (which could be
non-portable) but no luck.
What am I doing wrong???
Thanks
Ciao
-- bronto
_______________________________________________
Help-cfengine mailing list
[email protected]
https://cfengine.org/mailman/listinfo/help-cfengine