Azure App Service Linux - Custom Startup Script for Nodejs & Python

1 minute read | By Toan Nguyen

In my previous post Azure App Service Linux - PHP Custom Startup Script I covered steps for adding a custom startup script for PHP. In this post, I’l be providing some examples for creating custom startup scripts that will work for both our Nodejs and Python images.

Modifying the Startup Script

Both the Nodejs and Python images create startup scripts based on default settings or based on a “Startup Command” that you may be specifying in the Azure Portal, Azure CLI, etc. We’ll be copying and modifying the file to use for our custom script.

  1. Go to the Kudu site for your App (i.e. https://<sitename>.azurewebsites.net) and select SSH from the menu.
  2. SSH into the container and copy the current startup script by typing the following
    cp /opt/startup/startup.sh /home
    
  3. Using your favorite editor, edit the startup.sh under /home/startup.sh and add your changes to the top of the file after ”#!/bin/sh”. In the sample below, I’ll be installing cron to run a cronjob.
# Installing cron
apt-get update -qq && apt-get install cron -yqq
service cron start
mkdir /home/BackupLogs
(crontab -l 2>/dev/null; echo "*/5 * * * * cp /home/LogFiles/*.log /home/BackupLogs")|crontab
  1. Save the file.

Saving the Changes

In the Azure Portal configurations, add “/home/startup.sh” as the Startup Command and restart the site.