FAILED TO INITIALIZE RUN FROM PACKAGE.txt

I was doing some deployments to an Azure Function and found this text file in my d:\home\site\wwwroot directory.  This can happen if you are trying to run an Azure Function from package, which is discussed here.  Real fast, the way you get this to happen is by making a deployment, then after the deployment is complete you create an application setting named WEBSITE_RUN_FROM_PACKAGE with a value of 1.  FAILED TO INITIALIZE RUN FROM PACKAGE.txt will be generated only on the first deployment and setting of this application setting, in that order.  If you redeploy the code again, the issue will go away.

The reason is because when you deploy to an Azure Function that does not have an application setting named WEBSITE_RUN_FROM_PACKAGE with a value of 1 the code will be unzipped or placed directly into the d:\home\site\wwwroot directory.  That makes sense right?  The platform doesn’t know that you want to run your Azure Function from ZIP.  When you manually then add an application setting named WEBSITE_RUN_FROM_PACKAGE with a value of 1, there is no trigger or mechanism to get your code restructured so that it works in this new structure.  Without going into implementation details, this would be hard to accomplish, i.e. making such signifigant platform changes based on the adding (or removal) of an application setting.

image

When you initially make a deployment the code is stored on either Azure Files or an Azure Storage Container.  The code is taken from that source and used on the instances of your workers.  When WEBSITE_RUN_FROM_PACKAGE is enabled (i.e. 1) the zipped code is expected to be in the d:/home/data/SitePackages.  Looking at the setup on Kudu when I deployed my code without WEBSITE_RUN_FROM_PACKAGE set to one you will not find any files in the SitePackages directory and you will find a file in the wwwroot named FAILED TO INITIALIZE RUN FROM PACKAGE.txt as you see in Figure 1.

image

Figure 1, WEBSITE_RUN_FROM_PACKAGE , FAILED TO INITIALIZE RUN FROM PACKAGE.txt

If you leave WEBSITE_RUN_FROM_PACKAGE enabled and redeploy, I used Azure CLI similar to the following, you will then find the ZIP in SitePackages and the extracted content in the wwwroot directory, as seen in Figure 2.

az functionapp deployment source config-zip --resource-group "***" --name "***" --src "***.zip"

image

Figure 2, WEBSITE_RUN_FROM_PACKAGE , FAILED TO INITIALIZE RUN FROM PACKAGE.txt, resolved

Since this was a test site I stopped the Azure Function, deployed and restarted it.  Never deploy directly into production, use deployment slots, test and then swap.