From 2c9e12466085b7a19dc55cdadde252645ac7478e Mon Sep 17 00:00:00 2001 From: Magicalex Date: Thu, 19 Nov 2020 18:13:36 +0100 Subject: [PATCH] fix(): chown performance improvement --- rootfs/usr/local/bin/extension | 6 +++--- rootfs/usr/local/bin/startup | 27 ++++++++++++--------------- 2 files changed, 15 insertions(+), 18 deletions(-) diff --git a/rootfs/usr/local/bin/extension b/rootfs/usr/local/bin/extension index 362f8fa..bddd408 100644 --- a/rootfs/usr/local/bin/extension +++ b/rootfs/usr/local/bin/extension @@ -25,7 +25,7 @@ su-exec "${UID}:${GID}" touch "${LIST_FILE}" case "${action}" in # Install a flarum extension "require") - COMPOSER_CACHE_DIR="${CACHE_DIR}" composer require "$package" + COMPOSER_CACHE_DIR="${CACHE_DIR}" su-exec "${UID}:${GID}" composer require "${package}" if [ $? -eq 0 ]; then echo "${package}" >> "${LIST_FILE}" echo -e "\n${CGREEN}${package} added to flarum.${CEND}" @@ -37,7 +37,7 @@ case "${action}" in ;; # Remove a flarum extension "remove") - COMPOSER_CACHE_DIR="$CACHE_DIR" composer remove "${package}" + COMPOSER_CACHE_DIR="$CACHE_DIR" su-exec "${UID}:${GID}" composer remove "${package}" if [ $? -eq 0 ]; then sed -i "\|${package}|d" "$LIST_FILE" echo -e "\n${CGREEN}${package} removed from flarum${CEND}" @@ -50,7 +50,7 @@ case "${action}" in ;; # Other composer action *) - COMPOSER_CACHE_DIR="${CACHE_DIR}" composer "${@}" + COMPOSER_CACHE_DIR="${CACHE_DIR}" su-exec "${UID}:${GID}" composer "${@}" ;; esac diff --git a/rootfs/usr/local/bin/startup b/rootfs/usr/local/bin/startup index f48f2e9..f6698d3 100644 --- a/rootfs/usr/local/bin/startup +++ b/rootfs/usr/local/bin/startup @@ -17,12 +17,16 @@ sed -i "s//${UPLOAD_MAX_SIZE}/g" /etc/nginx/nginx.conf /etc/php sed -i "s//${PHP_MEMORY_LIMIT}/g" /etc/php7/php-fpm.conf sed -i "s//${OPCACHE_MEMORY_LIMIT}/g" /etc/php7/conf.d/00_opcache.ini -# Set permissions +# Set permissions for /flarum folder +echo "[INFO] Setting folder permissions" for folder in /services /var/log /var/lib/nginx; do - find ${folder} ! -user "${UID}" -exec chown -h "${UID}:${GID}" {} \; - find ${folder} ! -group "${GID}" -exec chown -h "${UID}:${GID}" {} \; + find ${folder} ! -user "${UID}" -exec chown -h "${UID}:${GID}" {} \+ + find ${folder} ! -group "${GID}" -exec chown -h "${UID}:${GID}" {} \+ done +find /flarum ! -user "${UID}" -exec chown "${UID}:${GID}" {} \+ +find /flarum ! -group "${GID}" -exec chown "${UID}:${GID}" {} \+ + # Set log output to STDOUT if wanted (LOG_TO_STDOUT=true) if [ "${LOG_TO_STDOUT}" = true ]; then echo "[INFO] Logging to stdout activated" @@ -36,13 +40,13 @@ if [ -n "${PHP_EXTENSIONS}" ]; then for php_extension in ${PHP_EXTENSIONS}; do PACKAGES="php7-${php_extension} ${PACKAGES}" done - + echo "[INFO] Adding php extensions" apk add --no-progress --no-cache ${PACKAGES} fi cd /flarum/app -# add github token authentication (eg. for privates extensions) +# Add github token authentication (eg. for privates extensions) if [ "${GITHUB_TOKEN_AUTH}" != false ]; then echo "[INFO] Adding github token authentication" composer config github-oauth.github.com "${GITHUB_TOKEN_AUTH}" @@ -54,7 +58,7 @@ if [ -f '/flarum/app/extensions/composer.repositories.txt' ]; then repository="$(echo ${line} | cut -d '|' -f1)" json="$(echo ${line} | cut -d '|' -f2)" echo "[INFO] Adding ${repository} composer repository" - composer config repositories."${repository}" "${json}" + composer config repositories."${repository}" --json "${json}" done < /flarum/app/extensions/composer.repositories.txt fi @@ -79,7 +83,7 @@ if [ -e '/flarum/app/public/assets/rev-manifest.json' ]; then -e "s||${DB_PREF}|g" \ -e "s||${FORUM_URL}|g" /flarum/app/config.php.sample - cp /flarum/app/config.php.sample /flarum/app/config.php + cp -p /flarum/app/config.php.sample /flarum/app/config.php su-exec "${UID}:${GID}" php /flarum/app/flarum cache:clear # Composer cache dir and packages list paths @@ -93,7 +97,7 @@ if [ -e '/flarum/app/public/assets/rev-manifest.json' ]; then extension="${extension}${line} " done < /flarum/app/extensions/list cmd="composer require ${extension}" - COMPOSER_CACHE_DIR="${CACHE_DIR}" eval "${cmd}" + COMPOSER_CACHE_DIR="${CACHE_DIR}" su-exec "${UID}:${GID}" eval "${cmd}" echo "[INFO] Install extra bundled extensions: DONE." else echo "[INFO] No installed extensions" @@ -123,16 +127,9 @@ else -e "s||${FLARUM_TITLE}|g" /flarum/app/config.yml # Install flarum - find /flarum ! -user "${UID}" -exec chown "${UID}:${GID}" {} \; - find /flarum ! -group "${GID}" -exec chown "${UID}:${GID}" {} \; su-exec "${UID}:${GID}" php /flarum/app/flarum install --file=/flarum/app/config.yml echo "[INFO] End of flarum installation" fi -# Set permissions for /flarum folder -echo "[INFO] Setting folder permissions" -find /flarum ! -user "${UID}" -exec chown "${UID}:${GID}" {} \+ -find /flarum ! -group "${GID}" -exec chown "${UID}:${GID}" {} \+ - echo "[Info] End of startup script. Forum is starting." exec su-exec "${UID}:${GID}" /bin/s6-svscan /services