Rearrange the user creation step for slaves 45/40045/1
authorAndrew Grimberg <agrimberg@linuxfoundation.org>
Wed, 8 Jun 2016 15:15:02 +0000 (08:15 -0700)
committerAndrew Grimberg <agrimberg@linuxfoundation.org>
Wed, 8 Jun 2016 15:15:02 +0000 (08:15 -0700)
With the change from JClouds to the OpenStack slave plugin we need to
fully manage the creation of the Jenkins user. This modifies the timing
of when the user gets created to be the last step. This will hopefully
prevent us from having issues with the init scripts not having been
completed before a job starts on the system.

Secondly, we handle adding Jenkins to the docker group in a slightly
more sane manner but without breaking our current production setup that
executes some, but not all of these scripts and in a different order.

Change-Id: I8d88cd0d9de6b3defd6615faa474e4ce8d583ea4
Signed-off-by: Andrew Grimberg <agrimberg@linuxfoundation.org>
jenkins-scripts/create_jenkins_user.sh
jenkins-scripts/docker.sh
jenkins-scripts/jenkins-init-script.sh

index 238f335e161f59677495b63e35003094faedc586..f2874de336e04742fa7c6b70d1c4c15aa65d808d 100755 (executable)
@@ -4,9 +4,18 @@
 # Create Jenkins User #
 #######################
 
-OS=`facter operatingsystem | tr '[:upper:]' '[:lower:]'`
+OS=$(facter operatingsystem | tr '[:upper:]' '[:lower:]')
 
-useradd -m -s /bin/bash jenkins
+# Determine if we need to add jenkins to the docker group
+grep -q docker /etc/group
+if [ "$?" == '0' ]
+then
+  GROUP='-G docker'
+else
+  GROUP=''
+fi
+
+useradd -m ${GROUP} -s /bin/bash jenkins
 mkdir /home/jenkins/.ssh
 mkdir /w
 cp -r /home/${OS}/.ssh/authorized_keys /home/jenkins/.ssh/authorized_keys
index 365dc9574d52a63c4162767bad93995b4149ed1e..c70408da3e7fed32ac3c91361c6db9efbd632948 100755 (executable)
@@ -6,7 +6,13 @@ Defaults:jenkins !requiretty
 jenkins     ALL = NOPASSWD: /sbin/ifconfig
 EOF
 
-/usr/sbin/usermod -a -G docker jenkins
+# make sure jenkins is part of the docker only if jenkins has already been
+# created
+grep -q jenkins /etc/passwd
+if [ "$?" == '0' ]
+then
+  /usr/sbin/usermod -a -G docker jenkins
+fi
 
 # stop firewall
 systemctl stop firewalld
index dfb5ee8587b420f2c3069cfc26eb79a87a2ceb35..88c5eb620bf285281c51cbcbeb6b9a46108ed815 100755 (executable)
@@ -15,5 +15,8 @@ chmod +x *.sh
 
 source /tmp/system_type.sh
 ./basic_settings.sh
-./create_jenkins_user.sh
 ./${SYSTEM_TYPE}.sh
+
+# Create the jenkins user last so that hopefully we don't have to deal with
+# guard files
+./create_jenkins_user.sh