// runMaster is the main function of the master process.
190847
func (g *Graceful) runMaster(ctx context.Context) error {
	logger := log.DefaultLogger()

	// prepare listener files
	listeners, err := g.Listen()
	if err != nil {
		return err
	}
	files, err := listenerFiles(listeners)
	if err != nil {
		return err
	}
	if len(files) == 0 {
		return errors.New("no listener")
	}
	defer func() {
		for _, f := range files {
			f.Close()
		}
		// we cannot close listeners no sooner than this point
		// because net.UnixListener removes the socket file on Close.
		for _, l := range listeners {
			l.Close()
		}
	}()

	sighup := make(chan os.Signal, 2)
	signal.Notify(sighup, syscall.SIGHUP)

RESTART:
	child := g.makeChild(files)
	clog, err := child.StderrPipe()
	if err != nil {
		return err
	}
	copyDone := make(chan struct{})
	// clog will be closed on child.Wait().
	go copyLog(logger, clog, copyDone)

	done := make(chan error, 1)
	err = child.Start()
	if err != nil {
		return err
	}
	go func() {
		<-copyDone
		done <- child.Wait()
	}()

	select {
	case err := <-done:
		return err
	case <-sighup:
		child.Process.Signal(syscall.SIGTERM)
		log.Warn("well: got sighup", nil)
		time.Sleep(restartWait)
		goto RESTART
	case <-ctx.Done():
		child.Process.Signal(syscall.SIGTERM)
		if g.ExitTimeout == 0 {
			<-done
			return nil
		}
		select {
		case <-done:
			return nil
		case <-time.After(g.ExitTimeout):
			logger.Warn("well: timeout child exit", nil)
			return nil
		}
	}
}
1150463
func (c *removeCommand) Run(ctx *cmd.Context) (err error) {
	client, err := getRemoveImageAPI(&c.CachedImagesCommandBase)
	if err != nil {
		return err
	}
	defer client.Close()

	return client.DeleteImage(c.Kind, c.Series, c.Arch)
}
459177
func runAsNewCommand(cmd CommandRunner, mode string) {
	execCmd, ok := cmd.(ExecRunner)
	if !ok {
		panic(fmt.Sprintf("%v does not implement ExecRunner", mode))
	}
	cmdPath, err := execCmd.LookPath()
	if err != nil {
		Errorf("Error: %v\n", err)
		Exit(2)
	}
	allArgs := shiftFlags(mode)
	if err := runExec(cmdPath, allArgs, newCopyEnv()); err != nil {
		panic(fmt.Sprintf("running %v should have ended with an os.Exit, and not leave us with that error: %v", cmdPath, err))
	}
}
65703
func RunCommand(fs *flag.FlagSet, cmd *Command, projectroot, goroot string, args []string) error {
	if cmd.AddFlags != nil {
		cmd.AddFlags(fs)
	}
	if err := fs.Parse(args); err != nil {
		fs.Usage()
		os.Exit(1)
	}
	args = fs.Args() // reset to the remaining arguments

	ctx, err := NewContext(projectroot, gb.GcToolchain())
	if err != nil {
		return errors.Wrap(err, "unable to construct context")
	}
	defer ctx.Destroy()

	ctx.Debug("args: %v", args)
	return cmd.Run(ctx, args)
}
86468
func AllMasters(c context.Context, checkAccess bool) ([]*Master, error) {
	const batchSize = int32(500)
	masters := make([]*Master, 0, batchSize)
	q := datastore.NewQuery(masterKind)

	// note: avoid calling isAllowedInternal is checkAccess is false.
	// checkAccess is usually false in cron jobs where there is no auth state,
	// so isAllowedInternal call would unconditionally log an error.
	allowInternal := !checkAccess || isAllowedInternal(c)
	err := datastore.RunBatch(c, batchSize, q, func(e *masterEntity) error {
		if allowInternal || !e.Internal {
			m, err := e.decode(c)
			if err != nil {
				return err
			}
			masters = append(masters, m)
		}
		return nil
	})
	return masters, err
}
81814
func (c *SetMeterStatusCommand) Run(ctx *cmd.Context) error {
	client, err := newClient(c.ModelCommandBase)
	if err != nil {
		return errors.Trace(err)
	}
	defer client.Close()
	err = client.SetMeterStatus(c.Tag.String(), c.Status, c.StatusInfo)
	if err != nil {
		return errors.Trace(err)
	}
	return nil
}
702744
func (mr *ModRunner) Run() error {
	for {
		modchan := make(chan *moddwatch.Mod, 1024)
		err := mr.runOnChan(modchan, func() {})
		if err != nil {
			return err
		}
	}
}
798808
func (c *addImageMetadataCommand) Run(ctx *cmd.Context) (err error) {
	api, err := getImageMetadataAddAPI(c)
	if err != nil {
		return err
	}
	defer api.Close()

	m := c.constructMetadataParam()
	if err := api.Save([]params.CloudImageMetadata{m}); err != nil {
		return errors.Trace(err)
	}
	return nil
}
428626
func (runner *runner) RunCommands(commands string) (*utilexec.ExecResponse, error) {
	result, err := runner.runCommandsWithTimeout(commands, 0, clock.WallClock)
	return result, runner.context.Flush("run commands", err)
}
404879
func (c *APIClient) RunMethod(name string) ([]byte, error) {
	resp, err := c.slackMethod(name)
	if err != nil {
		return nil, err
	}
	defer resp.Body.Close()

	return ioutil.ReadAll(resp.Body)
}
4640
func runCommand(ctx context.Context, command []string) error {
	cmd := exec.Command(command[0], command[1:]...)
	cmd.Stderr = os.Stderr
	cmd.Stdout = os.Stdout
	return cmd.Run()
}
564707
func (c *configCommand) Run(ctx *cmd.Context) error {
	client, err := c.getAPI()
	if err != nil {
		return errors.Trace(err)
	}
	defer func() { _ = client.Close() }()

	if len(c.resetKeys) > 0 {
		if err := c.resetConfig(client, ctx); err != nil {
			// We return this error naked as it is almost certainly going to be
			// cmd.ErrSilent and the cmd.Command framework expects that back
			// from cmd.Run if the process is blocked.
			return err
		}
	}
	if c.action == nil {
		// If we are reset only, we end up here; we have already done that.
		return nil
	}

	return c.action(client, ctx)
}
317952
func (c *FleetClient) runCommand(cmd string, machID string) (retcode int) {
	var err error
	if machine.IsLocalMachineID(machID) {
		retcode, err = c.runner.LocalCommand(cmd)
		if err != nil {
			fmt.Fprintf(c.errWriter, "Error running local command: %v\n", err)
		}
	} else {
		ms, err := c.machineState(machID)
		if err != nil || ms == nil {
			fmt.Fprintf(c.errWriter, "Error getting machine IP: %v\n", err)
		} else {
			sshTimeout := time.Duration(Flags.SSHTimeout*1000) * time.Millisecond
			retcode, err = c.runner.RemoteCommand(cmd, ms.PublicIP, sshTimeout)
			if err != nil {
				fmt.Fprintf(c.errWriter, "Error running remote command: %v\n", err)
			}
		}
	}
	return
}
448063
func (r *RunListener) RunCommands(args RunCommandsArgs) (results *exec.ExecResponse, err error) {
	logger.Tracef("run commands: %s", args.Commands)
	return r.CommandRunner.RunCommands(args)
}
268076
func (m *Manager) Run(ctx context.Context) {
	// Save the context for all other jobs usage, and to indicate
	// the manager is running.
	m.mu.Lock()
	if m.ctx != nil {
		m.mu.Unlock()
		panic("Manager is already running")
	}
	m.ctx = ctx
	m.loadAndStartJobsLocked()
	// Signal the successful startup.
	close(m.started)
	m.started = make(chan struct{})
	m.mu.Unlock()

	// Wait for the context to be canceled.
	<-ctx.Done()

	// Clear context and get a copy of the running jobs.
	m.mu.Lock()
	m.ctx = nil
	runningWorkflows := m.workflows
	m.workflows = make(map[string]*runningWorkflow)
	m.mu.Unlock()

	// Abort the running jobs. They won't save their state as
	// m.ctx is nil and they know it means we're shutting down.
	for _, rw := range runningWorkflows {
		rw.cancel()
	}
	for _, rw := range runningWorkflows {
		<-rw.done
	}
}
1284382
func (cfg *cloudConfig) RunCmds() []string {
	cmds, _ := cfg.attrs["runcmd"].([]string)
	return cmds
}
671708
func (g *Cloud) Master(ctx context.Context, clusterName string) (string, error) {
	return "k8s-" + clusterName + "-master.internal", nil
}