// Start a process
357342
func (s *Service) Start(ctx context.Context, r *shimapi.StartRequest) (*shimapi.StartResponse, error) {
	p, err := s.getExecProcess(r.ID)
	if err != nil {
		return nil, err
	}
	if err := p.Start(ctx); err != nil {
		return nil, err
	}
	return &shimapi.StartResponse{
		ID:  p.ID(),
		Pid: uint32(p.Pid()),
	}, nil
}
1015938
func (prg *Program) Start(srv service.Service) error {
	os.Exit(0)
	return nil
}
353722
func (s *service) Start(ctx context.Context, r *taskAPI.StartRequest) (*taskAPI.StartResponse, error) {
	return nil, errdefs.ErrNotImplemented
}
73880
func (c *Command) Start() error {

	cmd, err := c.buildCmd()
	if err != nil {
		return err
	}
	cmd.Stdout = logfile(c.GetLogfile())
	cmd.Stderr = logfile(c.GetLogfile())
	if c.WorkingDir != "" {
		cmd.Dir = c.WorkingDir
	}

	if c.UseEnv {
		flagEnv := filepath.Join(cmd.Dir, ".env")
		env, _ := ReadEnv(flagEnv)
		cmd.Env = env.asArray()
	} else if len(c.Env) > 0 {
		cmd.Env = c.Env.asArray()
	}

	pid, err := start(cmd)
	if err != nil {
		return err
	}
	c.Pid = pid
	return nil
}
13514
func (s Service) Start() error {
	running, err := s.Running()
	if err != nil {
		return errors.Trace(err)
	}
	if running {
		return nil
	}

	commands, err := s.StartCommands()
	if err != nil {
		return errors.Trace(err)
	}
	for _, command := range commands {
		commandParts := strings.Fields(command)
		out, err := utils.RunCommand(commandParts[0], commandParts[1:]...)
		if err != nil {
			if strings.Contains(out, "has no services") {
				continue
			}
			return errors.Annotatef(err, "%v -> %v", command, out)
		}
	}

	return nil
}
834584
func (s *Stdin) Start() error {
	if os.Stdin == nil {
		return errors.New("stdin is not available")
	}
	return nil
}
693773
func (as *Step) Start(startTime *timestamp.Timestamp) bool {
	if as.Started != nil {
		return false
	}
	as.Started = startTime
	return true
}
726830
func StartProcess(label string, dir string, execPath string, args []string, inFile io.Reader, outFile io.WriteCloser) (*Process, error) {
	cmd := exec.Command(execPath, args...)
	cmd.Dir = dir
	cmd.Stdout = outFile
	cmd.Stderr = outFile
	cmd.Stdin = inFile
	if err := cmd.Start(); err != nil {
		return nil, err
	}
	proc := &Process{
		Label:      label,
		ExecPath:   execPath,
		Args:       args,
		Pid:        cmd.Process.Pid,
		StartTime:  time.Now(),
		Cmd:        cmd,
		ExitState:  nil,
		InputFile:  inFile,
		OutputFile: outFile,
		WaitCh:     make(chan struct{}),
	}
	go func() {
		err := proc.Cmd.Wait()
		if err != nil {
			// fmt.Printf("Process exit: %v\n", err)
			if exitError, ok := err.(*exec.ExitError); ok {
				proc.ExitState = exitError.ProcessState
			}
		}
		proc.ExitState = proc.Cmd.ProcessState
		proc.EndTime = time.Now() // TODO make this goroutine-safe
		err = proc.OutputFile.Close()
		if err != nil {
			fmt.Printf("Error closing output file for %v: %v\n", proc.Label, err)
		}
		close(proc.WaitCh)
	}()
	return proc, nil
}
969605
func (s *Service) Start() error {
	running, err := s.Running()
	if err != nil {
		return errors.Trace(err)
	}
	if running {
		return nil
	}
	err = runCommand("start", "--system", s.Service.Name)
	if err != nil {
		// Double check to see if we were started before our command ran.
		// If this fails then we simply trust it's okay.
		if running, _ := s.Running(); running {
			return nil
		}
	}
	return err
}
1321705
func Launch(cmd []string, wd string, foreground bool, _ []string) (*Process, error) {
	// check that the argument to Launch is an executable file
	if fi, staterr := os.Stat(cmd[0]); staterr == nil && (fi.Mode()&0111) == 0 {
		return nil, proc.ErrNotExecutable
	}
	argv0Go, err := filepath.Abs(cmd[0])
	if err != nil {
		return nil, err
	}
	// Make sure the binary exists.
	if filepath.Base(cmd[0]) == cmd[0] {
		if _, err := exec.LookPath(cmd[0]); err != nil {
			return nil, err
		}
	}
	if _, err := os.Stat(argv0Go); err != nil {
		return nil, err
	}

	argv0 := C.CString(argv0Go)
	argvSlice := make([]*C.char, 0, len(cmd)+1)
	for _, arg := range cmd {
		argvSlice = append(argvSlice, C.CString(arg))
	}
	// argv array must be null terminated.
	argvSlice = append(argvSlice, nil)

	dbp := New(0)
	var pid int
	dbp.execPtraceFunc(func() {
		ret := C.fork_exec(argv0, &argvSlice[0], C.int(len(argvSlice)),
			C.CString(wd),
			&dbp.os.task, &dbp.os.portSet, &dbp.os.exceptionPort,
			&dbp.os.notificationPort)
		pid = int(ret)
	})
	if pid <= 0 {
		return nil, fmt.Errorf("could not fork/exec")
	}
	dbp.pid = pid
	dbp.childProcess = true
	for i := range argvSlice {
		C.free(unsafe.Pointer(argvSlice[i]))
	}

	// Initialize enough of the Process state so that we can use resume and
	// trapWait to wait until the child process calls execve.

	for {
		task := C.get_task_for_pid(C.int(dbp.pid))
		// The task_for_pid call races with the fork call. This can
		// result in the parent task being returned instead of the child.
		if task != dbp.os.task {
			err = dbp.updateThreadListForTask(task)
			if err == nil {
				break
			}
			if err != couldNotGetThreadCount && err != couldNotGetThreadList {
				return nil, err
			}
		}
	}

	if err := dbp.resume(); err != nil {
		return nil, err
	}

	dbp.common.ClearAllGCache()
	for _, th := range dbp.threads {
		th.CurrentBreakpoint.Clear()
	}

	trapthread, err := dbp.trapWait(-1)
	if err != nil {
		return nil, err
	}
	if err := dbp.stop(nil); err != nil {
		return nil, err
	}

	dbp.os.initialized = true
	err = dbp.initialize(argv0Go, []string{})
	if err != nil {
		return nil, err
	}

	if err := dbp.SwitchThread(trapthread.ID); err != nil {
		return nil, err
	}

	return dbp, err
}
427074
func start() {
	defer func() {
		if r := recover(); r != nil {
			fmt.Fprintf(os.Stderr, "initd: panicked: %s\n", r)
			os.Exit(4)
		}
	}()

	flag.String("title", "", "")
	dropCaps := flag.Bool("dropCapabilities", false, "drop capabilities before running processes")
	flag.Parse()

	container_daemon.Detach("/dev/null", "/dev/null")
	logger := lager.NewLogger("initd")

	syncWriter := os.NewFile(uintptr(4), "/dev/sync_writer")
	syscall.RawSyscall(syscall.SYS_FCNTL, uintptr(4), syscall.F_SETFD, syscall.FD_CLOEXEC)
	defer syncWriter.Close()

	sync := &containerizer.PipeSynchronizer{
		Writer: syncWriter,
	}

	reaper := system.StartReaper(logger, syscall.Wait4)
	defer reaper.Stop()

	daemon := &container_daemon.ContainerDaemon{
		CmdPreparer: &container_daemon.ProcessSpecPreparer{
			Users:   container_daemon.LibContainerUser{},
			Rlimits: &container_daemon.RlimitsManager{},
			Reexec: container_daemon.CommandFunc(func(args ...string) *exec.Cmd {
				return &exec.Cmd{
					Path: "/proc/self/exe",
					Args: args,
				}
			}),
			AlwaysDropCapabilities: *dropCaps,
		},
		Spawner: &container_daemon.Spawn{
			Runner: reaper,
			PTY:    system.KrPty,
		},
		Signaller: &container_daemon.ProcessSignaller{
			Logger: logger,
		},
	}

	socketFile := os.NewFile(uintptr(5), "/dev/host.sock")
	listener, err := unix_socket.NewListenerFromFile(socketFile)
	if err != nil {
		fail(fmt.Sprintf("initd: failed to create listener: %s\n", err), 5)
	}

	socketFile.Close()

	if err := sync.SignalSuccess(); err != nil {
		fail(fmt.Sprintf("signal host: %s", err), 6)
	}

	if err := daemon.Run(listener); err != nil {
		fail(fmt.Sprintf("run daemon: %s", err), 7)
	}
}
273269
func (s *serviceConfigWatch) Start() error {
	s.ctx, s.cancelFunc = context.WithCancel(context.Background())
	if err := s.ensureConfigWatch(); err != nil {
		return err
	}
	go s.runWatch()

	return nil
}
504566
func (c *Connect) Start() error {
	c.cmd = exec.Command(c.Path, c.Args...)
	if c.UserName != "" {
		c.cmd.Args = append(c.cmd.Args, "--user", c.UserName)
	}
	if c.AccessKey != "" {
		c.cmd.Args = append(c.cmd.Args, "--api-key", c.AccessKey)
	}
	if c.SeleniumPort > 0 {
		c.cmd.Args = append(c.cmd.Args, "--se-port", strconv.Itoa(c.SeleniumPort))
	}
	if c.ExtraVerbose {
		c.cmd.Args = append(c.cmd.Args, "-vv")
	} else if c.Verbose {
		c.cmd.Args = append(c.cmd.Args, "-v")
	}
	if c.ExtraVerbose || c.Verbose {
		c.cmd.Stdout = os.Stdout
		c.cmd.Stderr = os.Stderr
	}
	if c.LogFile != "" {
		c.cmd.Args = append(c.cmd.Args, "--logfile", c.LogFile)
	}
	if c.QuitProcessUponExit && runtime.GOOS == "linux" {
		c.cmd.SysProcAttr = &syscall.SysProcAttr{
			// Deliver SIGTERM to process when we die.
			Pdeathsig: syscall.SIGTERM,
		}
	}

	dir, err := ioutil.TempDir("", "selenium-sauce-connect")
	if err != nil {
		return err
	}
	defer func() {
		os.RemoveAll(dir) // ignore error.
	}()

	var pidFilePath string
	if c.PIDFile != "" {
		pidFilePath = c.PIDFile
	} else {
		f, err := ioutil.TempFile("", "selenium-sauce-connect-pid.")
		if err != nil {
			return err
		}
		pidFilePath = f.Name()
		f.Close() // ignore the error.
	}

	// The path specified here will be touched by the proxy process when it is
	// ready to accept connections.
	readyPath := filepath.Join(dir, "ready")
	c.cmd.Args = append(c.cmd.Args, "--readyfile", readyPath)
	c.cmd.Args = append(c.cmd.Args, "--pidfile", pidFilePath)

	if err := c.cmd.Start(); err != nil {
		return err
	}

	// Wait for the Proxy to accept connections.
	var started bool
	for i := 0; i < 60; i++ {
		time.Sleep(time.Second)
		if _, err := os.Stat(readyPath); err == nil {
			started = true
			break
		}
	}
	if !started {
		c.Stop() // ignore error.
		return fmt.Errorf("proxy process did not become ready before the timeout")
	}
	return nil
}
861952
func (cmd AppCmd) Start(c *model.CommandConfig) error {
	listeningWriter := &startupListeningWriter{os.Stdout, make(chan bool), c, &bytes.Buffer{}}
	cmd.Stdout = listeningWriter
	utils.Logger.Info("Exec app:", "path", cmd.Path, "args", cmd.Args, "dir", cmd.Dir, "env", cmd.Env)
	utils.CmdInit(cmd.Cmd, c.AppPath)
	if err := cmd.Cmd.Start(); err != nil {
		utils.Logger.Fatal("Error running:", "error", err)
	}

	select {
	case exitState := <-cmd.waitChan():
		fmt.Println("Startup failure view previous messages, \n Proxy is listening :", c.Run.Port)
		err := utils.NewError("","Revel Run Error", "starting your application there was an exception. See terminal output, " + exitState,"")
		// TODO pretiffy command line output
		// err.MetaError = listeningWriter.getLastOutput()
		return err

	case <-time.After(60 * time.Second):
		println("Revel proxy is listening, point your browser to :", c.Run.Port)
		utils.Logger.Error("Killing revel server process did not respond after wait timeout.", "processid", cmd.Process.Pid)
		cmd.Kill()
		return errors.New("revel/harness: app timed out")

	case <-listeningWriter.notifyReady:
		println("Revel proxy is listening, point your browser to :", c.Run.Port)
		return nil
	}

}
641142
func (c *Gcd) startProcess() error {
	go func() {
		err := c.chromeCmd.Start()
		if err != nil {
			msg := fmt.Sprintf("failed to start chrome: %s", err)
			if c.terminatedHandler != nil {
				c.terminatedHandler(msg)
			} else {
				log.Println(msg)
			}
		}
		c.chromeProcess = c.chromeCmd.Process
		err = c.chromeCmd.Wait()

		c.removeProfileDir()

		closeMessage := "exited"
		if err != nil {
			closeMessage = err.Error()
		}
		if c.terminatedHandler != nil {
			c.terminatedHandler(closeMessage)
		}
	}()

	var err error
	go func(err error) {
		err = c.probeDebugPort()
	}(err)
	<-c.readyCh

	return err
}
888573
func (n *Node) Start(ctx context.Context) error {
	err := errNodeStarted

	n.startOnce.Do(func() {
		close(n.started)
		go n.run(ctx)
		err = nil // clear error above, only once.
	})
	return err
}
509388
func (r *agentReaper) start(c *exec.Cmd) (<-chan int, error) {
	// This lock is very important to avoid any race with reaper.reap().
	// We don't want the reaper to reap a process before we have added
	// it to the exit code channel list.
	r.RLock()
	defer r.RUnlock()

	if err := c.Start(); err != nil {
		return nil, err
	}

	exitCodeCh := make(chan int, 1)

	// This channel is buffered so that reaper.reap() will not
	// block until reaper.wait() listen onto this channel.
	r.setExitCodeCh(c.Process.Pid, exitCodeCh)

	return exitCodeCh, nil
}