[LINUX] App Service Small story collection

We've picked up a few questions that you sometimes hear about Azure App Service, so please refer to them.

Part 1: "I can't scale up to Premium V2!"

# I haven't heard about it recently. </ font>

There are several spec grades for multi-tenant (other than ASE) App Service scales, the highest spec being the Premium V2 plan. image.png

There are differences in the available features depending on whether the Premium V2 plan is available. One of them is App Service's new VNet integration (called "Region VNet integration").

The App Service does not need to be running on PremiumV2 to use the Region VNet integration. However, it must be deployed on a scale unit that supports the PremiumV2 plan (whether it is possible to scale up to PremiumV2 with the \ [Scale Up] blade in the Azure portal).

--Regional VNet integration --Integrating apps with Azure virtual networks --Azure App Service | Microsoft Docs
https://docs.microsoft.com/ja-jp/azure/app-service/web-sites-integrate-with-vnet#regional-vnet-integration

This feature is only available from new App Service scale units that support PremiumV2 App Service plans.

The scale unit is explained in here, so please refer to it, but in fact, the Premium V2 plan can be used. Whether or not the App Service is related to the scale unit on which it was deployed, and that scale unit is determined during the initial deployment.

So if you're likely to need PremiumV2 (or related features) later, choose the PremiumV2 plan when you first deploy __. __ It ensures that PremiumV2 is deployed to the available scale unit. \ # If the deployment fails, don't panic and try again.

If you don't have any particular reason to keep PremiumV2 after the deployment is complete, scale it down to Standard etc. quickly.

Part 2: "I want to use web jobs with the Linux version of App Service!"

The Windows version of App Service has a feature called Web Jobs that allows you to perform periodic processing in the background. I think some people are using it for moving log files.

On the other hand, App Service also has a Linux version (App Service on Linux), but unfortunately it does not have a mechanism like Web jobs.

However, in App Service on Linux, you can start the web application via the startup script on the Docker container [^ 1], so if you want to add a little, you can process the preprocessing by devising the startup script. Is possible.

[^ 1]: App Service on Linux is launching a Docker container based on Docker Images (Blessed Images) for each runtime language provided by Microsoft.

  • appsvc's Profile - Docker Hub
    https://hub.docker.com/u/appsvc
  • Azure App Service - GitHub
    https://github.com/Azure-App-Service

Using this start-up script mechanism, install cron at the timing of starting the Web application and try to set an appropriate job.

Additional installation & startup procedure for cron

  1. Copy the default startup script /opt/startup/startup.sh.

    cp /opt/startup/startup.sh /home/start.sh
    
  2. In most cases, the last line of the copied script /home/start.sh will be the command to start the web application, so delete it leaving the last line and add additional processing just before that (such as installing cron or (Additional settings, etc.) are described.

    apt update && apt install cron -y            #Install cron
    service cron start                           #Start cron
    echo "*/5 * * * * sh /home/job.sh" | crontab #Scheduling cron
    npm start                                    #Launch web application(node.For js)
    
  • /Home/job.sh is a shell script that describes the process you want to execute.
  1. From the Azure portal, set /home/start.sh created in 1. as the" startup command "and restart.
    image.png

If it works properly, the process tree will be as follows.

ProcessTree


/home# pstree -a
bash /opt/startup/init_container.sh sh /home/start.sh
  |-cron
  |-sshd
 (snipped)
  |
  `-startup.sh /opt/startup/startup.sh
      `-sh /home/start.sh
          `-npm
              (snipped)

You can see the cron process, the custom startup script /home/start.sh under the default /opt/startup/startup.sh, and the web application startup command (npm) under it. I will.

The above example is a way to put cron in and make it look like a web job, but you can also edit various settings in the startup script before starting the web application. For example, the blog below describes how to edit the config file before launch, based on the PHP Docker image, so that the X-Powered-By header is not displayed.

  • Custom Startup script for PHP – Azure App Service Linux – HTTP Stack and other fun things I support
    http://jsandersblog.azurewebsites.net/2019/08/06/custom-startup-script-for-php-azure-app-service-linux/

As a pre-process, you may be able to download the source from the outside and compile it, but if you add too heavy pre-process, it will take time to start the initial request, so Not recommended. In that case, consider using custom containers and Web App for Containers.

That's all for Azure App Service.

Recommended Posts

App Service Small story collection
python small story collection
Small story: numpy flatten mechanism
[Small story] Get timestamp with Python
[Memo] Small story of pandas, numpy