Example #1
0
// Start will take a launchable and start every runit service associated with the launchable.
// All services will attempt to be started.
func (hl *Launchable) start(serviceBuilder *runit.ServiceBuilder, sv *runit.SV) error {
	executables, err := hl.Executables(serviceBuilder)
	if err != nil {
		return err
	}

	for _, executable := range executables {
		_, err := sv.Restart(&executable.Service)
		if err != nil && err != runit.SuperviseOkMissing {
			return err
		}
	}

	return nil
}
Example #2
0
func (hl *Launchable) stop(serviceBuilder *runit.ServiceBuilder, sv runit.SV) error {
	executables, err := hl.Executables(serviceBuilder)
	if err != nil {
		return err
	}

	for _, executable := range executables {
		_, err := sv.Stop(&executable.Service, hl.RestartTimeout)
		if err != nil && err != runit.Killed {
			// TODO: FAILURE SCENARIO (what should we do here?)
			// 1) does `sv stop` ever exit nonzero?
			// 2) should we keep stopping them all anyway?
			return err
		}
	}
	return nil
}
Example #3
0
func (l *Launchable) start(serviceBuilder *runit.ServiceBuilder, sv runit.SV) error {
	executables, err := l.Executables(serviceBuilder)
	if err != nil {
		return err
	}

	for _, executable := range executables {
		var err error
		if l.RestartPolicy == runit.RestartPolicyAlways {
			_, err = sv.Restart(&executable.Service, l.RestartTimeout)
		} else {
			_, err = sv.Once(&executable.Service)
		}
		if err != nil && err != runit.SuperviseOkMissing {
			return err
		}
	}

	return nil
}
Example #4
0
func (hl *Launchable) stop(serviceBuilder *runit.ServiceBuilder, sv *runit.SV) error {
	executables, err := hl.Executables(serviceBuilder)
	if err != nil {
		return err
	}

	for _, executable := range executables {
		// if we use sv -w to wait for the service to stop and then SIGKILL, we
		// will also kill the preparer itself before it can restart. do not use
		// sv -w yet.
		_, err := sv.Stop(&executable.Service)
		if err != nil {
			// TODO: FAILURE SCENARIO (what should we do here?)
			// 1) does `sv stop` ever exit nonzero?
			// 2) should we keep stopping them all anyway?
			return err
		}
	}
	return nil
}
Example #5
0
// Start will take a launchable and start every runit service associated with the launchable.
// All services will attempt to be started.
func (hl *Launchable) start(serviceBuilder *runit.ServiceBuilder, sv runit.SV) error {
	executables, err := hl.Executables(serviceBuilder)
	if err != nil {
		return err
	}

	for _, executable := range executables {
		var err error
		if hl.RestartPolicy == runit.RestartPolicyAlways {
			_, err = sv.Restart(&executable.Service, hl.RestartTimeout)
		} else {
			_, err = sv.Once(&executable.Service)
		}
		if err != nil && err != runit.SuperviseOkMissing && err != runit.Killed {
			return err
		}

		if _, err = sv.Restart(&executable.LogAgent, runit.DefaultTimeout); err != nil && err != runit.Killed {
			return err
		}

	}

	return nil
}
Example #6
0
func (l *Launchable) stop(serviceBuilder *runit.ServiceBuilder, sv runit.SV) error {
	executables, err := l.Executables(serviceBuilder)
	if err != nil {
		return err
	}

	for _, executable := range executables {
		_, err := sv.Stop(&executable.Service, l.RestartTimeout)
		if err != nil {
			cmd := exec.Command(
				l.P2Exec,
				p2exec.P2ExecArgs{
					WorkDir: l.InstallDir(),
					Command: []string{*RuncPath, "kill", "SIGKILL"},
				}.CommandLine()...,
			)
			err = cmd.Run()
			if err != nil {
				return util.Errorf("%s: error stopping container: %s", l.ServiceID_, err)
			}
		}
	}
	return nil
}