utils: jenkins-jnlp-connect.sh: Make monit actions conditional 59/24859/2
authorMarkos Chandras <mchandras@suse.de>
Thu, 24 Nov 2016 14:42:13 +0000 (14:42 +0000)
committerMarkos Chandras <mchandras@suse.de>
Tue, 29 Nov 2016 12:04:10 +0000 (12:04 +0000)
When executing the connection testing command as indicated in [1], -t is
added to the monit start-up script parameters. This prevents the jenkins
service from running in the background and create the pid file. Because
of that, monit is confused and reports the service as failed. We fix
this by moving all the monit related actions inside the 'monit'
conditional block.

[1]: http://artifacts.opnfv.org/octopus/brahmaputra/docs/octopus_docs/opnfv-jenkins-slave-connection.html#connecting-slaves-from-community-labs-to-opnfv-jenkins

Change-Id: I7371c4560311b84f56eff3461254264e1769ff7e
Signed-off-by: Markos Chandras <mchandras@suse.de>
utils/jenkins-jnlp-connect.sh

index 33463e1..56ce61e 100755 (executable)
@@ -58,17 +58,6 @@ main () {
       fi
     fi
 
-
-    if [ -d /etc/monit/conf.d ]; then
-        monitconfdir="/etc/monit/conf.d/"
-    elif [ -d /etc/monit.d ]; then
-        monitconfdir="/etc/monit.d"
-    else
-        echo "Could not determine the location of the monit configuration file."
-        echo "Make sure monit is installed."
-        exit 1
-    fi
-
     #make pid dir
     pidfile="/var/run/$jenkinsuser/jenkins_jnlp_pid"
     if ! [ -d /var/run/$jenkinsuser/ ]; then
@@ -92,29 +81,39 @@ main () {
                 exit 1
             fi
         fi
-    fi
 
-    makemonit () {
-        echo "Writing the following as monit config:"
+        if [ -d /etc/monit/conf.d ]; then
+            monitconfdir="/etc/monit/conf.d/"
+        elif [ -d /etc/monit.d ]; then
+            monitconfdir="/etc/monit.d"
+        else
+            echo "Could not determine the location of the monit configuration file."
+            echo "Make sure monit is installed."
+            exit 1
+        fi
+
+        makemonit () {
+            echo "Writing the following as monit config:"
         cat << EOF | tee $monitconfdir/jenkins
 check process jenkins with pidfile /var/run/$jenkinsuser/jenkins_jnlp_pid
 start program = "/usr/bin/sudo -u $jenkinsuser /bin/bash -c 'cd $jenkinshome; export started_monit=true; $0 $@' with timeout 60 seconds"
 stop program = "/bin/bash -c '/bin/kill \$(/bin/cat /var/run/$jenkinsuser/jenkins_jnlp_pid)'"
 EOF
-    }
+        }
 
-    if [[ -f $monitconfdir/jenkins ]]; then
-        #test for diff
-        if [[ "$(diff $monitconfdir/jenkins <(echo "\
+        if [[ -f $monitconfdir/jenkins ]]; then
+            #test for diff
+            if [[ "$(diff $monitconfdir/jenkins <(echo "\
 check process jenkins with pidfile /var/run/$jenkinsuser/jenkins_jnlp_pid
 start program = \"/usr/bin/sudo -u $jenkinsuser /bin/bash -c 'cd $jenkinshome; export started_monit=true; $0 $@' with timeout 60 seconds\"
 stop program = \"/bin/bash -c '/bin/kill \$(/bin/cat /var/run/$jenkinsuser/jenkins_jnlp_pid)'\"\
 ") )" ]]; then
-            echo "Updating monit config..."
+                echo "Updating monit config..."
+                makemonit $@
+            fi
+        else
             makemonit $@
         fi
-    else
-        makemonit $@
     fi
 
 if [[ $started_monit == "true" ]]; then