X-Git-Url: https://gerrit.opnfv.org/gerrit/gitweb?a=blobdiff_plain;f=utils%2Fjenkins-jnlp-connect.sh;h=cd81f29d3a8e59a8c78c2968b205c3b42eab2540;hb=25e73c4cf7a3e617ab0015d1ce61f51d07befade;hp=8337684ec4cb1107b7a0b8ab54e9f3e7d28efd50;hpb=d6e609cd29998ea7c146eea48fbaa40994f4e29f;p=releng.git diff --git a/utils/jenkins-jnlp-connect.sh b/utils/jenkins-jnlp-connect.sh index 8337684ec..cd81f29d3 100755 --- a/utils/jenkins-jnlp-connect.sh +++ b/utils/jenkins-jnlp-connect.sh @@ -52,7 +52,7 @@ main () { fi if [[ $(whoami) != "root" ]]; then - if sudo -l | grep "requiretty"; then + if sudo -l | grep "requiretty" | grep -v "\!requiretty"; then echo "please comment out Defaults requiretty from /etc/sudoers" exit 1 fi @@ -61,8 +61,8 @@ main () { #make pid dir pidfile="/var/run/$jenkinsuser/jenkins_jnlp_pid" if ! [ -d /var/run/$jenkinsuser/ ]; then - mkdir /var/run/$jenkinsuser/ - chown $jenkinsuser:$jenkinsuser /var/run/$jenkinsuser/ + sudo mkdir /var/run/$jenkinsuser/ + sudo chown $jenkinsuser:$jenkinsuser /var/run/$jenkinsuser/ fi if [[ $skip_monit != true ]]; then @@ -92,21 +92,36 @@ main () { exit 1 fi + chown=$(type -p chown) + mkdir=$(type -p mkdir) + makemonit () { echo "Writing the following as monit config:" cat << EOF | tee $monitconfdir/jenkins +check directory jenkins_piddir path /var/run/$jenkinsuser +if does not exist then exec "$mkdir -p /var/run/$jenkinsuser" +if failed uid $jenkinsuser then exec "$chown $jenkinsuser /var/run/$jenkinsuser" +if failed gid $jenkinsuser then exec "$chown :$jenkinsuser /var/run/$jenkinsuser" + 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)'" +depends on jenkins_piddir EOF } if [[ -f $monitconfdir/jenkins ]]; then #test for diff if [[ "$(diff $monitconfdir/jenkins <(echo "\ +check directory jenkins_piddir path /var/run/$jenkinsuser +if does not exist then exec \"$mkdir -p /var/run/$jenkinsuser\" +if failed uid $jenkinsuser then exec \"$chown $jenkinsuser /var/run/$jenkinsuser\" +if failed gid $jenkinsuser then exec \"$chown :$jenkinsuser /var/run/$jenkinsuser\" + 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)'\"\ +stop program = \"/bin/bash -c '/bin/kill \$(/bin/cat /var/run/$jenkinsuser/jenkins_jnlp_pid)'\" +depends on jenkins_piddir\ ") )" ]]; then echo "Updating monit config..." makemonit $@ @@ -116,33 +131,33 @@ stop program = \"/bin/bash -c '/bin/kill \$(/bin/cat /var/run/$jenkinsuser/jenki fi fi -if [[ $started_monit == "true" ]]; then - wget --timestamping https://build.opnfv.org/ci/jnlpJars/slave.jar && true - chown $jenkinsuser:$jenkinsuser slave.jar + if [[ $started_monit == "true" ]]; then + wget --timestamping https://build.opnfv.org/ci/jnlpJars/slave.jar && true + chown $jenkinsuser:$jenkinsuser slave.jar - if [[ -f /var/run/$jenkinsuser/jenkins_jnlp_pid ]]; then - echo "pid file found" - if ! kill -0 "$(/bin/cat /var/run/$jenkinsuser/jenkins_jnlp_pid)"; then - echo "no java process running cleaning up pid file" - rm -f /var/run/$jenkinsuser/jenkins_jnlp_pid; - else - echo "java connection process found and running already running quitting." - exit 1 + if [[ -f /var/run/$jenkinsuser/jenkins_jnlp_pid ]]; then + echo "pid file found" + if ! kill -0 "$(/bin/cat /var/run/$jenkinsuser/jenkins_jnlp_pid)"; then + echo "no java process running cleaning up pid file" + rm -f /var/run/$jenkinsuser/jenkins_jnlp_pid; + else + echo "java connection process found and running already running quitting." + exit 1 + fi fi - fi - if [[ $run_in_foreground == true ]]; then - $connectionstring + if [[ $run_in_foreground == true ]]; then + $connectionstring + else + exec $connectionstring & + echo $! > /var/run/$jenkinsuser/jenkins_jnlp_pid + fi else - exec $connectionstring & - echo $! > /var/run/$jenkinsuser/jenkins_jnlp_pid + echo "you are ready to start monit" + echo "eg: service monit start" + echo "example debug mode if you are having problems: /usr/bin/monit -Ivv -c /etc/monit.conf " + exit 0 fi -else - echo "you are ready to start monit" - echo "eg: service monit start" - echo "example debug mode if you are having problems: /usr/bin/monit -Ivv -c /etc/monit.conf " - exit 0 -fi } usage() {