Merge "Upload Generated Documentation to Correct Path"
[releng.git] / utils / jenkins-jnlp-connect.sh
index 8c41620..9ef4298 100755 (executable)
@@ -38,6 +38,11 @@ main () {
         exit 1
     fi
 
+    if [[ $(pwd) != "$jenkinshome" ]]; then
+        echo "This script needs to be run from the jenkins users home dir"
+        exit 1
+    fi
+
     if [[ -z $slave_name || -z $slave_secret ]]; then
         echo "slave name or secret not defined, please edit this file to define it"
         exit 1
@@ -48,6 +53,14 @@ main () {
         exit 1
     fi
 
+    if [[ $(whoami) != "root" ]]; then
+      if sudo -l | grep "requiretty"; then
+        echo "please comment out Defaults requiretty from /etc/sudoers"
+        exit 1
+      fi
+    fi
+
+
     if [ -d /etc/monit/conf.d ]; then
         monitconfdir="/etc/monit/conf.d/"
     elif [ -d /etc/monit.d ]; then
@@ -87,7 +100,7 @@ main () {
         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 $dir; export started_monit=true; $0 $@'"
+start program = "/usr/bin/sudo -u $jenkinsuser /bin/bash -c 'cd $dir; 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
     }
@@ -96,7 +109,7 @@ EOF
         #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 $dir; export started_monit=true; $0 $@'\"
+start program = \"/usr/bin/sudo -u $jenkinsuser /bin/bash -c 'cd $dir; 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..."
@@ -138,6 +151,7 @@ fi
 usage() {
     cat << EOF
 
+**this file must be copied to the jenkins home directory to work**
 jenkins-jnlp-connect.sh configures monit to keep slave connection up
 Checks for new versions of slave.jar
 run as root to create pid directory and create monit config.