Add start delay to monit for jnlp daemon
[releng.git] / utils / jenkins-jnlp-connect.sh
index be9fe18..c8a2b49 100755 (executable)
@@ -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
@@ -84,21 +84,30 @@ main () {
 
         if [ -d /etc/monit/conf.d ]; then
             monitconfdir="/etc/monit/conf.d/"
+            monitconfig="/etc/monit/monitrc"
+            #add start delay
+            sed -i '/^#.* delay /s/^#//' "$monitconfig"
         elif [ -d /etc/monit.d ]; then
             monitconfdir="/etc/monit.d"
+            monitconfig="/etc/monitrc"
+            #add start delay
+            sed -i '/^#.* delay /s/^#//' "$monitconfig"
         else
             echo "Could not determine the location of the monit configuration file."
             echo "Make sure monit is installed."
             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 "/usr/bin/mkdir -p /var/run/$jenkinsuser"
-if failed uid $jenkinsuser then exec "/usr/bin/chown $jenkinsuser /var/run/$jenkinsuser"
-if failed gid $jenkinsuser then exec "/usr/bin/chown :$jenkinsuser /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"
@@ -111,9 +120,9 @@ EOF
             #test for diff
             if [[ "$(diff $monitconfdir/jenkins <(echo "\
 check directory jenkins_piddir path /var/run/$jenkinsuser
-if does not exist then exec \"/usr/bin/mkdir -p /var/run/$jenkinsuser\"
-if failed uid $jenkinsuser then exec \"/usr/bin/chown $jenkinsuser /var/run/$jenkinsuser\"
-if failed gid $jenkinsuser then exec \"/usr/bin/chown :$jenkinsuser /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\"