From 3b3f98a4a16994681e5aa115f9fc986663f0f1cf Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Robert=20Martin-Leg=C3=A8ne?= <robert@nic.ar>
Date: Thu, 27 Sep 2018 12:39:09 -0300
Subject: [PATCH] Starting monitor from start.sh. Cron.sh now only calls
 start.sh

---
 bin/cron.sh       | 11 +----------
 bin/installbfa.sh |  1 +
 bin/start.sh      | 20 ++++++++++++++++++++
 3 files changed, 22 insertions(+), 10 deletions(-)

diff --git a/bin/cron.sh b/bin/cron.sh
index e1f8ca4..50a0b0a 100755
--- a/bin/cron.sh
+++ b/bin/cron.sh
@@ -8,13 +8,4 @@ exec < /dev/null > bfa-cron-output.log 2>&1
 # Go to script bin, 'cause we expect to find $BFAHOME/bin/env there
 cd `dirname $0`
 source ./env
-(
-    ./start.sh &
-    # Yes, we wait 60 seconds after starting the server.
-    # If you don't want to wait, kill the sleep.. the || true
-    # will capture the ERR trap.
-    while sleep 60 || true
-    do
-        ./monitor.sh
-    done &
-)
+./start.sh
diff --git a/bin/installbfa.sh b/bin/installbfa.sh
index 8f7c884..d21f5de 100755
--- a/bin/installbfa.sh
+++ b/bin/installbfa.sh
@@ -163,6 +163,7 @@ function usersetup
         info Adding to automatically source \~bfa/bfa/bin/env via .bashrc
         echo 'source ~/bfa/bin/env' >> .bashrc
     fi
+    mkdir ~bfa/bfa/network
 }
 
 function cronit
diff --git a/bin/start.sh b/bin/start.sh
index 734b39a..11dbad6 100755
--- a/bin/start.sh
+++ b/bin/start.sh
@@ -80,6 +80,25 @@ function startbootnode
     ) 9>> $pidfile
 }
 
+function startmonitor
+{
+    local   pidfile=${BFANETWORKDIR}/monitor.pid
+    (
+        flock --nonblock --exclusive 9 || (
+            echo "A monitor is already running."
+            false
+        ) || exit
+        sleep 15
+        while :
+        do
+            monitor.sh &
+            echo $! > $pidfile
+            wait
+            sleep 60
+        done &
+    ) 9>> $pidfile
+}
+
 function startgeth
 {
   # Start the node.
@@ -121,3 +140,4 @@ function startgeth
 
 startgeth
 startbootnode
+startmonitor
-- 
GitLab