X-Git-Url: https://gerrit.opnfv.org/gerrit/gitweb?a=blobdiff_plain;f=utils%2Fjenkins-jnlp-connect.sh;h=9ef4298efeca34ef6f49bbe9bb0b44a7fe372fd3;hb=7891b74307d0c69acf5d7a77e8393dc46b3f903b;hp=8c41620d6de7e7875e55766a289ef6f1eb12280d;hpb=9a758c37d8464ba6a452f83b30e8bf8af072eb67;p=releng.git diff --git a/utils/jenkins-jnlp-connect.sh b/utils/jenkins-jnlp-connect.sh index 8c41620d6..9ef4298ef 100755 --- a/utils/jenkins-jnlp-connect.sh +++ b/utils/jenkins-jnlp-connect.sh @@ -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.