Skip to content
Browse files
Merge pull request #87 from raul-arabaolaza/JENKINS-23273
[JENKINS-23273] RPM post-install should not do a "chown -R ${JENKINS_USER:-jenkins} ${JENKINS_HOME:-/var/lib/jenkins}"
  • Loading branch information
svanoort committed Apr 4, 2017
2 parents 2206ee9 + 322d0ee commit eb7579d4d39466ade20f0405ce1b0e2a28d764de
Showing with 40 additions and 20 deletions.
  1. +40 −20 rpm/build/SPECS/jenkins.spec
@@ -76,30 +76,51 @@ rm -rf "%{buildroot}"
/usr/sbin/useradd -g %{name} -s /bin/false -r -c "@@SUMMARY@@" \
-d "%{workdir}" %{name} &>/dev/null || :

# Used to decide later if we should perform a chown in case JENKINS_INSTALL_SKIP_CHOWN is false
# Check if a previous installation exists, if so check the JENKINS_HOME value and existing owners of work, log and cache dir, need to to this check
# here because the %files directive overwrites folder owners, I have not found a simple way to make the
# files directive to use JENKINS_USER as owner.
if [ -f "/etc/sysconfig/%{name}" ]; then
logger -t %{name}.installer "Found previous config file /etc/sysconfig/%{name}"
. "/etc/sysconfig/%{name}"
stat --format=%U "/var/cache/%{name}" > "/tmp/%{name}.installer.cacheowner"
stat --format=%U "/var/log/%{name}" > "/tmp/%{name}.installer.logowner"
stat --format=%U ${JENKINS_HOME:-%{workdir}} > "/tmp/%{name}.installer.workdirowner"
logger -t %{name}.installer "No previous config file /etc/sysconfig/%{name} found"

/sbin/chkconfig --add %{name}

# If we have an old hudson install, rename it to jenkins
if test -d /var/lib/hudson; then
# leave a marker to indicate this came from Hudson.
# could be useful down the road
# This also ensures that the .??* wildcard matches something
touch /var/lib/hudson/.moving-hudson
mv -f /var/lib/hudson/* /var/lib/hudson/.??* /var/lib/%{name}
rmdir /var/lib/hudson
find /var/lib/%{name} -user hudson -exec chown %{name} {} + || true
if test -d /var/run/hudson; then
mv -f /var/run/hudson/* /var/run/%{name}
rmdir /var/run/hudson

# Ensure the right ownership on files
function chownIfNecessary {
logger -t %{name}.installer "Checking ${2} ownership"
if [ -f "${1}" ] ; then
owner=$(cat "$1")
rm -f "$1"
logger -t %{name}.installer "Found previous owner of ${2}: ${owner} "
if [ "${owner:-%{name}}" != "${JENKINS_USER:-%{name}}" ] ; then
logger -t %{name}.installer "Previous owner of ${2} is different than configured JENKINS_USER... Doing a recursive chown of ${2} "
chown -R ${JENKINS_USER:-%{name}} "$2"
elif [ "${JENKINS_USER:-%{name}}" != "%{name}" ] ; then
# User has changed ownership of files and JENKINS_USER, chown only the folder
logger -t %{name}.installer "Configured JENKINS_USER is different than default... Doing a non recursive chown of ${2} "
chown ${JENKINS_USER:-%{name}} "$2"
logger -t %{name}.installer "No chown needed for ${2} "

# Ensure the right ownership on files only if not owned by JENKINS_USER and JENKINS_USER
# != %{name}, namely all cases but the default one (configured for %{name} owned by %{name})
# In any case if JENKINS_INSTALL_SKIP_CHOWN is true we do not chown anything to maintain
# the existing semantics
. /etc/sysconfig/%{name}
if test x"$JENKINS_INSTALL_SKIP_CHOWN" != "xtrue"; then
chown -R ${JENKINS_USER:-%{name}} /var/cache/%{name}
chown -R ${JENKINS_USER:-%{name}} /var/log/%{name}
chown -R ${JENKINS_USER:-%{name}} ${JENKINS_HOME:-%{workdir}}
chownIfNecessary "/tmp/%{name}.installer.cacheowner" "/var/cache/%{name}"
chownIfNecessary "/tmp/%{name}.installer.logowner" "/var/log/%{name}"
chownIfNecessary "/tmp/%{name}.installer.workdirowner" ${JENKINS_HOME:-%{workdir}}

@@ -136,4 +157,3 @@ exit 0
- Removed the jenkins.repo installation. Per
* Wed Sep 28 2011
- See [@@CHANGELOG_PAGE@@] for complete details

0 comments on commit eb7579d

Please sign in to comment.