简体   繁体   中英

Restarting IIS6 - Python

I'm serving a Django app behind IIS 6 . I'm wondering if I can restart IIS 6 within Python/Django and what one of the best ways to do would be.

Help would be great!

Besides what's already suggested, you can also use WMI via either the Win32_Service or the IIsWebService class, which inherits from it. There is a Python WMI wrapper available, which is based on pywin32 .

UPDATE: A quick test of the following worked for me.

import wmi

c = wmi.WMI()

for service in c.Win32_Service(Name="W3SVC"):
    result, = service.StopService()

I didn't test the next piece of code, but something like this should also work:

for service in c.IIsWebService():
    result, = service.StopService()

You can see the documentation for the return values from the StopService and StartService methods.

The following post shows how to control Windows services from Python: http://fuzzytolerance.info/code/using-python-to-manage-windows-services/

You should be able that to restart the IIS web publishing service (known as 'w3svc')

I think that you can execute an iisreset via a commandline. I've never tried that with Django but it should work and be quite simple to implement.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM