diff options
author | Holger Levsen <holger@layer-acht.org> | 2015-03-20 13:19:52 +0100 |
---|---|---|
committer | Holger Levsen <holger@layer-acht.org> | 2015-03-20 13:19:52 +0100 |
commit | 541b1d3ecba24f7031bbcbb5f32575210cd38ac8 (patch) | |
tree | 1cfe9644f9f951153dc5da567e6811d499a5f0d2 /bin | |
parent | 186e4609f2e87687503b5ea79480ea8440d73d35 (diff) | |
download | jenkins.debian.net-541b1d3ecba24f7031bbcbb5f32575210cd38ac8.tar.xz |
reproducible: only kill parentless processes if they are older than a day
Diffstat (limited to 'bin')
-rwxr-xr-x | bin/reproducible_maintainance.sh | 18 |
1 files changed, 12 insertions, 6 deletions
diff --git a/bin/reproducible_maintainance.sh b/bin/reproducible_maintainance.sh index a473da17..d0026e40 100755 --- a/bin/reproducible_maintainance.sh +++ b/bin/reproducible_maintainance.sh @@ -113,19 +113,25 @@ RESULT=$(mktemp) PBUIDS="1234 1111 2222" ps axo pid,user,size,pcpu,cmd > $HAYSTACK for i in $PBUIDS ; do - for ZOMBIE in $(pgrep -u $i -P 1 || true) ; do + for PROCESS in $(pgrep -u $i -P 1 || true) ; do # faked-sysv comes and goes... - grep ^$ZOMBIE $HAYSTACK | grep -v faked-sysv >> $RESULT 2> /dev/null || true + grep ^$PROCESS $HAYSTACK | grep -v faked-sysv >> $RESULT 2> /dev/null || true done done if [ -s $RESULT ] ; then echo - echo "Warning: processes found which should not be there, killing them now:" + echo "Warning: processes found which should not be there, maybe killing them now:" cat $RESULT echo - ZOMBIES=$(cat $RESULT | cut -d " " -f1 | xargs echo) - sudo kill -9 $(echo $ZOMBIES) 2>&1 - echo "'kill -9 $(echo $ZOMBIES)' done." + for PROCESS in $(cat $RESULT | cut -d " " -f1 | xargs echo) ; do + AGE=$(ps -p $PROCESS -o etimes= || echo 0) + if [ $AGE -gt 86400 ] ; then + sudo kill -9 $PROCESS 2>&1 + echo "'kill -9 $PROCESS' done." + else + echo "Did not kill $PROCESS as it is only $AGE seconds old." + fi + done echo DIRTY=true fi |