How to use Azure App Service SSh to write, save and persist a new startup.sh command in home directory

Stephen Wartel 60 Reputation points
2023-06-13T12:23:01.5933333+00:00

Made progress through these answers: (1) https://techcommunity.microsoft.com/t5/apps-on-azure-blog/updating-nginx-default-configurations-on-azure-app-services/ba-p/3710146 and (2) https://learn.microsoft.com/en-us/answers/questions/1304020/app-service-wordpress-(wp)-can-i-add-rules-via-ssh.

Question 1

The two postings above suggest different commands:

(1) cp /home/default.conf /etc/nginx/conf.d/default.conf /usr/sbin/nginx -s reload

(2) cp /home/site/nginx.conf /etc/nginx/sites-available/default service nginx reload

Not sure which to use?

Question 2

However, my new startup.sh command adding the command also did not persist. When I reopened it after several hours, my additions were gone. I had written the additions then used ESC + ZZ to hopefully close and save this new /home/startup.sh. It appears that it did not persistently save since the added commands were gone a few hours later (after a server refresh/restart?).

If possible, I would appreciate any step-by-step walk-through to create save and importantly persist this command using Azure portal SSH in my App Service.

Thank you in advance for your help.

Stephen

Azure App Service
Azure App Service
Azure App Service is a service used to create and deploy scalable, mission-critical web apps.
8,257 questions
{count} votes

1 answer

Sort by: Most helpful
  1. brtrach-MSFT 17,391 Reputation points Microsoft Employee
    2023-06-14T02:59:33.99+00:00

    @Stephen Wartel Both commands are used to copy a file from one location to another and reload the Nginx service. The first command copies the default.conf file from /home to /etc/nginx/conf.d/ and then reloads the Nginx service using the -s reload option. The second command copies the nginx.conf file from /home/site/ to /etc/nginx/sites-available/default and then reloads the Nginx service using the service nginx reload command.

    In regard to what route to take, I would use the below call. The article you mentioned that uses this call was recently published, was written by a Microsoft Employee, and the author showcases an end-to-end proven solution.

    @Stephen Wartel Both commands are used to copy a file from one location to another and reload the Nginx service. The first command copies the default.conf file from /home to /etc/nginx/conf.d/ and then reloads the Nginx service using the -s reload option. The second command copies the nginx.conf file from /home/site/ to /etc/nginx/sites-available/default and then reloads the Nginx service using the service nginx reload command.

    Here is a step-by-step walkthrough to create, save, and persist the command using Azure portal SSH in your App Service:

    1. Open the Azure portal and navigate to your App Service.
    2. In the left-hand menu, click on "SSH" under the "Development Tools" section.
    3. Click "Go" to open the SSH session in your browser.
    4. Once you are connected to the SSH session, navigate to the home directory by typing cd ~.
    5. Create a new file named startup.sh by typing nano startup.sh.
    6. Type or paste the command you want to run at startup into the file.
    7. Save the file by pressing Ctrl+X, then Y, then Enter.
    8. Make the file executable by typing chmod +x startup.sh.
    9. Exit the SSH session by typing exit.
    10. In the Azure portal, navigate to your App Service and click on "Configuration" in the left-hand menu.
    11. Scroll down to the "Startup Command" section and enter the following command: bash /home/startup.sh.
    12. Click "Save" to persist the changes.

    By following these steps, your startup.sh command should be saved and persist across server restarts. If you still encounter issues with persistence after following the above 12 steps, please reply here so we can investigate the matter further with you.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.