Exemple #1
0
func main() {
	bin2pod.Version(version.VERSION)
	kingpin.MustParse(bin2pod.Parse(os.Args[1:]))

	res := result{}
	manifestBuilder := manifest.NewBuilder()
	manifestBuilder.SetID(podID())

	stanza := launch.LaunchableStanza{}
	stanza.LaunchableType = "hoist"

	workingDir := activeDir()

	err := addManifestConfig(manifestBuilder)
	tarLocation, err := makeTar(workingDir)
	if err != nil {
		log.Fatalln(err.Error())
	}
	res.TarPath = tarLocation

	if *location != "" {
		stanza.Location = *location
		res.FinalLocation = *location
	} else {
		stanza.Location = fmt.Sprintf("file://%v", tarLocation)
		res.FinalLocation = tarLocation
	}

	manifestBuilder.SetLaunchables(map[launch.LaunchableID]launch.LaunchableStanza{
		launch.LaunchableID(podID()): stanza,
	})

	if err != nil {
		log.Fatalln(err.Error())
	}

	manifest := manifestBuilder.GetManifest()
	res.ManifestPath, err = writeManifest(workingDir, manifest)
	if err != nil {
		log.Fatalf("Couldn't write manifest: %s", err)
	}

	b, err := json.MarshalIndent(res, "", "  ")
	if err != nil {
		log.Fatalf("Couldn't marshal output: %s", err)
	}
	_, err = os.Stdout.Write(b)
	if err != nil {
		log.Fatalf("Couldn't write to stdout: %s", err)
	}
}
Exemple #2
0
func (pod *Pod) getLaunchable(launchableID launch.LaunchableID, launchableStanza launch.LaunchableStanza, runAsUser string) (launch.Launchable, error) {
	launchableRootDir := filepath.Join(pod.home, launchableID.String())
	serviceId := strings.Join(
		[]string{
			pod.UniqueName(),
			"__",
			launchableID.String(),
		}, "")

	restartTimeout := pod.DefaultTimeout

	if launchableStanza.RestartTimeout != "" {
		possibleTimeout, err := time.ParseDuration(launchableStanza.RestartTimeout)
		if err != nil {
			pod.logger.WithError(err).Errorf("%v is not a valid restart timeout - must be parseable by time.ParseDuration(). Using default time %v", launchableStanza.RestartTimeout, restartTimeout)
		} else {
			restartTimeout = possibleTimeout
		}
	}

	version, err := launchableStanza.LaunchableVersion()
	if err != nil {
		pod.logger.WithError(err).Warnf("Could not parse version from launchable %s.", launchableID)
	}

	if launchableStanza.LaunchableType == "hoist" {
		entryPoints := launchableStanza.EntryPoints
		if len(entryPoints) == 0 {
			entryPoints = append(entryPoints, path.Join("bin", "launch"))
		}
		cgroupName := serviceId
		if *NestedCgroups {
			cgroupName = filepath.Join(
				"p2",
				pod.node.String(),
				pod.UniqueName(),
				launchableID.String(),
			)
		}

		ret := &hoist.Launchable{
			Version:          version,
			Id:               launchableID,
			ServiceId:        serviceId,
			RunAs:            runAsUser,
			PodEnvDir:        pod.EnvDir(),
			RootDir:          launchableRootDir,
			P2Exec:           pod.P2Exec,
			ExecNoLimit:      true,
			RestartTimeout:   restartTimeout,
			RestartPolicy_:   launchableStanza.RestartPolicy(),
			CgroupConfig:     launchableStanza.CgroupConfig,
			CgroupConfigName: launchableID.String(),
			CgroupName:       cgroupName,
			SuppliedEnvVars:  launchableStanza.Env,
			EntryPoints:      entryPoints,
		}
		ret.CgroupConfig.Name = ret.ServiceId
		return ret.If(), nil
	} else if *ExperimentalOpencontainer && launchableStanza.LaunchableType == "opencontainer" {
		ret := &opencontainer.Launchable{
			ID_:             launchableID,
			ServiceID_:      serviceId,
			RunAs:           runAsUser,
			RootDir:         launchableRootDir,
			P2Exec:          pod.P2Exec,
			RestartTimeout:  restartTimeout,
			RestartPolicy_:  launchableStanza.RestartPolicy(),
			CgroupConfig:    launchableStanza.CgroupConfig,
			SuppliedEnvVars: launchableStanza.Env,
		}
		ret.CgroupConfig.Name = serviceId
		return ret, nil
	} else {
		err := fmt.Errorf("launchable type '%s' is not supported", launchableStanza.LaunchableType)
		pod.logLaunchableError(launchableID.String(), err, "Unknown launchable type")
		return nil, err
	}
}