From fcae1055278374b01cc9b5e1c76237a3f49e1120 Mon Sep 17 00:00:00 2001
From: Britney Fransen <brfransen@gmail.com>
Date: Wed, 29 Nov 2017 20:39:45 +0000
Subject: LinHES-system: checkXFSfrag.sh: add --idle option that uses idle.py
 to check system idle before defrag

xfs_defrag.cron: use the --idle option of checkXFSfrag.sh
---
 abs/core/LinHES-system/PKGBUILD        |  6 +++---
 abs/core/LinHES-system/checkXFSfrag.sh | 10 ++++++++++
 abs/core/LinHES-system/xfs_defrag.cron |  2 +-
 3 files changed, 14 insertions(+), 4 deletions(-)

diff --git a/abs/core/LinHES-system/PKGBUILD b/abs/core/LinHES-system/PKGBUILD
index 237f686..3ff5184 100755
--- a/abs/core/LinHES-system/PKGBUILD
+++ b/abs/core/LinHES-system/PKGBUILD
@@ -1,6 +1,6 @@
 pkgname=LinHES-system
 pkgver=8.5
-pkgrel=1
+pkgrel=2
 arch=('i686' 'x86_64')
 install=system.install
 pkgdesc="Everything that makes LinHES an automated system"
@@ -126,7 +126,7 @@ md5sums=('c6e6b83a1f4c35ef4501e277657ab2ac'
          'bacc813b48bafcc6fe906e5969930501'
          'dedd3fcb1abec6361f4060d8149c7d6d'
          '8b0298f70f97cc1dc2a58b9a73c64bd3'
-         '85558db5864bc70676ef46acc4595f88'
+         'd2f1bec810a740885d9c0a2893186587'
          'e30bf8ec8b9dcc2ceb7127375a91d8d1'
          'e9f545c3bcf9c85b45496c281fc6a1b8'
          'a94fe6d980f4b810f2e2ae5352084b39'
@@ -142,7 +142,7 @@ md5sums=('c6e6b83a1f4c35ef4501e277657ab2ac'
          '02c810c2f47b7c4495fdacaf54189473'
          '1aac1872bf9569ea58ceb2f6f766a654'
          '1fb7b4badf30508b0a761a2ae7d7887d'
-         '4d7164800122243be6513b29c8fc498e'
+         '8d7b147972dc30a38e093825eb9f4b02'
          '0b05329fda4b7c982778c233495a53d9'
          '36bdfa8d877cea20ca3870faf08e08d5'
          '59d0602bac7e06f11abba1894acc8bb0'
diff --git a/abs/core/LinHES-system/checkXFSfrag.sh b/abs/core/LinHES-system/checkXFSfrag.sh
index 5fccece..d25eaa8 100755
--- a/abs/core/LinHES-system/checkXFSfrag.sh
+++ b/abs/core/LinHES-system/checkXFSfrag.sh
@@ -31,12 +31,22 @@ e='/usr/bin/echo -e'                                # Use the echo command, not
 xfsfsr=/usr/bin/xfs_fsr                            # Set variable with the path to xfs_fsr.
 xfsdb=/usr/bin/xfs_db                              # Set variable with the path to xfs_db.
 ionice=/usr/bin/ionice                             # Set variable with the path to ionice.
+idle='/usr/LH/bin/idle.py -s'                      # Set varialbe with path to idle.py.
 pctmax=12                                        # Set maxiumum frag percent needed for defrag.
                                                 # This is zero here for testing purposes only
                                                 # a higher number should be used in production.
 array=`df -T|grep xfs|cut -f 1 --delim=" "`     # Array of all XFS file systems.
 for i in ${array[@]};
 do
+        #check for idle flag
+        if [[ $1 == "--idle" ]]
+        then
+            while ! $idle
+            do
+                echo "System is busy. Waiting 10 minutes before trying again."
+                sleep 600
+            done
+        fi
         #check that the device is SATA and skip defrag on SSDs
         device=`echo ${i} | cut -f 3 --delim="/" | sed 's/[0-9]//g'`
         isSATA=`cat /sys/block/${device}/queue/rotational`
diff --git a/abs/core/LinHES-system/xfs_defrag.cron b/abs/core/LinHES-system/xfs_defrag.cron
index e47176b..792a4b4 100755
--- a/abs/core/LinHES-system/xfs_defrag.cron
+++ b/abs/core/LinHES-system/xfs_defrag.cron
@@ -1,3 +1,3 @@
 #!/bin/bash
 #. /etc/profile
-/usr/LH/bin/checkXFSfrag.sh | /usr/bin/logger -t xfs_defrag
+/usr/LH/bin/checkXFSfrag.sh --idle | /usr/bin/logger -t xfs_defrag
-- 
cgit v0.12

