views:

259

answers:

4

I am trying to reset IIS on a set of servers all at one time instead of looping through and resetting each one individually, but I can't seem to figure out how to do it. Could someone please give me an example? Thank you

I am using System.Diagnostics

            With m_Process.StartInfo
                .FileName = strFileName
                .Arguments = String.Format("{0}{1}", server, strArguements)
                .UseShellExecute = False
                .CreateNoWindow = True
                .RedirectStandardError = True
                .RedirectStandardOutput = True
            End With
A: 

I've seen a few questions today with similar conditions ("instead of looping") and I've been trying to figure out what the big deal is about looping. Since iisreset (what I am guessing is assigned to strFileName in your example) takes a single machine name, you are out of luck in that department.

I would assume that iisreset connects to the SCM on the target server and does a restart of the IIS Admin and dependent services.

I suppose you could roll your own iisreset.exe that took multiple servers on the command line, but internal to that you would have to use some kind of iteration.

Could you maybe explain why you can't or don't want to loop?

Sean Bright
The reason I do not want to loop is because I don't want to have to wait for IIS to reset on 100 servers. I would rather all 100 servers be reset at almost the exact same time. Sometimes I need to do this when we have database problems so I would rather have them all reset at once.
Why not just open a thread for each server in a loop (it's inevitable) so that they run roughly concurrently?
JohnFx
That's what I'm trying to figure out. How to correctly run a seperate thread for each server.
A: 

At some level you have to loop over the list of servers and send some message to each to instruct them to reset. Whether you do that by running iisreset with each server name or by some other means, you can't really make the loop go away.

However, if you're just saying that you want to start resetting all the servers as fast as possible rather than waiting for the first to finish resetting before you start resetting the second, it looks like you already have that. When you call m_Process.Start(), it should return as soon as the new iisreset process has started. As far as I can see, it doesn't block and wait until iisreset exits. Therefore, your iisreset processes should already run in parallel.

stevemegson
A: 

If I understand what you're asking, you're okay looping throught he servers, but you just don't want to wait for each server to complete before proceeding to the next one. Since ProcessStartInfo doesn't allow any way to detach from a process you're starting (be nice if it did), you can do it like this (obviously, missing your parameters and such):

Imports System.Threading

Class Restarter

    Sub Main()

        Dim ServerList As New List(Of String)

        For Each server As String In ServerList
            ThreadPool.QueueUserWorkItem(AddressOf RestartServer, server)
        Next
    End Sub

    Sub RestartServer(ByVal Server As String)

        Dim m_Process As System.Diagnostics.Process

        With m_Process.StartInfo
            .FileName = strFileName
            .Arguments = String.Format("{0}{1}", Server, strArguements)
            .UseShellExecute = False
            .CreateNoWindow = True
            .RedirectStandardError = True
            .RedirectStandardOutput = True
        End With

        m_Process.Start()

    End Sub

End Class
rwmnau
A: 

I have the same requirement but I need to write in vbscript, does any one know how to do that ? I'm resetting IIS 7 on windows Server 2008 machines

Jahir