dimanche 6 octobre 2024

How to Fix "Read-Only File System" Error in Azure App Service Due to WEBSITE_RUN_FROM_PACKAGE

If you’re running an application on Azure App Service and encounter an error like:

Invalid operation on Read-Only File System: Create New File

or a message saying:

Your app is currently in read-only mode because you are running from a package file. To make any changes, please update the content in your zip file and WEBSITE_RUN_FROM_PACKAGE app setting.

This means your application is likely running in read-only mode because it’s configured to run from a ZIP package. This setting is controlled by the WEBSITE_RUN_FROM_PACKAGE environment variable in Azure App Service.

In this post, we’ll cover the causes of this issue, how to fix it, and how to prevent it from happening in the future.


What Is WEBSITE_RUN_FROM_PACKAGE?

WEBSITE_RUN_FROM_PACKAGE is a feature that lets your app run directly from a ZIP package in Azure App Service. While this can speed up deployments and ensure consistency, it makes the file system read-only.

This works well if your application doesn’t need to modify files at runtime, but if it does, you will encounter issues when trying to write or modify files.


Why Does This Happen?

When you deploy an app using a ZIP file or certain CI/CD pipelines (like Azure DevOps, GitHub Actions, or other tools), Azure may automatically enable WEBSITE_RUN_FROM_PACKAGE. This causes your app to run from a ZIP file, resulting in the file system being read-only.

Any attempt by your application to create or modify files at runtime will fail because the app is running from this read-only ZIP package.


How to Fix the Read-Only File System Issue

The easiest way to fix this issue is to disable the WEBSITE_RUN_FROM_PACKAGE setting or modify your deployment pipeline to avoid running in read-only mode.

Solution 1: Set WEBSITE_RUN_FROM_PACKAGE to 0

You can disable WEBSITE_RUN_FROM_PACKAGE by setting it to 0, which will allow your app to use a writable file system.

Here’s how you can do that:

  1. Go to the Azure Portal.
  2. Navigate to your App Service.
  3. Go to "Configuration" under the "Settings" section.
  4. Find the WEBSITE_RUN_FROM_PACKAGE setting and set its value to 0 (or delete it entirely).
  5. Save the configuration and restart your app.

This will disable the ZIP package deployment and allow the file system to be writable, resolving the error.

Solution 2: Set WEBSITE_RUN_FROM_PACKAGE to 0 in the Pipeline

If you're using a CI/CD pipeline (like Azure DevOps), you can configure the pipeline to automatically set WEBSITE_RUN_FROM_PACKAGE to 0 after deployment.

For example, in Azure Pipelines, you can add the following task:


- task: AzureAppServiceSettings@1
  inputs:
    azureSubscription: 'your-azure-subscription'
    ResourceGroupName: 'your-resource-group'
    appName: 'your-app-service'
    appSettings: '-WEBSITE_RUN_FROM_PACKAGE 0'

This ensures that after each deployment, WEBSITE_RUN_FROM_PACKAGE is set to 0 to avoid the read-only file system issue.

Alternatively, you can use the Azure CLI in your pipeline to accomplish the same thing:


- task: AzureCLI@2
  inputs:
    azureSubscription: 'your-azure-subscription'
    scriptType: 'bash'
    scriptLocation: 'inlineScript'
    inlineScript: |
      az webapp config appsettings set --resource-group your-resource-group --name your-app-service --settings WEBSITE_RUN_FROM_PACKAGE=0

Solution 3: Use a Writable Directory for File Operations

If you need to keep WEBSITE_RUN_FROM_PACKAGE enabled but still want to write files at runtime, you can direct your application to use one of the writable directories in Azure App Service.

Writable directories in Azure App Service include:

  • D:\home: This directory is writable and persists across restarts.
  • D:\local: This is a temporary directory that is writable but does not persist across restarts.

You can modify your code to write files to these directories:


var writablePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "myfile.txt");
// Use this path for file operations


Preventing the Issue in Future Deployments

If your pipeline or deployment method automatically enables WEBSITE_RUN_FROM_PACKAGE, you can prevent this by:

  1. Disabling ZIP deployment in your pipeline and using another deployment method (like web deploy).
  2. Ensuring the correct settings are applied after deployment (as shown in Solution 2).

Conclusion

Running from a ZIP package with WEBSITE_RUN_FROM_PACKAGE is useful for fast and efficient deployments, but it can sometimes lead to a "read-only file system" issue if your app needs to modify files at runtime.

By disabling this setting or adjusting your deployment pipeline, you can ensure your app runs smoothly without encountering file system issues.

Let me know if you need further assistance!

samedi 20 septembre 2014

Get workflow task related item


  SPList list = null;
       
var relativeUrl = SPContext.Current.Web.ServerRelativeUrl.Equals("/") ? string.Empty : web.ServerRelativeUrl;

            try
            {
                list = SPContext.Current.Web.GetList(string.Concat(relativeUrl, "/Lists/", listname));
            }
            catch
            {
                list = SPContext.Current.Web.GetList(string.Concat(relativeUrl, "/", listname));
            }

list .commandesList.GetItemById(int.Parse( currentItem[SPBuiltInFieldId.WorkflowItemId].ToString()));

vendredi 5 septembre 2014

Remove the default Task Outcomes (Approved rejected)


  • Create a new Task List Instance (new workflow wizard will help you do it)
  • new Custom List Column with type OutcomeChoice

<Elements xmlns="http://schemas.microsoft.com/sharepoint/">  
  <Field
       ID="{a8229356-e367-4379-a6f7-f19fdca45cde}"
       Name="tatatatatata"
       DisplayName="tatatatata"
       Type="OutcomeChoice"
       Required="FALSE"
       Group="Custom Site Columns">

    <CHOICES>
      <CHOICE>very goodt</CHOICE>
      <CHOICE>good</CHOICE>
      <CHOICE>Average</CHOICE>    
      <CHOICE>Bad</CHOICE>
    </CHOICES>
  </Field>
</Elements>


  • new ContentType Inherit from Workflow Task (SharePoint 2013)  (we will edit this later)
  • Add the Custom Column to the contentType
  • from the contentType Element.xml remove this string  003365C4474CAE8C42BCE396314E88E51F
So an ID like:
0x0108003365C4474CAE8C42BCE396314E88E51F00B237734C3B3E48D38A52DAAA52F56A8F  ==> 0x010800B237734C3B3E48D38A52DAAA52F56A

  • Open the file Workflow.xaml with xml editor 
  • find your <p:SingleTask
  • change ContentTypeId to the new id you just modified (0x010800B237734C3B3E48D38A52DAAA52F56A)
  • go to your TaskList instance and Add your contentType:
  <ContentTypeBinding ListUrl="Lists/InterventionList" RootWebOnly="FALSE" ContentTypeId="0x010800B237734C3B3E48D38A52DAAA52F56A" />
  • Deploy your project and see the magic happens
Please leave a comment if you need clarifications


jeudi 4 septembre 2014

Workflow manager not responding after cumulative update

Hi,

If you have updated your workflow manager using the cumulative update :
http://www.microsoft.com/en-us/download/confirmation.aspx?id=36800

So you probably facing an issue with your workflow manager, right ?



Ok this is how to fix it (it's weird I konw but this works for me)

Open your SQL management studio and run this script in the Sharepoint database

USE WFResourceManagementDB
INSERT INTO WorkflowServiceConfig VALUES('WorkflowServiceScopeSnapshotProcessBatchSize', '50')
INSERT INTO WorkflowServiceConfig VALUES('WorkflowServiceScopeSnapshotProcessLoopInterval', '00:05:00')
INSERT INTO WorkflowServiceConfig VALUES('WorkflowServiceSuspendedInstanceRetentionDuration', '00:30:00')
INSERT INTO WorkflowServiceConfig VALUES('WorkflowServiceMaxInstanceCompressedSizeKB', '5120')

This solution will help you deploy workflows again but you will be facing many other problems. so I recommand to reinstall your workflow manager on a clean Database. (reusing an existing database will not resolve your problems)

so detach your workflow manager from the farm and remove this databases list:

  1. WfManagementDB
  2. SbGatewayDatabase
  3. SBMessagingContainer01
  4. WFInstanceManagementDB
  5. WFResourceManagementDB
  6. SBManagementDB
And then you will be able to have a new workflow manager clean installation.

mercredi 3 septembre 2014

sharepoint 2013 Show Errors (why it's not working for you)

To disable the custom error page in  sharepoint 2013 you have to set  
<customErrors mode="On" /> to <customErrors mode="Off" /> 

Ok but this may not work , right ? I tell you why.

For sharepoint there is many web.config files located under:

"C:\inetpub\wwwroot\wss\VirtualDirectories\80"

but non of them will work as expected for pages using layouts.

To make it work, you must modify the web.config under

"C:\Program Files\Common Files\microsoft shared\Web Server Extensions\15\TEMPLATE\LAYOUTS"


Hope it works for you either. 

Sharepoint 2013 & Custom Task Outcome on VisualStudio

This is the how it works:


Add new SiteColumn
Change the Type param value to "OutcomeChoice" in <Field /> tag

Add :   <CHOICES >
                <CHOICE>choice one</CHOICE>
                <CHOICE>choice two</CHOICE>
          </CHOICES>
Add new ContentType  and inherit from Workflow Task (SharePoint 2013)
Add Columns: 
  • % Completed
  • Task Status
  • The custom OutcomeColumn
NB: The order is Important, if the custom Outcome Column is not the last one choices will appear as a DropBox and to as buttons

Add new Task List Instance (Or a Custom list template)

Insure the TemplateType is set to "171" (this Id reference Task template)

If you are working with a Task list Instance Add Schema.xml file to it and copy content from a Task list template (create a new Task list template, copy schema.xml content, modify List Name and URL to match your List Instance )

Deploy and happy to help you.

Please let me know if there is any issue so i can update this article


mardi 16 octobre 2012

PHP Curl wamp Et windows


L'installation de curl sur windows peut poser des problèmes, il ne suffit pas d'activer l'extension du fichier php.ini mais il faut s'assurer que l'extension php_curl correspond avotre version php.

la correction de ce problème réside dans la modification de ce fichier par le DLL adéquat a la version de PHP installé.
pour la version php 5.4.3, la version curl installé par défaut présente des bugs. d'où il faut la modifier par le fichier suivant

php5.4.3 => http://www.morningtime.com/sites/default/files/attachments/book/188/php_curl-5.4.3-VC9-x64.zip