即使问这个问题,我也想知道这么简单的事情对我来说怎么这么难。我要做的就是按计划自动停止和启动 Azure 网站。起初,我查看了 WebJobs,并创建了一个 powershell 脚本来停止使用 stop-azurewebsite 命令行开关的网站:
stop-azurewebsite [my site]
然后我创建了一个 .cmd 文件来调用它,使用 powershell.exe 来执行 powershell 文件
PowerShell.exe -ExecutionPolicy RemoteSigned -File stopit.ps1
我创建了一个 WebJob 来运行 powershell 命令来停止该站点,但它出错并显示一条消息:
stop-azurewebsite : The term 'stop-azurewebsite' is not recognized as the name
of a cmdlet, function, script file, or operable program. Check the spelling of
the name, or if a path was included, verify that the path is correct and try
again.
所以,我想我会走 REST API 路线。我使用 fiddler 和适当的管理证书创建了一个发布请求来调用:
https://management.core.windows.net/[my subscription id]/services/WebSpaces/[webspace]/sites/[website name]/stop
事实证明,没有“停止”命令。有“重启”,但这显然在这种情况下没有用。那么,综上所述,在特定时间安排上自动停止和随后(但要晚得多)启动 Azure 网站的合理方法是什么?
更新:
我已经想出了如何使用 PUT 发出 http 请求来停止站点
https://management.core.windows.net/[my subscription id]/services/WebSpaces/[webspace]/sites/[website name]
正文为{"State":"Stopped"}
,但我仍然没有明显的方式在 WebJob 中向此 URL 'PUT`ing'。