예제 #1
0
파일: unit_main.go 프로젝트: pulcy/j2
// createMainUnit
func createMainUnit(t *jobs.Task, sidekickUnitNames []string, engine engine.Engine, ctx generatorContext) (*sdunits.Unit, error) {
	unit, err := createDefaultUnit(t,
		unitName(t, unitKindMain, ctx.ScalingGroup),
		unitDescription(t, "Main", ctx.ScalingGroup),
		"service", unitKindMain, ctx)
	if err != nil {
		return nil, maskAny(err)
	}
	cmds, err := engine.CreateMainCmds(t, unit.ExecOptions.Environment, ctx.ScalingGroup)
	if err != nil {
		return nil, maskAny(err)
	}
	setupUnitFromCmds(unit, cmds)
	switch t.Type {
	case "oneshot":
		unit.ExecOptions.IsOneshot = true
		unit.ExecOptions.Restart = "on-failure"
	case "proxy":
		unit.ExecOptions.Restart = "always"
	default:
		unit.ExecOptions.Restart = "always"
	}

	// Additional service dependencies
	unit.ExecOptions.Require(sidekickUnitNames...)
	unit.ExecOptions.After(sidekickUnitNames...)
	for _, name := range t.VolumesFrom {
		other, err := t.Task(name)
		if err != nil {
			return nil, maskAny(err)
		}
		otherName := unitName(other, unitKindMain, ctx.ScalingGroup) + ".service"
		unit.ExecOptions.Require(otherName)
		unit.ExecOptions.After(otherName)
	}

	// Add metrics registration commands
	if err := addMetricsRegistration(t, unit, ctx); err != nil {
		return nil, maskAny(err)
	}

	// Add frontend registration commands
	if err := addFrontEndRegistration(t, unit, ctx); err != nil {
		return nil, maskAny(err)
	}

	return unit, nil
}
예제 #2
0
파일: unit_proxy.go 프로젝트: pulcy/j2
// createProxyUnit
func createProxyUnit(t *jobs.Task, link jobs.Link, linkIndex int, engine engine.Engine, ctx generatorContext) (*sdunits.Unit, error) {
	namePostfix := fmt.Sprintf("%s%d", unitKindProxy, linkIndex)
	unit, err := createDefaultUnit(t,
		unitName(t, namePostfix, ctx.ScalingGroup),
		unitDescription(t, fmt.Sprintf("Proxy %d", linkIndex), ctx.ScalingGroup),
		"service", namePostfix, ctx)
	if err != nil {
		return nil, maskAny(err)
	}
	unit.ExecOptions.StopWhenUnneeded()
	cmds, err := engine.CreateProxyCmds(t, link, linkIndex, unit.ExecOptions.Environment, ctx.ScalingGroup)
	if err != nil {
		return nil, maskAny(err)
	}
	setupUnitFromCmds(unit, cmds)

	return unit, nil
}
예제 #3
0
파일: unit_volume.go 프로젝트: pulcy/j2
// createVolumeUnit
func createVolumeUnit(t *jobs.Task, vol jobs.Volume, volIndex int, engine engine.Engine, ctx generatorContext) (*sdunits.Unit, error) {
	namePostfix := createVolumeUnitNamePostfix(volIndex)
	volPrefix := path.Join(fmt.Sprintf("%s/%v", t.FullName(), ctx.ScalingGroup), vol.Path)
	volHostPath := fmt.Sprintf("/media/%s", volPrefix)

	unit, err := createDefaultUnit(t,
		unitName(t, namePostfix, ctx.ScalingGroup),
		unitDescription(t, fmt.Sprintf("Volume %d", volIndex), ctx.ScalingGroup),
		"service", namePostfix, ctx)
	if err != nil {
		return nil, maskAny(err)
	}
	cmds, err := engine.CreateVolumeCmds(t, vol, volIndex, volPrefix, volHostPath, unit.ExecOptions.Environment, ctx.ScalingGroup)
	if err != nil {
		return nil, maskAny(err)
	}
	setupUnitFromCmds(unit, cmds)

	return unit, nil
}