diff --git a/azuredeploy.json b/azuredeploy.json index 99649ba4..14231b91 100644 --- a/azuredeploy.json +++ b/azuredeploy.json @@ -217,6 +217,20 @@ }, "type": "string" }, + "moodleDbName": { + "defaultValue": "moodle", + "metadata": { + "description": "Moodle Database name" + }, + "type": "string" + }, + "moodleDbUser": { + "defaultValue": "moodle", + "metadata": { + "description": "Moodle Database username. This user is different from Database admin user." + }, + "type": "string" + }, "mysqlPgresVcores": { "allowedValues": [ 1, @@ -671,6 +685,13 @@ "metadata": { "description": "Azure Location for all resources." } + }, + "isMigration": { + "type": "bool", + "defaultValue": false, + "metadata": { + "description": "Indicates whether the this template is using for migration scenario." + } } }, "resources": [ @@ -1189,10 +1210,10 @@ "lbOutPipName002": "[concat('lb-outpubip002-',variables('resourceprefix'))]", "location": "[parameters('location')]", "moodleAdminPass": "[concat(toUpper('xl'), substring(uniqueString(resourceGroup().id, deployment().name), 6, 7),',1*8')]", - "moodleDbName": "moodle", + "moodleDbName": "[parameters('moodleDbName')]", "moodleDbPass": "[concat('9#36^', substring(uniqueString(resourceGroup().id, deployment().name), 5, 8), toUpper('ercq'))]", - "moodleDbUser": "moodle", - "moodleDbUserAzure": "[concat('moodle', '@', parameters('dbServerType'), '-', variables('resourceprefix'))]", + "moodleDbUser": "[parameters('moodleDbUser')]", + "moodleDbUserAzure": "[concat(parameters('moodleDbUser'), '@', parameters('dbServerType'), '-', variables('resourceprefix'))]", "moodleInstallScriptFilename": "install_moodle.sh", "moodleOnAzureConfigsJsonPath": "/var/lib/cloud/instance/moodle_on_azure_configs.json", "moodleVersion": "[parameters('moodleVersion')]", @@ -1271,7 +1292,8 @@ "vnetName": "[concat('vnet-',variables('resourceprefix'))]", "vpnType": "[parameters('vpnType')]", "webServerSetupScriptFilename": "setup_webserver.sh", - "webServerType": "[parameters('webServerType')]" + "webServerType": "[parameters('webServerType')]", + "isMigration": "[parameters('isMigration')]" }, "certUrlArray": [ { diff --git a/migration/azure-fileshare-sa-deploy.json b/migration/azure-fileshare-sa-deploy.json new file mode 100644 index 00000000..9e744cc4 --- /dev/null +++ b/migration/azure-fileshare-sa-deploy.json @@ -0,0 +1,94 @@ +{ + "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#", + "contentVersion": "1.0.0.0", + "parameters": { + "storageAccountType": { + "defaultValue": "Premium_LRS", + "allowedValues": [ + "Standard_LRS", + "Standard_GRS", + "Standard_ZRS", + "Premium_LRS" + ], + "metadata": { + "description": "Storage Account type." + }, + "type": "string" + }, + "fileServerDiskSize": { + "defaultValue": "1024", + "metadata": { + "description": "Size of the azure file share in GB." + }, + "type": "string" + } + }, + "resources": [ + { + "type": "Microsoft.Resources/deployments", + "apiVersion": "2017-05-10", + "name": "storageAccountTemplate", + "properties": { + "mode": "Incremental", + "parameters": { + "moodleCommon": { + "value": "[variables('moodleCommon')]" + } + }, + "templateLink": { + "uri": "[concat(variables('moodleCommon').baseTemplateUrl,'storageAccount.json',variables('moodleCommon').artifactsSasToken)]" + } + } + }, + { + "type": "Microsoft.Storage/storageAccounts/fileServices/shares", + "apiVersion": "2019-06-01", + "name": "[concat(variables('storageName'), '/default/moodle')]", + "dependsOn": [ + "Microsoft.Resources/deployments/storageAccountTemplate" + ], + "properties": { + "accessTier": "[if(equals(variables('moodleCommon').storageAccountType, 'Premium_LRS'), 'Premium', 'TransactionOptimized')]", + "shareQuota": "[int(variables('moodleCommon').fileServerDiskSize)]", + "enabledProtocols": "SMB" + } + } + ], + "outputs": { + "storageAccountName": { + "type": "string", + "value": "[variables('moodleCommon').storageAccountName]" + }, + "storageAccountType": { + "type": "string", + "value": "[variables('moodleCommon').storageAccountType]" + }, + "fileServerDiskSize": { + "type": "string", + "value": "[variables('moodleCommon').fileServerDiskSize]" + } + }, + "variables": { + "_artifactsLocation": "https://raw.githubusercontent.com/Azure/Moodle/master/", + "_artifactsLocationSasToken": "", + "unsupportedLocations": [ + "eastus2euap", + "westcentralus" + ], + "documentationLine1": "Some of the Azure Services used by moodle migration are not available in few regions. Those regions are declared above.", + "documentationLine2": "If resource group belong to one of those unsupported regions, then use default region 'westus' for deployment.", + "rgLocation": "[toLower(resourceGroup().location)]", + "location": "[if(contains(variables('unsupportedLocations'), variables('rgLocation')), 'westus', variables('rgLocation'))]", + "moodleCommon": { + "baseTemplateUrl": "[concat(variables('_artifactsLocation'), 'nested/')]", + "artifactsSasToken": "[variables('_artifactsLocationSasToken')]", + "fileServerType": "azurefiles", + "location": "[variables('location')]", + "storageAccountName": "[tolower(concat('abs',variables('resourceprefix')))]", + "storageAccountType": "[parameters('storageAccountType')]", + "fileServerDiskSize": "[parameters('fileServerDiskSize')]" + }, + "resourceprefix": "[substring(uniqueString(resourceGroup().id, 'mainTemplate'), 3, 6)]", + "storageName": "[concat(variables('moodleCommon').storageAccountName,if(equals(variables('moodleCommon').fileServerType, 'azurefiles'), 'af', 'naf'))]" + } +} diff --git a/migration/azuredeploy-migration.json b/migration/azuredeploy-migration.json new file mode 100644 index 00000000..a3fc5aa0 --- /dev/null +++ b/migration/azuredeploy-migration.json @@ -0,0 +1,261 @@ +{ + "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#", + "contentVersion": "1.0.0.0", + "parameters": { + "redisDeploySwitch": { + "defaultValue": "false", + "metadata": { + "description": "Switch to deploy a redis cache or not. Note that certain versions of Moodle (e.g., 3.1) don't work well with Redis, so use this only for known well-working Moodle versions (e.g., 3.4)." + }, + "allowedValues": [ + "true", + "false" + ], + "type": "string" + }, + "httpsTermination": { + "allowedValues": [ + "VMSS", + "AppGw", + "None" + ], + "defaultValue": "VMSS", + "metadata": { + "description": "Indicates where https termination occurs. 'VMSS' is for https termination at the VMSS instance VMs (using nginx https proxy). 'AppGw' is for https termination with an Azure Application Gateway. When selecting this, you need to specify all appGw* parameters. 'None' is for testing only with no https. 'None' may not be used with a separately configured https termination layer. If you want to use the 'None' option with your separately configured https termination layer, you'll need to update your Moodle config.php manually for $cfg->wwwroot and $cfg->sslproxy." + }, + "type": "string" + }, + "loadBalancerSku": { + "defaultValue": "Basic", + "allowedValues": [ + "Basic", + "Standard" + ], + "metadata": { + "description": "Loadbalancer SKU" + }, + "type": "string" + }, + "moodleVersion": { + "allowedValues": [ + "MOODLE_39_STABLE", + "MOODLE_38_STABLE" + ], + "defaultValue": "MOODLE_38_STABLE", + "metadata": { + "description": "The Moodle version you want to install." + }, + "type": "string" + }, + "sshPublicKey": { + "metadata": { + "description": "ssh public key" + }, + "type": "string" + }, + "webServerType": { + "defaultValue": "nginx", + "allowedValues": [ + "apache", + "nginx" + ], + "metadata": { + "description": "Web server type" + }, + "type": "string" + }, + "autoscaleVmSku": { + "defaultValue": "Standard_DS2_v2", + "metadata": { + "description": "VM size for autoscaled web VMs" + }, + "type": "string" + }, + "autoscaleVmCountMax": { + "defaultValue": "10", + "metadata": { + "description": "Maximum number of autoscaled web VMs" + }, + "type": "string" + }, + "phpVersion": { + "allowedValues": [ + "7.2", + "7.3", + "7.4" + ], + "defaultValue": "7.4", + "metadata": { + "description": "php version" + }, + "type": "string" + }, + "dbServerType": { + "defaultValue": "mysql", + "allowedValues": [ + "postgres", + "mysql" + ], + "metadata": { + "description": "Database type" + }, + "type": "string" + }, + "moodleDbName": { + "defaultValue": "moodle", + "metadata": { + "description": "Moodle Database name" + }, + "type": "string" + }, + "moodleDbUser": { + "defaultValue": "moodle", + "metadata": { + "description": "Moodle Database username. This user is different from Database admin user." + }, + "type": "string" + }, + "mysqlPgresVcores": { + "allowedValues": [ + "1", + "2", + "4", + "8", + "16", + "32" + ], + "defaultValue": "2", + "metadata": { + "description": "MySql/Postgresql vCores. For Basic tier, only 1 & 2 are allowed. For GeneralPurpose tier, 2, 4, 8, 16, 32 are allowed. For MemoryOptimized, 2, 4, 8, 16 are allowed." + }, + "type": "string" + }, + "mysqlPgresStgSizeGB": { + "defaultValue": "125", + "metadata": { + "description": "MySql/Postgresql storage size in GB. Minimum 5GB, increase by 1GB, up to 1TB (1024 GB)" + }, + "type": "string" + }, + "mysqlPgresSkuTier": { + "allowedValues": [ + "Basic", + "GeneralPurpose", + "MemoryOptimized" + ], + "defaultValue": "GeneralPurpose", + "metadata": { + "description": "MySql/Postgresql sku tier" + }, + "type": "string" + }, + "mysqlPgresSkuHwFamily": { + "allowedValues": [ + "Gen4", + "Gen5" + ], + "defaultValue": "Gen5", + "metadata": { + "description": "MySql/Postgresql sku hardware family. Central US is Gen4 only, so make sure to change this parameter to Gen4 if your deployment is on Central US." + }, + "type": "string" + }, + "mysqlVersion": { + "allowedValues": [ + "5.6", + "5.7" + ], + "defaultValue": "5.7", + "metadata": { + "description": "Mysql version" + }, + "type": "string" + }, + "fileServerDiskSize": { + "defaultValue": "1024", + "metadata": { + "description": "Size per disk for gluster nodes or nfs server" + }, + "type": "string" + }, + "vNetAddressSpace": { + "defaultValue": "172.31.0.0", + "metadata": { + "description": "Address range for the Moodle virtual network and various subnets - presumed /16 for a newly created vnet in case customVnetId is blank. Further subneting (a number of */24 subnets starting from the xxx.yyy.zzz.0/24 will be created on a newly created vnet or your BYO-vnet (specified in customVnetId parameter)." + }, + "type": "string" + }, + "ubuntuVersion": { + "type": "string", + "allowedValues": [ + "18.04-LTS" + ], + "defaultValue": "18.04-LTS" + } + }, + "variables": { + "_artifactsLocation": "https://raw.githubusercontent.com/Azure/Moodle/master/", + "_artifactsLocationSasToken": "", + "unsupportedLocations": [ + "eastus2euap", + "westcentralus" + ], + "documentationLine1": "Some of the Azure Services used by moodle migration are not available in few regions. Those regions are declared above.", + "documentationLine2": "If resource group belong to one of those unsupported regions, then use default region 'westus' for deployment.", + "rgLocation": "[toLower(resourceGroup().location)]", + "location": "[if(contains(variables('unsupportedLocations'), variables('rgLocation')), 'westus', variables('rgLocation'))]" + }, + "resources": [ + { + "type": "Microsoft.Resources/deployments", + "apiVersion": "2017-05-10", + "name": "mainTemplate", + "properties": { + "mode": "Incremental", + "parameters": { + "_artifactsLocation": { "value": "[variables('_artifactsLocation')]" }, + "_artifactsLocationSasToken": { "value": "[variables('_artifactsLocationSasToken')]" }, + "redisDeploySwitch": { "value": "[bool(parameters('redisDeploySwitch'))]" }, + "httpsTermination": { "value": "[parameters('httpsTermination')]"}, + "loadBalancerSku": { "value": "[parameters('loadBalancerSku')]"}, + "siteURL": { "value": ""}, + "moodleVersion": { "value": "[parameters('moodleVersion')]"}, + "sshPublicKey": { "value": "[parameters('sshPublicKey')]" }, + "controllerVmSku": { "value": "Standard_DS1_v2"}, + "webServerType": { "value": "[parameters('webServerType')]"}, + "autoscaleVmSku": { "value": "[parameters('autoscaleVmSku')]" }, + "autoscaleVmCountMax": { "value": "[int(parameters('autoscaleVmCountMax'))]" }, + "phpVersion": { "value": "[parameters('phpVersion')]" }, + "dbServerType": { "value": "[parameters('dbServerType')]" }, + "dbLogin": { "value": "dbadmin" }, + "moodleDbName": { "value": "[parameters('moodleDbName')]" }, + "moodleDbUser": { "value": "[parameters('moodleDbUser')]" }, + "mysqlPgresVcores": { "value": "[int(parameters('mysqlPgresVcores'))]" }, + "mysqlPgresStgSizeGB": { "value": "[int(parameters('mysqlPgresStgSizeGB'))]" }, + "mysqlPgresSkuTier": { "value": "[parameters('mysqlPgresSkuTier')]" }, + "mysqlPgresSkuHwFamily": { "value": "[parameters('mysqlPgresSkuHwFamily')]" }, + "mysqlVersion": { "value": "[parameters('mysqlVersion')]" }, + "postgresVersion": { "value": "9.6" }, + "fileServerType": { "value": "azurefiles" }, + "storageAccountType": { "value": "Premium_LRS" }, + "fileServerDiskSize": { "value": "[int(parameters('fileServerDiskSize'))]" }, + "searchType": { "value": "none" }, + "azureSearchSku": { "value": "basic" }, + "vNetAddressSpace": { "value": "[parameters('vNetAddressSpace')]"}, + "ubuntuVersion": { "value": "[parameters('ubuntuVersion')]"}, + "location": { "value": "[variables('location')]" }, + "isMigration": { "value": true } + }, + "templateLink": { + "uri": "[concat(variables('_artifactsLocation'), 'azuredeploy.json', variables('_artifactsLocationSasToken'))]" + } + } + } + ], + "outputs": { + "mainTemplateOutputs": { + "type": "object", + "value": "[reference('mainTemplate').outputs]" + } + } +} diff --git a/nested/vmsetupparams.json b/nested/vmsetupparams.json index 26f92402..dc17f9b9 100644 --- a/nested/vmsetupparams.json +++ b/nested/vmsetupparams.json @@ -71,7 +71,8 @@ "tikaVmIP": "[parameters('moodleCommon').tikaVmIP]", "syslogServer": "[parameters('moodleCommon').ctlrVmName]", "webServerType": "[parameters('moodleCommon').webServerType]", - "htmlLocalCopySwitch": "[parameters('moodleCommon').htmlLocalCopySwitch]" + "htmlLocalCopySwitch": "[parameters('moodleCommon').htmlLocalCopySwitch]", + "isMigration": "[parameters('moodleCommon').isMigration]" }, "dbServerProfile": { "type": "[parameters('moodleCommon').dbServerType]", diff --git a/scripts/helper_functions.sh b/scripts/helper_functions.sh index 3211f225..69488873 100644 --- a/scripts/helper_functions.sh +++ b/scripts/helper_functions.sh @@ -69,6 +69,7 @@ function get_setup_params_from_configs_json export storageAccountType=$(echo $json | jq -r .moodleProfile.storageAccountType) export fileServerDiskSize=$(echo $json | jq -r .fileServerProfile.fileServerDiskSize) export phpVersion=$(echo $json | jq -r .phpProfile.phpVersion) + export isMigration=$(echo $json | jq -r .moodleProfile.isMigration) } function get_php_version { @@ -127,6 +128,56 @@ function create_azure_files_moodle_share --quota $fileServerDiskSize } +function replace_config_setting_value +{ + local setting_name=$1 + local setting_value=$2 + local delemeter=$3 + local file_name=$4 + + echo "Replacing $setting_name $delemeter $setting_value in $file_name" + + sed -i "s/^\($setting_name\s*$delemeter\s*\).*\$/\1$setting_value/" $file_name +} + +# This function can replace only single line $CFG setting in moodle/config.php file. +# Supported config setting format: +# $CFG->setting = 'value'; +# Usage: +# replace_moodle_config_value "setting" "value" +function replace_moodle_config_value +{ + local formated_setting_name="\$CFG->$1" + local formated_setting_value="'$2';" + local delemeter="=" + local moodle_config_file=/moodle/html/moodle/config.php + + replace_config_setting_value $formated_setting_name $formated_setting_value $delemeter $moodle_config_file +} + +function check_azure_files_moodle_share_exists +{ + local storageAccountName=$1 + local storageAccountKey=$2 + + local azResponse=$(az storage share exists --name moodle --account-name $storageAccountName --account-key $storageAccountKey) + if [ $? -ne 0 ];then + echo "Could not check if moodle file share exists in the storage account ($storageAccountName)" + exit 1 + fi + + echo "az storage share exists command response:" + echo $azResponse + #Sample 'az storage share exists' command response + # { "exists": true } + local exists=$(echo $azResponse | jq -r .exists) + + if [ "$exists" != "true" ];then + echo "File share 'moodle' does not exists in the storage account ($storageAccountName)" + exit 1 + fi +} + function setup_and_mount_gluster_moodle_share { local glusterNode=$1 diff --git a/scripts/install_moodle.sh b/scripts/install_moodle.sh index 424e8753..39958e20 100644 --- a/scripts/install_moodle.sh +++ b/scripts/install_moodle.sh @@ -53,8 +53,8 @@ set -ex echo $dbServerType >> /tmp/vars.txt echo $fileServerType >> /tmp/vars.txt echo $mssqlDbServiceObjectiveName >> /tmp/vars.txt - echo $mssqlDbEdition >> /tmp/vars.txt - echo $mssqlDbSize >> /tmp/vars.txt + echo $mssqlDbEdition >> /tmp/vars.txt + echo $mssqlDbSize >> /tmp/vars.txt echo $installObjectFsSwitch >> /tmp/vars.txt echo $installGdprPluginsSwitch >> /tmp/vars.txt echo $thumbprintSslCert >> /tmp/vars.txt @@ -67,6 +67,7 @@ set -ex echo $storageAccountType >>/tmp/vars.txt echo $fileServerDiskSize >>/tmp/vars.txt echo $phpVersion >> /tmp/vars.txt + echo $isMigration >> /tmp/vars.txt check_fileServerType_param $fileServerType @@ -126,43 +127,55 @@ set -ex elif [ "$dbServerType" = "postgres" ]; then sudo apt-get -y --force-yes install postgresql-client >> /tmp/apt3.log fi - + if [ "$installObjectFsSwitch" = "true" -o "$fileServerType" = "azurefiles" ]; then - # install azure cli & setup container + # install azure cli & setup container AZ_REPO=$(lsb_release -cs) echo "deb [arch=amd64] https://packages.microsoft.com/repos/azure-cli/ $AZ_REPO main" | tee /etc/apt/sources.list.d/azure-cli.list + curl -L https://packages.microsoft.com/keys/microsoft.asc | sudo apt-key add - >> /tmp/apt4.log sudo apt-get -y install apt-transport-https >> /tmp/apt4.log sudo apt-get -y update > /dev/null sudo apt-get -y install azure-cli >> /tmp/apt4.log - + # FileStorage accounts can only be used to store Azure file shares; # Premium_LRS will support FileStorage kind # No other storage resources (blob containers, queues, tables, etc.) can be deployed in a FileStorage account. if [ $storageAccountType != "Premium_LRS" ]; then - az storage container create \ - --name objectfs \ - --account-name $storageAccountName \ - --account-key $storageAccountKey \ - --public-access off \ - --fail-on-exist >> /tmp/wabs.log - - az storage container policy create \ - --account-name $storageAccountName \ - --account-key $storageAccountKey \ - --container-name objectfs \ - --name readwrite \ - --start $(date --date="1 day ago" +%F) \ - --expiry $(date --date="2199-01-01" +%F) \ - --permissions rw >> /tmp/wabs.log - - sas=$(az storage container generate-sas \ - --account-name $storageAccountName \ - --account-key $storageAccountKey \ - --name objectfs \ - --policy readwrite \ - --output tsv) - fi + az storage container create \ + --name objectfs \ + --account-name $storageAccountName \ + --account-key $storageAccountKey \ + --public-access off \ + --fail-on-exist >> /tmp/wabs.log + + az storage container policy create \ + --account-name $storageAccountName \ + --account-key $storageAccountKey \ + --container-name objectfs \ + --name readwrite \ + --start $(date --date="1 day ago" +%F) \ + --expiry $(date --date="2199-01-01" +%F) \ + --permissions rw >> /tmp/wabs.log + + sas=$(az storage container generate-sas \ + --account-name $storageAccountName \ + --account-key $storageAccountKey \ + --name objectfs \ + --policy readwrite \ + --output tsv) + fi + + # If its a migration flow, then mount the azure file share now. + if [ "$isMigration" = "true" ]; then + # On migration flow, the moodle azure file share must present before running this script. + echo -e '\n\rIts a migration flow, check whether moodle fileshare exists\n\r' + check_azure_files_moodle_share_exists $storageAccountName $storageAccountKey + + # Set up and mount Azure Files share. + echo -e '\n\rSetting up and mounting Azure Files share //'$storageAccountName'.file.core.windows.net/moodle on /moodle\n\r' + setup_and_mount_azure_files_moodle_share $storageAccountName $storageAccountKey + fi fi if [ $fileServerType = "gluster" ]; then @@ -289,7 +302,7 @@ worker_processes 2; pid /run/nginx.pid; events { - worker_connections 768; + worker_connections 768; } http { @@ -386,9 +399,9 @@ EOF return 404; } - location / { - try_files \$uri \$uri/index.php?\$query_string; - } + location / { + try_files \$uri \$uri/index.php?\$query_string; + } location ~ [^/]\.php(/|$) { fastcgi_split_path_info ^(.+?\.php)(/.*)$; @@ -793,8 +806,35 @@ EOF siteProtocol="https" fi if [ $dbServerType = "mysql" ]; then - echo -e "cd /tmp; /usr/bin/php /moodle/html/moodle/admin/cli/install.php --chmod=770 --lang=en --wwwroot="$siteProtocol"://"$siteFQDN" --dataroot=/moodle/moodledata --dbhost="$mysqlIP" --dbname="$moodledbname" --dbuser="$azuremoodledbuser" --dbpass="$moodledbpass" --dbtype=mysqli --fullname='Moodle LMS' --shortname='Moodle' --adminuser=admin --adminpass="$adminpass" --adminemail=admin@"$siteFQDN" --non-interactive --agree-license --allow-unstable || true " - cd /tmp; /usr/bin/php /moodle/html/moodle/admin/cli/install.php --chmod=770 --lang=en --wwwroot=$siteProtocol://$siteFQDN --dataroot=/moodle/moodledata --dbhost=$mysqlIP --dbname=$moodledbname --dbuser=$azuremoodledbuser --dbpass=$moodledbpass --dbtype=mysqli --fullname='Moodle LMS' --shortname='Moodle' --adminuser=admin --adminpass=$adminpass --adminemail=admin@$siteFQDN --non-interactive --agree-license --allow-unstable || true + if [ "$isMigration" = "true" ]; then + echo "Importing database from the mysql dump file" + if [ ! -f /moodle/migration-db-moodle.sql.tar.gz ]; then + echo "Migrating moodle DB dump archive file not found." + exit 1 + fi + + tar -xvf /moodle/migration-db-moodle.sql.tar.gz -C /moodle/ + + if [ ! -f /moodle/migration-db-moodle.sql ]; then + echo "Migrating moodle DB dump file not found." + exit 1 + fi + + echo "Importing migration moodle DB." + mysql -h $mysqlIP -u $mysqladminlogin -p${mysqladminpass} ${moodledbname} < /moodle/migration-db-moodle.sql + + echo "Updating moodle db config settings" + replace_moodle_config_value "dbhost" "$mysqlIP" + replace_moodle_config_value "dbuser" "$azuremoodledbuser" + replace_moodle_config_value "dbpass" "$moodledbpass" + + echo "Updating other moodle config settings" + replace_moodle_config_value "dataroot" "\/moodle\/moodledata" + replace_moodle_config_value "wwwroot" "$siteProtocol:\/\/$siteFQDN" + else + echo -e "cd /tmp; /usr/bin/php /moodle/html/moodle/admin/cli/install.php --chmod=770 --lang=en --wwwroot="$siteProtocol"://"$siteFQDN" --dataroot=/moodle/moodledata --dbhost="$mysqlIP" --dbname="$moodledbname" --dbuser="$azuremoodledbuser" --dbpass="$moodledbpass" --dbtype=mysqli --fullname='Moodle LMS' --shortname='Moodle' --adminuser=admin --adminpass="$adminpass" --adminemail=admin@"$siteFQDN" --non-interactive --agree-license --allow-unstable || true " + cd /tmp; /usr/bin/php /moodle/html/moodle/admin/cli/install.php --chmod=770 --lang=en --wwwroot=$siteProtocol://$siteFQDN --dataroot=/moodle/moodledata --dbhost=$mysqlIP --dbname=$moodledbname --dbuser=$azuremoodledbuser --dbpass=$moodledbpass --dbtype=mysqli --fullname='Moodle LMS' --shortname='Moodle' --adminuser=admin --adminpass=$adminpass --adminemail=admin@$siteFQDN --non-interactive --agree-license --allow-unstable || true + fi if [ "$installObjectFsSwitch" = "true" ]; then mysql -h $mysqlIP -u $mysqladminlogin -p${mysqladminpass} ${moodledbname} -e "INSERT INTO mdl_config_plugins (plugin, name, value) VALUES ('tool_objectfs', 'enabletasks', 1);" @@ -943,40 +983,44 @@ EOF fi if [ $fileServerType = "azurefiles" ]; then - # Delayed copy of moodle installation to the Azure Files share - - # First rename moodle directory to something else - mv /moodle /moodle_old_delete_me - # Then create the moodle share - echo -e '\n\rCreating an Azure Files share for moodle' - create_azure_files_moodle_share $storageAccountName $storageAccountKey /tmp/wabs.log $fileServerDiskSize - # Set up and mount Azure Files share. Must be done after nginx is installed because of www-data user/group - echo -e '\n\rSetting up and mounting Azure Files share on //'$storageAccountName'.file.core.windows.net/moodle on /moodle\n\r' - setup_and_mount_azure_files_moodle_share $storageAccountName $storageAccountKey - # Move the local installation over to the Azure Files - echo -e '\n\rMoving locally installed moodle over to Azure Files' - - # install azcopy - wget -q -O azcopy_v10.tar.gz https://aka.ms/downloadazcopy-v10-linux && tar -xf azcopy_v10.tar.gz --strip-components=1 && mv ./azcopy /usr/bin/ + if [ "$isMigration" = "true" ]; then + echo -e '\n\rIts a migration flow, the moodle content is already on azure file share\n\r' + else + # Delayed copy of moodle installation to the Azure Files share + + # First rename moodle directory to something else + mv /moodle /moodle_old_delete_me + # Then create the moodle share + echo -e '\n\rCreating an Azure Files share for moodle' + create_azure_files_moodle_share $storageAccountName $storageAccountKey /tmp/wabs.log $fileServerDiskSize + # Set up and mount Azure Files share. Must be done after nginx is installed because of www-data user/group + echo -e '\n\rSetting up and mounting Azure Files share on //'$storageAccountName'.file.core.windows.net/moodle on /moodle\n\r' + setup_and_mount_azure_files_moodle_share $storageAccountName $storageAccountKey + # Move the local installation over to the Azure Files + echo -e '\n\rMoving locally installed moodle over to Azure Files' + + # install azcopy + wget -q -O azcopy_v10.tar.gz https://aka.ms/downloadazcopy-v10-linux && tar -xf azcopy_v10.tar.gz --strip-components=1 && mv ./azcopy /usr/bin/ - ACCOUNT_KEY="$storageAccountKey" - NAME="$storageAccountName" - END=`date -u -d "60 minutes" '+%Y-%m-%dT%H:%M:00Z'` - - sas=$(az storage share generate-sas \ - -n moodle \ - --account-key $ACCOUNT_KEY \ - --account-name $NAME \ - --https-only \ - --permissions lrw \ - --expiry $END -o tsv) - - export AZCOPY_CONCURRENCY_VALUE='48' - export AZCOPY_BUFFER_GB='4' - - # cp -a /moodle_old_delete_me/* /moodle || true # Ignore case sensitive directory copy failure - azcopy --log-level ERROR copy "/moodle_old_delete_me/*" "https://$NAME.file.core.windows.net/moodle?$sas" --recursive || true # Ignore case sensitive directory copy failure - rm -rf /moodle_old_delete_me || true # Keep the files just in case + ACCOUNT_KEY="$storageAccountKey" + NAME="$storageAccountName" + END=`date -u -d "60 minutes" '+%Y-%m-%dT%H:%M:00Z'` + + sas=$(az storage share generate-sas \ + -n moodle \ + --account-key $ACCOUNT_KEY \ + --account-name $NAME \ + --https-only \ + --permissions lrw \ + --expiry $END -o tsv) + + export AZCOPY_CONCURRENCY_VALUE='48' + export AZCOPY_BUFFER_GB='4' + + # cp -a /moodle_old_delete_me/* /moodle || true # Ignore case sensitive directory copy failure + azcopy --log-level ERROR copy "/moodle_old_delete_me/*" "https://$NAME.file.core.windows.net/moodle?$sas" --recursive || true # Ignore case sensitive directory copy failure + rm -rf /moodle_old_delete_me || true # Keep the files just in case + fi fi create_last_modified_time_update_script