问题
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