Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Restart IIS site and its apppool from a batch file

Tags:

iis

batch-file

I have a site where I need to restart the site and its apppool each time I make changes. When I'm debugging one of the scripts it becomes a chore to do it manually each time (it's 5-6 clicks).

enter image description here enter image description here

Is there a way to automate it in a batch file?

Edit: I found how to restart the apppool from https://stackoverflow.com/a/38607626/492336, but I need to restart the site as well:

C:\Windows\System32\inetsrv\appcmd start apppool /apppool.name:"MYAPPPOOLNAME"
like image 907
sashoalm Avatar asked Mar 16 '18 10:03

sashoalm


People also ask

What happens when you restart IIS?

When you restart IIS, all session connected to web server are dropped. Any data held in web applications is lost. All Internet sites are unavailable until Internet services are restarted. So Microsoft suggest users avoid restarting, stopping, or rebooting server if at all possible.

Does restarting IIS restart app pool?

Does IISRESET recycle the application pools? The correct answer is no. Instead, IISRESET causes the shutdown of all active IIS worker processes, kills them if they do not stop in time.


1 Answers

After some searching and trial and error, I came up with a short script, where "Default Web Site" is the name of the site to restart:

C:\Windows\System32\inetsrv\appcmd stop apppool /apppool.name:"Default Web Site"
C:\Windows\System32\inetsrv\appcmd stop site /site.name:"Default Web Site"
C:\Windows\System32\inetsrv\appcmd start site /site.name:"Default Web Site"
C:\Windows\System32\inetsrv\appcmd start apppool /apppool.name:"Default Web Site"

If you get this error:

message:The WAS service is not available - try starting the service first.

Try to execute with admin privileges.

like image 163
sashoalm Avatar answered Oct 20 '22 23:10

sashoalm