Example #1
0
        public void Start()
        {
            /*
             * agent/lib/agent.rb
             * Takes command line args in agent/bin/agent
             * Bootstrap!
             * Configure and enable Monit
             * Starts the Handler
             */

            BoshAgentInfrastructureVsphereSettings_LoadSettings();
            config.UpdateFrom(settings);

            /*
             * TODO:
             * run sysprep
                 set admin password (via unattend.xml)
             * set ip address
             * set licensing server
            netsh interface ipv4 set address name="Local Area Connection" source=static address=%1 mask=%2 gateway=%3
            netsh interface ipv4 set dns name="Local Area Connection" source=static addr=%4
            netsh interface ipv4 add dns name="Local Area Connection" addr=%5
             */
            bool wasSysprepped = Sysprep();
            if (wasSysprepped)
            {
                Stop();
                Environment.Exit(0); // TODO not the prettiest way to do this.
            }
            SetupNetworking();

            #if DEBUG
            if (config.Debugging && this.ShouldWaitAtStartup)
            {
                log.Info("Waiting 90 seconds...");
                Thread.Sleep(TimeSpan.FromSeconds(90));
            }
            #endif

            // agent/lib/agent/handler.rb

            // find_message_processors

            var natsConfig = new BoshAgentNatsConfig(config.Mbus);
            natsClient.UseConfig(natsConfig);

            ushort natsFailCount = 0;
            while (false == natsClient.Start())
            {
                ++natsFailCount;
                if (natsFailCount > NatsRetries)
                {
                    // TODO move to BoshHandler class, custom exceptions
                    string msg = String.Format(Resources.BoshAgent_UnableToConnectAfterRetries_Fmt, natsFailCount);
                    log.Fatal(msg);
                    throw new Exception(msg);
                }
                else
                {
                    Thread.Sleep(NatsReconnectSleep);
                }
            }

            SetupSubscriptions();

            // setup heartbeats
            heartbeatProcessor = new HeartbeatProcessor(log, natsClient, config);
            heartbeatProcessor.Start();

            // SetupSshdMonitor();
            /*
            if @process_alerts
              if (@smtp_port.nil? || @smtp_user.nil? || @smtp_password.nil?)
                @logger.error "Cannot start alert processor without having SMTP port, user and password configured"
                @logger.error "Agent will be running but alerts will NOT be properly processed"
              else
                @logger.debug("SMTP: #{@smtp_password}")
                @processor = Bosh::Agent::AlertProcessor.start("127.0.0.1", @smtp_port, @smtp_user, @smtp_password)
              end
            end
             */
        }
Example #2
0
        public void Start()
        {
            /*
             * agent/lib/agent.rb
             * Takes command line args in agent/bin/agent
             * Bootstrap!
             * Configure and enable Monit
             * Starts the Handler
             */

            BoshAgentInfrastructureVsphereSettings_LoadSettings();
            config.UpdateFrom(settings);

            /*
             * TODO:
             * run sysprep
             *   set admin password (via unattend.xml)
             * set ip address
             * set licensing server
             * netsh interface ipv4 set address name="Local Area Connection" source=static address=%1 mask=%2 gateway=%3
             * netsh interface ipv4 set dns name="Local Area Connection" source=static addr=%4
             * netsh interface ipv4 add dns name="Local Area Connection" addr=%5
             */
            bool wasSysprepped = Sysprep();

            if (wasSysprepped)
            {
                Stop();
                Environment.Exit(0); // TODO not the prettiest way to do this.
            }
            SetupNetworking();

#if DEBUG
            if (config.Debugging && this.ShouldWaitAtStartup)
            {
                log.Info("Waiting 90 seconds...");
                Thread.Sleep(TimeSpan.FromSeconds(90));
            }
#endif

            // agent/lib/agent/handler.rb

            // find_message_processors

            var natsConfig = new BoshAgentNatsConfig(config.Mbus);
            natsClient.UseConfig(natsConfig);

            ushort natsFailCount = 0;
            while (false == natsClient.Start())
            {
                ++natsFailCount;
                if (natsFailCount > NatsRetries)
                {
                    // TODO move to BoshHandler class, custom exceptions
                    string msg = String.Format(Resources.BoshAgent_UnableToConnectAfterRetries_Fmt, natsFailCount);
                    log.Fatal(msg);
                    throw new Exception(msg);
                }
                else
                {
                    Thread.Sleep(NatsReconnectSleep);
                }
            }

            SetupSubscriptions();

            // setup heartbeats
            heartbeatProcessor = new HeartbeatProcessor(log, natsClient, config);
            heartbeatProcessor.Start();

            // SetupSshdMonitor();

            /*
             * if @process_alerts
             * if (@smtp_port.nil? || @smtp_user.nil? || @smtp_password.nil?)
             *  @logger.error "Cannot start alert processor without having SMTP port, user and password configured"
             *  @logger.error "Agent will be running but alerts will NOT be properly processed"
             * else
             *  @logger.debug("SMTP: #{@smtp_password}")
             *  @processor = Bosh::Agent::AlertProcessor.start("127.0.0.1", @smtp_port, @smtp_user, @smtp_password)
             * end
             * end
             */
        }