Detect if our script file has been changed and restart
authorSteve McIntyre <steve@einval.com>
Tue, 6 Nov 2018 16:58:36 +0000 (16:58 +0000)
committerSteve McIntyre <steve@einval.com>
Tue, 6 Nov 2018 16:58:36 +0000 (16:58 +0000)
Can happen if we have more than one instance running

bin/build-client

index 6d563d6..8ec71b5 100755 (executable)
@@ -90,6 +90,8 @@ SLEEP_NO_JOB_DEFAULT=10
 SLEEP_NO_JOB_SLOW=600
 SLEEP_TIME=$SLEEP_NO_JOB_DEFAULT
 
+START_TIME=$(date +'%s')
+
 while true; do
     # How many times in a row have we asked for a job and not got
     # anything? If this gets high, back off
@@ -103,6 +105,12 @@ while true; do
     # Should we update ourselves?
     attempt_update
 
+    SCRIPT_TIME=$(stat -c %Y $0)
+    if [ $SCRIPT_TIME -gt $START_TIME ]; then
+       echo "$@ updated under me, need to restart"
+       exec $ME $@
+    fi
+
     # Ask jack for a package to build
     BNUM_PKG_VER_ARCH=$(ssh build@jack ./bin/get_package $HOSTNAME)
     BNUM=$(echo $BNUM_PKG_VER_ARCH | cut -d " " -f1)