Stopping Website from within a WebJob

柔情痞子 提交于 2019-12-11 04:36:11

问题


Is there any way of stopping an Azure website from a WebJob?

I have an Azure Website using Ghost that runs on Node. I'm trying to schedule a backup of the Ghost database file which ideally should be done while the site is not running. I can stop the site temporarily by terminating the Node.exe process using the Kudu PowerShell console.

If I try to do the same thing from a WebJob, the process does not get terminated - presumably because the WebJob is running in a different context and doesn't see the node.exe process.

Is there any way of stopping/starting a site from within a WebJob?


回答1:


Azure web-sites are controlled via HTTP API. From your WebJob you can stop you web-site by issuing HTTP request. See here for details of the request.

However, WebJob is running in the same context as your Web-Site. So if the site is stopped, your WebJob will also be stopped. And you should have some other way to bring your site back online, because WebJob will not be there for you...




回答2:


Actually it seems I was doing something wrong in my WebJob when I was originally trying to terminate the node.exe process.

While @trailmax is correct in that terminating the site (i.e. the w3wp process) will also stop the WebJobs (and indeed the Kudu site), you can terminate node.exe from a webjob. It will restart as soon as another connection is made to the site, so it's not the best solution unfortunately - unless some kind of async process is started to continually check for and terminate node.exe until the WebJob has finished its work.



来源:https://stackoverflow.com/questions/24620812/stopping-website-from-within-a-webjob

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