安排Azure VM开启,运行脚本并关闭 [英] Schedule Azure VM to turn on, run a script and turn off

查看:58
本文介绍了安排Azure VM开启,运行脚本并关闭的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个多容器应用程序,我需要每天在特定时间运行两次,每次运行大约30分钟.为了节省成本,我想:

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. 在Microsoft Azure上打开Linux VM
  2. 运行一个脚本,该脚本运行 docker-compose up -d ,等待30分钟,然后调用 docker-compose stop
  3. 关闭虚拟机
  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.

到目前为止,我还没有找到可以完成所有这些任务的任何Azure解决方案.Azure自动化允许您打开/关闭虚拟机,但不允许在打开虚拟机后运行sh脚本.Azure Logic应用程序允许您按计划启动容器,但不能使用docker-compose.

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.

关于我如何以不涉及拥有始终处于运行状态的VM的方式实现此目标的任何想法吗?

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

推荐答案

不用担心,您可以使用

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'

对于AzureRM命令,请参考此处

For AzureRM commands , refer to here

我已经接受了测试,对我来说效果很好.

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

这篇关于安排Azure VM开启,运行脚本并关闭的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆