// transitionUnitsStarted iterates over units managed by this machine. Starts
// the unit's agent service, and transitions all unit subordinate statuses.
494464
func (w *upgradeSeriesWorker) transitionUnitsStarted(unitServices map[string]string) error {
	w.logger.Infof("ensuring units are up after series upgrade")

	for unit, serviceName := range unitServices {
		svc, err := w.service.DiscoverService(serviceName)
		if err != nil {
			return errors.Trace(err)
		}
		running, err := svc.Running()
		if err != nil {
			return errors.Trace(err)
		}
		if running {
			continue
		}
		if err := svc.Start(); err != nil {
			return errors.Annotatef(err, "starting %q unit agent after series upgrade", unit)
		}
	}

	return errors.Trace(w.StartUnitCompletion("started unit agents after series upgrade"))
}
512044
func (m *Machine) Transition(t string, args ...interface{}) error {
	m.Lock()
	defer m.Unlock()

	if t == "" {
		return nil
	}

	if m.fsm.Can(t) {
		m.fsm.Event(t, args...)
	} else {
		m.Warnf("machine", "Could not fire '%s' event while in %s", t, m.fsm.Current())
	}

	return nil
}
203780
func (fw *Firewaller) startUnit(unit *firewaller.Unit, machineTag names.MachineTag) error {
	application, err := unit.Application()
	if err != nil {
		return err
	}
	applicationTag := application.Tag()
	unitTag := unit.Tag()
	if err != nil {
		return err
	}
	unitd := &unitData{
		fw:   fw,
		unit: unit,
		tag:  unitTag,
	}
	fw.unitds[unitTag] = unitd

	unitd.machined = fw.machineds[machineTag]
	unitd.machined.unitds[unitTag] = unitd
	if fw.applicationids[applicationTag] == nil {
		err := fw.startApplication(application)
		if err != nil {
			delete(fw.unitds, unitTag)
			delete(unitd.machined.unitds, unitTag)
			return err
		}
	}
	unitd.applicationd = fw.applicationids[applicationTag]
	unitd.applicationd.unitds[unitTag] = unitd

	m, err := unitd.machined.machine()
	if err != nil {
		return err
	}

	// check if the machine has ports open on any subnets
	subnetTags, err := m.ActiveSubnets()
	if err != nil {
		return errors.Annotatef(err, "failed getting %q active subnets", machineTag)
	}
	for _, subnetTag := range subnetTags {
		err := fw.openedPortsChanged(machineTag, subnetTag)
		if err != nil {
			return err
		}
	}

	return nil
}
175917
func (s *GracefulServer) StartRoutine() {
	s.lcsmu.Lock()
	defer s.lcsmu.Unlock()
	s.wg.Add(1)
	s.routinesCount++
}
295561
func (f *FSM) AddInitialState(state *FSMState) {
	f.AddState(state)
	f.initialState = state
}
1109111
func (c *FleetClient) createServiceUnit(component string, num int) (name string, uf *unit.UnitFile, err error) {
	name, err = formatUnitName(component, num)
	if err != nil {
		return "", nil, err
	}
	decorateStr, err := c.configBackend.GetWithDefault("/deis/platform/enablePlacementOptions", "false")
	if err != nil {
		return "", nil, err
	}
	decorate, err := strconv.ParseBool(decorateStr)
	if err != nil {
		return "", nil, err
	}
	uf, err = NewUnit(component, c.templatePaths, decorate)
	if err != nil {
		return
	}
	return name, uf, nil
}
51054
func (linux *systemDRecord) Start() (string, error) {
	startAction := "Starting " + linux.description + ":"

	if ok, err := checkPrivileges(); !ok {
		return startAction + failed, err
	}

	if !linux.isInstalled() {
		return startAction + failed, ErrNotInstalled
	}

	if _, ok := linux.checkRunning(); ok {
		return startAction + failed, ErrAlreadyRunning
	}

	if err := exec.Command("systemctl", "start", linux.name+".service").Run(); err != nil {
		return startAction + failed, err
	}

	return startAction + success, nil
}
1066583
func (c *controller) AgentInitWait() {
	c.Lock()
	agentInitDone := c.agentInitDone
	c.Unlock()

	if agentInitDone != nil {
		<-agentInitDone
	}
}
1188244
func startService() error {
	// Connect to the windows service manager.
	serviceManager, err := mgr.Connect()
	if err != nil {
		return err
	}
	defer serviceManager.Disconnect()

	service, err := serviceManager.OpenService(svcName)
	if err != nil {
		return fmt.Errorf("could not access service: %v", err)
	}
	defer service.Close()

	err = service.Start(os.Args)
	if err != nil {
		return fmt.Errorf("could not start service: %v", err)
	}

	return nil
}
793073
func (s *Service) StartCommands() ([]string, error) {
	// TODO(ericsnow) Add clarification about why transient services are not started.
	if s.Service.Conf.Transient {
		return nil, nil
	}
	return []string{"start " + s.Service.Name}, nil
}
182164
func (c *Command) startupJoin(config *Config, agent *Agent) error {
	if len(config.StartJoin) == 0 {
		return nil
	}

	c.Ui.Output(fmt.Sprintf("Joining cluster...(replay: %v)", config.ReplayOnJoin))
	n, err := agent.Join(config.StartJoin, config.ReplayOnJoin)
	if err != nil {
		return err
	}

	c.Ui.Info(fmt.Sprintf("Join completed. Synced with %d initial agents", n))
	return nil
}
833271
func (uow *UnitOfWork) Start() {
	uow.prepareRequirements()
	for _, container := range uow.Containers() {
		if includes(uow.targeted, container.Name()) {
			container.Start(true)
		} else if includes(uow.requireStarted, container.Name()) || !container.Exists() {
			container.Start(false)
		}
	}
}
1034493
func (s *Server) OnStart() error {
	go s.loop(state{
		subscriptions: make(map[string]map[string]*Subscription),
		queries:       make(map[string]*queryPlusRefCount),
	})
	return nil
}
141905
func (s *Service) Start() error {
	logger.Infof("Starting service %q", s.Service.Name)
	running, err := s.Running()
	if err != nil {
		return errors.Trace(err)
	}
	if running {
		logger.Infof("Service %q already running", s.Service.Name)
		return nil
	}
	err = s.manager.Start(s.Name())
	return err
}
663462
func (a *AAgent) Transition(name string, version string, path string, id string, transition string) error {
	m := a.findMachine(name, version, path, id)
	if m == nil {
		return fmt.Errorf("could not find machine with id %s", id)
	}

	if !m.machine.Can(transition) {
		return fmt.Errorf("transition %s is not valid while in %v state", transition, m.machine.State())
	}

	err := m.machine.Transition(transition)
	if err != nil {
		return err
	}

	return nil
}
836813
func (m *Mgr) DisableAgentAutoStart() error {
	const name = "bosh-agent"
	s, err := m.m.OpenService("bosh-agent")
	if err != nil {
		return &ServiceError{"opening service", name, err}
	}
	defer s.Close()
	return SetStartType(s, mgr.StartManual)
}
1197585
func TransitionEnd(listener func(*vecty.Event)) *vecty.EventListener {
	return &vecty.EventListener{Name: "transitionend", Listener: listener}
}