func (s *server) kill() error {
	klog.Infof("Kill server %q", s.name)
	name := s.name
	cmd := s.startCommand

	// If s has a restart loop, turn it off.
	if s.restartOnExit {
		s.stopRestartingCh <- true
		<-s.ackStopRestartingCh
	}

	if s.killCommand != nil {
		return s.killCommand.Run()
	}

	if cmd == nil {
		return fmt.Errorf("could not kill %q because both `killCommand` and `startCommand` are nil", name)
	}

	if cmd.Process == nil {
		klog.V(2).Infof("%q not running", name)
		return nil
	}
	pid := cmd.Process.Pid
	if pid <= 1 {
		return fmt.Errorf("invalid PID %d for %q", pid, name)
	}

	// Attempt to shut down the process in a friendly manner before forcing it.
	waitChan := make(chan error)
	go func() {
		_, err := cmd.Process.Wait()
		waitChan <- err
		close(waitChan)
	}()

	const timeout = 10 * time.Second
	for _, signal := range []string{"-TERM", "-KILL"} {
		klog.V(2).Infof("Killing process %d (%s) with %s", pid, name, signal)
		cmd := exec.Command("kill", signal, strconv.Itoa(pid))
		_, err := cmd.Output()
		if err != nil {
			klog.Errorf("Error signaling process %d (%s) with %s: %v", pid, name, signal, err)
			continue
		}

		select {
		case err := <-waitChan:
			if err != nil {
				return fmt.Errorf("error stopping %q: %v", name, err)
			}
			// Success!
			return nil
		case <-time.After(timeout):
			// Continue.
		}
	}

	return fmt.Errorf("unable to stop %q", name)
}
// kill runs the server's kill command.
kill runs the server's kill command.
// kill runs the server ' s kill command .
func (s *server) kill() error {
	klog.Infof("Kill server %q", s.name)
	name := s.name
	cmd := s.startCommand
	if s.restartOnExit {
		s.stopRestartingCh <- true
		<-s.ackStopRestartingCh
	}
	if s.killCommand != nil {
		return s.killCommand.Run()
	}
	if cmd == nil {
		return fmt.Errorf("could not kill %q because both `killCommand` and `startCommand` are nil", name)
	}
	if cmd.Process == nil {
		klog.V(2).Infof("%q not running", name)
		return nil
	}
	pid := cmd.Process.Pid
	if pid <= 1 {
		return fmt.Errorf("invalid PID %d for %q", pid, name)
	}
	waitChan := make(chan error)
	go func() {
		_, err := cmd.Process.Wait()
		waitChan <- err
		close(waitChan)
	}()
	const timeout = 10 * time.Second
	for _, signal := range []string{"-TERM", "-KILL"} {
		klog.V(2).Infof("Killing process %d (%s) with %s", pid, name, signal)
		cmd := exec.Command("kill", signal, strconv.Itoa(pid))
		_, err := cmd.Output()
		if err != nil {
			klog.Errorf("Error signaling process %d (%s) with %s: %v", pid, name, signal, err)
			continue
		}
		select {
		case err := <-waitChan:
			if err != nil {
				return fmt.Errorf("error stopping %q: %v", name, err)
			}
			return nil
		case <-time.After(timeout):
		}
	}
	return fmt.Errorf("unable to stop %q", name)
}
func ( s * server ) kill ( ) error { klog . Infof ( " " , s . name ) name := s . name cmd := s . startCommand if s . restartOnExit { s . stopRestartingCh <- true <- s . ackStopRestartingCh } if s . killCommand != nil { return s . killCommand . Run ( ) } if cmd == nil { return fmt . Errorf ( " " , name ) } if cmd . Process == nil { klog . V ( 2 ) . Infof ( " " , name ) return nil } pid := cmd . Process . Pid if pid <= 1 { return fmt . Errorf ( " " , pid , name ) } waitChan := make ( chan error ) go func ( ) { _ , err := cmd . Process . Wait ( ) waitChan <- err close ( waitChan ) } ( ) const timeout = 10 * time . Second for _ , signal := range [ ] string { " " , " " } { klog . V ( 2 ) . Infof ( " " , pid , name , signal ) cmd := exec . Command ( " " , signal , strconv . Itoa ( pid ) ) _ , err := cmd . Output ( ) if err != nil { klog . Errorf ( " " , pid , name , signal , err ) continue } select { case err := <- waitChan : if err != nil { return fmt . Errorf ( " " , name , err ) } return nil case <- time . After ( timeout ) : } } return fmt . Errorf ( " " , name ) }
kill runs the server's kill command.
kill runs the server ' s kill command .
// If s has a restart loop, turn it off. // Attempt to shut down the process in a friendly manner before forcing it. // Success! // Continue.