stop

in lib/instance_agent/runner/master.rb [33:68]


      def stop
        if (pid = self.class.find_pid)
          puts "Checking first if a deployment is already in progress"
          ProcessManager::Log.info("Checking first if any deployment lifecycle event is in progress #{description(pid)}")
          begin
            if(InstanceAgent::Plugins::CodeDeployPlugin::DeploymentCommandTracker.check_deployment_event_inprogress?)
              ProcessManager::Log.info("Master process (#{pid}) will not be shut down right now, as a deployment is already in progress")
              raise "A deployment is already in Progress",DeploymentAlreadyInProgressException
            else
              puts "Stopping #{description(pid)}"
              ProcessManager::Log.info("Stopping #{description(pid)}")
            end  
            Process.kill('TERM', pid)
          rescue Errno::ESRCH
          end
          
          begin
            Timeout.timeout(ProcessManager::Config.config[:kill_agent_max_wait_time_seconds]) do  
              loop do
                begin
                  Process.kill(0, pid)
                  sleep(1)
                rescue Errno::ESRCH
                  break
                end
              end
            end
          rescue Timeout::Error
            puts "Child processes still running. Master going down."
            ProcessManager::Log.warn("Master process (#{pid}) going down before terminating child")
          end
        else
          puts "Nothing running that could be stopped"
        end
      end