Skip to content

Commit a006797

Browse files
committed
fix: run the sitemap builder as www-data
su was called without a user, so the builder ran as root. The webroot is root owned, so the directory and the link are prepared before dropping privileges, and the directory is chowned recursively because the generator reopens the files an older image left behind as root.
1 parent af58b3f commit a006797

1 file changed

Lines changed: 12 additions & 1 deletion

File tree

‎mediawiki/build/run.sh‎

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -472,7 +472,18 @@ su -s /bin/bash -c '/mwjobrunner.sh &' www-data #run in the background as www-d
472472
su -s /bin/bash -c '/mwmaintenance.sh &' www-data
473473
su -s /bin/bash -c '/mwmaintenance_smw.sh &' www-data
474474
if [ "$MW_AUTOBUILD_SITEMAP" == 'true' ]; then
475-
su -s /bin/bash -c '/mwsitemapbuilder.sh "$MW_SITE_SERVER" &' #updates the sitemap in the background
475+
# The builder used to run as root, because su was called without a user.
476+
# $MW_HOME is root owned, so the directory and the link are prepared here
477+
# and the loop itself only needs to write inside sitemap/. The chown also
478+
# takes over a sitemap directory left behind by an older image.
479+
mkdir -p "$MW_HOME/sitemap"
480+
# Recursive, because the generator reopens the files it wrote last time and
481+
# those belong to root on an instance that ran an older image.
482+
chown -R "$WWW_USER":"$WWW_USER" "$MW_HOME/sitemap"
483+
if [ ! -e "$MW_HOME/sitemap.xml" ]; then
484+
ln -s "$MW_HOME/sitemap/sitemap-index-mediawiki.xml" "$MW_HOME/sitemap.xml"
485+
fi
486+
su -s /bin/bash -c '/mwsitemapbuilder.sh "$MW_SITE_SERVER" &' "$WWW_USER" #updates the sitemap in the background
476487
fi
477488

478489
print_logo

0 commit comments

Comments
 (0)