Hi

I made a small program that does this, it links to the assemblies of CCNet,
below  is the code.
It's in VB.Net,  but you can just compile it, or translate it to C# (online
translations)

works like a charm :-)

with kind regards
Ruben Willems


<---- start of code -->
Imports ThoughtWorks.CruiseControl
Imports ThoughtWorks.CruiseControl.Remote

Module Module1

    Private BuildServerManager As CCTrayLib.Monitoring.ICruiseServerManager
    Private Const BuildServerUrl As String = "tcp://appserver-cc:21234"

    Sub Main()

        Dim args As String()

        Try

            Dim StopProjects As Boolean

            args = Environment.GetCommandLineArgs()
            If args.Count <> 2 Then
                Console.WriteLine("{0} State ", args(0))
                Console.WriteLine(" example : {0} stop   to stop  all
projects", args(0))
                Console.WriteLine(" example : {0} start  to start all
projects", args(0))
                Return
            End If

            StopProjects = args(1).ToLower = "stop"

            BuildServerManager = CreateBuildServerManager()

            Dim CruiseSnapShot As Remote.CruiseServerSnapshot =
BuildServerManager.GetCruiseServerSnapshot

            Dim CruiseManager As Remote.ICruiseManager

            Dim z As New Remote.RemoteCruiseManagerFactory
            CruiseManager = z.GetCruiseManager(BuildServerUrl)


            For Each project As Remote.ProjectStatus In
CruiseSnapShot.ProjectStatuses

                If StopProjects Then
                    If project.Activity = Remote.ProjectActivity.Sleeping
OrElse project.Activity = Remote.ProjectActivity.Pending Then
                        Console.WriteLine("Stopping {0} ...", project.Name)
                        CreateProjectManager(project.Name).StopProject()
                    End If
                End If

                If Not StopProjects Then
                    If project.Status = ProjectIntegratorState.Stopped Then
                        Console.WriteLine("Starting {0} ...", project.Name)
                        CreateProjectManager(project.Name).StartProject()
                    End If
                End If

            Next

        Catch ex As Exception
            Console.WriteLine(ex.ToString)

        End Try



    End Sub


    Private Function CreateBuildServerManager() As
CCTrayLib.Monitoring.ICruiseServerManager

        Dim RemoteCruiseManagerFactory As Remote.RemoteCruiseManagerFactory
= New Remote.RemoteCruiseManagerFactory

        Dim Factory As CCTrayLib.Monitoring.CruiseServerManagerFactory = New
CCTrayLib.Monitoring.CruiseServerManagerFactory(RemoteCruiseManagerFactory)

        Dim Manager As CCTrayLib.Monitoring.ICruiseServerManager =
Factory.Create(CreateBuildServer())

        Return Manager

    End Function


    Private Function CreateProjectManager(ByVal projectName As String) As
CCTrayLib.Monitoring.ICruiseProjectManager

        Dim server = CreateBuildServer()

        Dim remoteCruiseManagerFactory As ICruiseManagerFactory = New
RemoteCruiseManagerFactory()
        Dim factory As CCTrayLib.Monitoring.CruiseProjectManagerFactory =
New
CCTrayLib.Monitoring.CruiseProjectManagerFactory(remoteCruiseManagerFactory)

        Dim projectConfig As CCTrayLib.Configuration.CCTrayProject = New
CCTrayLib.Configuration.CCTrayProject(server, projectName)


        Dim serverList As Collections.Generic.Dictionary(Of
CCTrayLib.Configuration.BuildServer,
CCTrayLib.Monitoring.ICruiseServerManager) = New Dictionary(Of
CCTrayLib.Configuration.BuildServer,
CCTrayLib.Monitoring.ICruiseServerManager)

        serverList.Add(server, CreateBuildServerManager)

        Dim manager As CCTrayLib.Monitoring.ICruiseProjectManager =
factory.Create(projectConfig, serverList)

        Return manager

    End Function


    Private Function CreateBuildServer() As
CCTrayLib.Configuration.BuildServer

        Dim serverName = BuildServerUrl.ToLower

        If Not serverName.StartsWith("tcp://") Then
            Throw New Exception("set up the url as remoting, url used : " +
BuildServerUrl)
        End If
        serverName = serverName.Substring(6)

        Return
CCTrayLib.Configuration.BuildServer.BuildFromRemotingDisplayName(serverName)


    End Function


End Module

<---- end of of code -->


On Wed, Mar 10, 2010 at 9:01 PM, MarkusW <[email protected]> wrote:

> Hi all,
>
> is there a way to stop all projects at once? (other than stopping the
> ccnet service)
>
> For backup purposes we are weekly shutting down the (virtual) machine
> that hosts our source control database. After a few minutes most of
> the 50+ CCNet projects on our build server go into "Exception" state
> because the source control database is no longer available.
>
> We would rather not see this behavior. So I thought we could stop all
> projects before shutting down the source control server. Then restart
> them when the source control database servere is available again.
>
> Any ideas?
>
> TIA,
>
> Markus Winhard
>

Reply via email to