commit:     1ed42685935cd83f562c8c8f5c86522d35723189
Author:     Fabian Groffen <grobian <AT> gentoo <DOT> org>
AuthorDate: Wed Aug 17 04:26:03 2016 +0000
Commit:     Fabian Groffen <grobian <AT> gentoo <DOT> org>
CommitDate: Wed Aug 17 04:26:03 2016 +0000
URL:        https://gitweb.gentoo.org/repo/proj/prefix.git/commit/?id=1ed42685

scripts/rsync-generation/refresh-mirror: store pid in a permanent place

 scripts/rsync-generation/refresh-mirror.sh | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/scripts/rsync-generation/refresh-mirror.sh 
b/scripts/rsync-generation/refresh-mirror.sh
index d444d40..348f2bf 100755
--- a/scripts/rsync-generation/refresh-mirror.sh
+++ b/scripts/rsync-generation/refresh-mirror.sh
@@ -10,14 +10,16 @@ if [[ -f /tmp/rsync-master-busy ]] ; then
        # allow one run to be skipped quietly
        if [[ $((laststart + (40 * 60))) -lt ${now} ]] ; then
                echo "another rsync-master generation process is still busy"
-               type pstree > /dev/null && pstree -p $(< /tmp/rsync-master-busy)
+               type pstree > /dev/null && pstree -p $(head -n1 ${LOGFILE})
                ps -ef | grep '[r]efresh-mirror'
                tail ${LOGFILE}
+       else
+               exit 0
        fi
        # if the log reports done, kill it as it seems that for some reason
        # it hangs after doing this
        if [[ $(tail -n1 ${LOGFILE}) == *"rsync done" ]] ; then
-               pid=$(< /tmp/rsync-master-busy)
+               pid=$(head -n1 ${LOGFILE})
                if [[ ${pid} -gt 0 ]] ; then
                        pstree -A -c -p ${pid} | grep -o '[0-9]\+' | xargs kill
                        rm /tmp/rsync-master-busy
@@ -26,8 +28,9 @@ if [[ -f /tmp/rsync-master-busy ]] ; then
 else
        mv ${LOGFILE} ${LOGFILE%.log}-prev.log
        cd "$(readlink -f "${BASH_SOURCE[0]%/*}")"
-       echo $$ > /tmp/rsync-master-busy
-       echo "starting generation $(date)" > ${LOGFILE}
+       touch /tmp/rsync-master-busy
+       echo $$ > ${LOGFILE}
+       echo "starting generation $(date)" >> ${LOGFILE}
        genandpush() {
                ./update-rsync-master.sh \
                        && ./push-rsync1.sh

Reply via email to