Schedule Azure VM to turn on, run a script and turn off

白昼怎懂夜的黑 提交于 2021-02-08 07:23:49

问题


I have a multi-container app that I need to run twice a day at specific times for about 30 mins each time. To save costs, I would like to:

  1. Turn on a Linux VM on Microsoft Azure
  2. Run a script that runs docker-compose up -d, waits 30 mins, then calls docker-compose stop
  3. Turn off the VM

I'd love for this to happen automatically on a cron schedule.

So far, I've failed to find any Azure solution that can do all of this. Azure automation allows you to turn on/off VMs but it doesn't allow you to run a sh script on it after you've turned it on. Azure Logic apps allows you to spin up containers on a schedule but not with docker-compose.

Any idea on how I might accomplish this in a way that doesn't involve me having a VM that is always on?


回答1:


No worries , you can use this AZ powershell command to run sh script on your Azure VMs directly via Azure automation runbook with prarm : -CommandId 'RunShellScript'

For AzureRM commands , refer to here

I have tested on my side and it works perfectly for me .



来源:https://stackoverflow.com/questions/59112150/schedule-azure-vm-to-turn-on-run-a-script-and-turn-off

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!