Search code examples
azureserverazure-web-app-servicestartupazure-deployment

Azure startup script is not executed


I've learned how to deploy .sh scripts to Azure with Azure CLI. But it seems like I have no clear understanding of how they work.

I'm creating the script that simply unarchives a .tgz archive in a current directory of Azure Web App, and then just deletes it. Quite simple:

New-Item ./startup.sh
Set-Content ./startup.sh '#!/bin/sh'
Add-Content ./startup.sh 'tar zxvf archive.tgz; rm-rf ./archive.tgz'

And then I deploy the script like this:

az webapp deploy --resource-group Group 
                 --name Name
                 --src-path ./startup.sh 
                 --target-path /home/site/wwwroot/startup.sh
                 --type=startup

Supposedly, it should appear in /home/site/wwwroot/, but for some reason it never does. No matter how I try. I thought it just gets executed and then deleted automatically (since I specified it as a startup script), but the archive is there, not unarchived at all.

My stack is .NET Core.

What am I doing wrong, and what's the right way to do what I need to do? Thank you.


Solution

  • I don't know if it makes sense, but I think the problem might be that you're using the target-path parameter while you should be using path instead.

    From the documentation you cited, when describing the Azure CLI functionality, they state:

    The CLI command uses the Kudu publish API to deploy the package and can be fully customized.

    The Kudu publish API reference indicates, when describing the different values for type and especially startup:

    type=startup: Deploy a script that App Service automatically uses as the startup script for your app. By default, the script is deployed to D:\home\site\scripts\<name-of-source> for Windows and home/site/wwwroot/startup.sh for Linux. The target path can be specified with path.

    Note the use of path:

    The absolute path to deploy the artifact to. For example, "/home/site/deployments/tools/driver.jar", "/home/site/scripts/helper.sh".

    I never tested it, I am aware that the option is not described when taking about the az webapp deploy command itself, and it may be just an error in the documentation, but it may work:

    az webapp deploy --resource-group Group 
                     --name Name
                     --src-path ./startup.sh 
                     --path /home/site/wwwroot/startup.sh
                     --type=startup
    

    Note that the path you are providing is the default one; as a consequence, you could safely delete it if required:

    az webapp deploy --resource-group Group 
                     --name Name
                     --src-path ./startup.sh
                     --type=startup
    

    Finally, try including some debug or echo commands in your script: perhaps the problem can be motivated for any permissions issue and having some traces in the logs could be helpful as well.