diff --git a/README.md b/README.md index d663623..a8d6fa9 100644 --- a/README.md +++ b/README.md @@ -129,7 +129,8 @@ Define the ENV variables in docker-compose.yml file | AUTO_UPDATE_MOODLE | true | Set to false to disable performing update of Moodle (e.g. plugins) at docker start | | UPDATE_MOODLE_CODE | true | Set to false to disable auto download latest patch of Moodle core code, only effective if AUTO_UPDATE_MOODLE is true or built with ARG_ENABLE_GIT_CLONE as true | | DISABLE_WEB_INSTALL_PLUGIN | false | Set to true to disable plugin installation via site admin UI, could be useful to avoid image outsync with HA setting | -| MAINT_STATUS_KEYWORD | Status: enabled | Keyword for detecting Moodle maintainence status when running admin/cli/maintenance.php, language following the Moodle site default language | +| MAINT_STATUS_KEYWORD | Status: enabled | Keyword for detecting Moodle maintenance status when running admin/cli/maintenance.php, language following the Moodle site default language | +| LOCAL_CACHE_DIRECTORY | | Set the path to a local fast filesystem for Moodle local caching that no need to be shared with other instances | ### Important Note about using `AUTO_UPDATE_MOODLE` and `UPDATE_MOODLE_CODE` diff --git a/rootfs/docker-entrypoint-init.d/02-configure-moodle.sh b/rootfs/docker-entrypoint-init.d/02-configure-moodle.sh index 78c4384..31fe6d5 100755 --- a/rootfs/docker-entrypoint-init.d/02-configure-moodle.sh +++ b/rootfs/docker-entrypoint-init.d/02-configure-moodle.sh @@ -97,7 +97,29 @@ if [ ! -f "${WEB_PATH}"/config.php ]; then # shellcheck disable=SC2016 sed -i '/require_once/i $CFG->xsendfile = '\''X-Accel-Redirect'\'';' "${WEB_PATH}"/config.php # shellcheck disable=SC2016 - sed -i '/require_once/i $CFG->xsendfilealiases = array('\''\/dataroot\/'\'' => $CFG->dataroot);' "${WEB_PATH}"/config.php + sed -i '/require_once/i $CFG->xsendfilealiases = array(' "${WEB_PATH}"/config.php + # shellcheck disable=SC2016 + sed -i "/\$CFG->xsendfilealiases/a );" "${WEB_PATH}"/config.php + # shellcheck disable=SC2016 + sed -i "/\$CFG->xsendfilealiases/a \ \ "\''/dataroot/'\'" => \$CFG->dataroot," "${WEB_PATH}"/config.php + + if [ -n "$LOCAL_CACHE_DIRECTORY" ]; then + if [ ! -d "$LOCAL_CACHE_DIRECTORY" ]; then + echo "Creating $LOCAL_CACHE_DIRECTORY for localcachedir..." + mkdir -p "$LOCAL_CACHE_DIRECTORY" + fi + # shellcheck disable=SC2016 + sed -i "/require_once/i \$CFG->localcachedir = \'$LOCAL_CACHE_DIRECTORY\';" "${WEB_PATH}"/config.php + # shellcheck disable=SC2016 + sed -i "/\$CFG->xsendfilealiases/a \ \ "\''/localcachedir/'\'" => \'$LOCAL_CACHE_DIRECTORY\'," "${WEB_PATH}"/config.php + cat << EOL >> /etc/nginx/conf.d/default/server/moodle.conf + location ~ ^/localcachedir/(.*)$ { + internal; + alias $LOCAL_CACHE_DIRECTORY/\$1; + } +EOL + echo "Set $LOCAL_CACHE_DIRECTORY as localcachedir" + fi if [ "$SSLPROXY" = 'true' ]; then # shellcheck disable=SC2016