1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
|
// Copyright (c) 2018-2023, Sylabs Inc. All rights reserved.
// This software is licensed under a 3-clause BSD license. Please consult the
// LICENSE.md file distributed with the sources of this project regarding your
// rights to use or distribute this software.
package cli
import (
"github.com/spf13/cobra"
"github.com/sylabs/singularity/v4/docs"
"github.com/sylabs/singularity/v4/internal/app/singularity"
"github.com/sylabs/singularity/v4/internal/pkg/runtime/launcher"
"github.com/sylabs/singularity/v4/pkg/cmdline"
"github.com/sylabs/singularity/v4/pkg/sylog"
)
func init() {
addCmdInit(func(cmdManager *cmdline.CommandManager) {
cmdManager.RegisterFlagForCmd(&instanceStartPidFileFlag, instanceStartCmd)
})
}
// --pid-file
var instanceStartPidFile string
var instanceStartPidFileFlag = cmdline.Flag{
ID: "instanceStartPidFileFlag",
Value: &instanceStartPidFile,
DefaultValue: "",
Name: "pid-file",
Usage: "write instance PID to the file with the given name",
EnvKeys: []string{"PID_FILE"},
}
// singularity instance start
var instanceStartCmd = &cobra.Command{
Args: cobra.MinimumNArgs(2),
PreRun: actionPreRun,
DisableFlagsInUseLine: true,
Run: func(cmd *cobra.Command, args []string) {
if isOCI {
sylog.Fatalf("Instances are not yet supported in OCI-mode. Omit --oci, or use --no-oci, to start a non-OCI Singularity container.")
}
ep := launcher.ExecParams{
Image: args[0],
Action: "start",
Instance: args[1],
Args: args[2:],
}
if err := launchContainer(cmd, ep); err != nil {
sylog.Fatalf("%s", err)
}
if instanceStartPidFile != "" {
err := singularity.WriteInstancePidFile(ep.Instance, instanceStartPidFile)
if err != nil {
sylog.Warningf("Failed to write pid file: %v", err)
}
}
},
Use: docs.InstanceStartUse,
Short: docs.InstanceStartShort,
Long: docs.InstanceStartLong,
Example: docs.InstanceStartExample,
}
|