I'm trying to match (and ultimately kill) a specific set of processes
that are "old". In this specific case, I'm looking for rsync daemons
that started more than a week ago, but this is a more generic problem.
Here's the current process list (note that this is the same command
cf-agent runs to dump the process table:
[beckerjes@host ~]$ ps -eo
user,pid,ppid,pgid,pcpu,pmem,vsz,pri,rss,nlwp,stime,time,args | grep '[r]sync
--daemon'
root 2527 4647 2527 0.0 0.0 71888 10 1188 1 Feb16 00:00:00
rsync --daemon
root 2672 4647 2672 0.0 0.0 71888 10 1188 1 Feb16 00:00:00
rsync --daemon
root 3997 4647 3997 0.0 0.0 71888 10 1188 1 Feb23 00:00:00
rsync --daemon
root 4842 4647 4842 0.0 0.0 71888 10 1188 1 Feb23 00:00:00
rsync --daemon
root 6370 4647 6370 0.0 0.0 71888 10 1196 1 Feb09 00:00:00
rsync --daemon
root 8166 4647 8166 0.0 0.0 71888 10 1188 1 Feb09 00:00:00
rsync --daemon
root 18552 4647 18552 0.0 0.0 71888 10 1192 1 Jan25 00:00:00
rsync --daemon
root 18583 4647 18583 0.0 0.0 71888 10 1184 1 Jan25 00:00:00
rsync --daemon
root 23609 4647 23609 0.0 0.0 71888 10 1188 1 Mar01 00:00:00
rsync --daemon
Here is the bundle:
bundle agent rsync_snipe {
vars:
'rsync_age_days' string => '7';
processes:
'rsync'
#signals => { 'term', 'kill' },
process_select => find_old_rsync("${rsync_age_days}"); # Time
in days.
}
body process_select find_old_rsync(age) {
command => '^rsync --daemon$';
stime_range => irange(0,ago(0,0,${age},0,0,0));
process_result => 'stime_range.command';
}
And here is the relevant output from cf-agent -v:
cf3> *****************************************************************
cf3> BUNDLE rsync_snipe
cf3> *****************************************************************
cf3>
cf3> =========================================================
cf3> vars in bundle rsync_snipe (1)
cf3> =========================================================
cf3>
cf3> + Private classes augmented:
cf3> - Private classes diminished:
cf3>
cf3> =========================================================
cf3> processes in bundle rsync_snipe (1)
cf3> =========================================================
cf3>
cf3> Observe process table with /bin/ps -eo
user,pid,ppid,pgid,pcpu,pmem,vsz,pri,rss,nlwp,stime,time,args
cf3>
cf3> .........................................................
cf3> Promise handle:
cf3> Promise made by: rsync
cf3> .........................................................
cf3>
cf3> Selection filter matched absolute STIME/START = Feb16 in
[0,1333553767]
cf3> Selection filter matched absolute STIME/START = Feb16 in
[0,1333553767]
cf3> Selection filter matched absolute STIME/START = Feb23 in
[0,1333553767]
cf3> Selection filter matched absolute STIME/START = Feb23 in
[0,1333553767]
cf3> Selection filter matched absolute STIME/START = Feb09 in
[0,1333553767]
cf3> Selection filter matched absolute STIME/START = Feb09 in
[0,1333553767]
cf3> Selection filter matched absolute STIME/START = Jan25 in
[0,1333553767]
cf3> Selection filter matched absolute STIME/START = Jan25 in
[0,1333553767]
cf3> Selection filter matched absolute STIME/START = Mar01 in
[0,1333553767]
cf3> -> No restart promised for rsync
cf3>
Now, if I remove the stime_range check in the process_select bundle to
be:
body process_select find_old_rsync(age) {
command => '^rsync --daemon*$';
stime_range => irange(0,ago(0,0,45,0,0,0));
process_result => 'command';
}
The output is much closer to what I expect:
cf3> =========================================================
cf3> processes in bundle rsync_snipe (1)
cf3> =========================================================
cf3>
cf3> Observe process table with /bin/ps -eo
user,pid,ppid,pgid,pcpu,pmem,vsz,pri,rss,nlwp,stime,time,args
cf3>
cf3> .........................................................
cf3> Promise handle:
cf3> Promise made by: rsync
cf3> .........................................................
cf3>
cf3> Selection filter matched absolute STIME/START = Feb16 in
[0,1330271365]
cf3> !! Matched: root 2527 4647 2527 0.0 0.0 71888 10 1188
1 Feb16 00:00:00 rsync --daemon
cf3> -> Found matching pid 2527
(root 2527 4647 2527 0.0 0.0 71888 10 1188 1 Feb16
00:00:00 rsync --daemon)
cf3> Selection filter matched absolute STIME/START = Feb16 in
[0,1330271365]
cf3> !! Matched: root 2672 4647 2672 0.0 0.0 71888 10 1188
1 Feb16 00:00:00 rsync --daemon
cf3> -> Found matching pid 2672
(root 2672 4647 2672 0.0 0.0 71888 10 1188 1 Feb16
00:00:00 rsync --daemon)
[etc]
Other checks in process_result, such as "pid" appear to work correctly.
Am I doing something really wrong here with regards to what stime_range
wants for input, or could this be a bug? The reference guide is pretty
thin on what exactly the input numbers for stime_range (and ttime_rante)
are for. The range appears to be absolute epoch time, but that's not
completely clear.
--
Jesse Becker
NHGRI Linux support (Digicon Contractor)
:(){ :&:};:
_______________________________________________
Help-cfengine mailing list
[email protected]
https://cfengine.org/mailman/listinfo/help-cfengine