github.com/apptainer/singularity@v3.1.1+incompatible/cmd/internal/cli/instance_stop_linux.go (about)

     1  // Copyright (c) 2018-2019, Sylabs Inc. All rights reserved.
     2  // This software is licensed under a 3-clause BSD license. Please consult the
     3  // LICENSE.md file distributed with the sources of this project regarding your
     4  // rights to use or distribute this software.
     5  
     6  package cli
     7  
     8  import (
     9  	"errors"
    10  
    11  	"github.com/spf13/cobra"
    12  	"github.com/sylabs/singularity/docs"
    13  )
    14  
    15  func init() {
    16  	InstanceStopCmd.Flags().SetInterspersed(false)
    17  
    18  	// -u|--user
    19  	InstanceStopCmd.Flags().StringVarP(&username, "user", "u", "", `if running as root, list instances from "<username>"`)
    20  	InstanceStopCmd.Flags().SetAnnotation("user", "argtag", []string{"<username>"})
    21  	InstanceStopCmd.Flags().SetAnnotation("user", "envkey", []string{"USER"})
    22  
    23  	// -a|--all
    24  	InstanceStopCmd.Flags().BoolVarP(&stopAll, "all", "a", false, "stop all user's instances")
    25  	InstanceStopCmd.Flags().SetAnnotation("all", "envkey", []string{"ALL"})
    26  
    27  	// -f|--force
    28  	InstanceStopCmd.Flags().BoolVarP(&forceStop, "force", "F", false, "force kill instance")
    29  	InstanceStopCmd.Flags().SetAnnotation("force", "envkey", []string{"FORCE"})
    30  
    31  	// -s|--signal
    32  	InstanceStopCmd.Flags().StringVarP(&stopSignal, "signal", "s", "", "signal sent to the instance")
    33  	InstanceStopCmd.Flags().SetAnnotation("signal", "argtag", []string{"<signal>"})
    34  	InstanceStopCmd.Flags().SetAnnotation("signal", "envkey", []string{"SIGNAL"})
    35  
    36  	// -t|--timeout
    37  	InstanceStopCmd.Flags().IntVarP(&stopTimeout, "timeout", "t", 10, "force kill non stopped instances after X seconds")
    38  }
    39  
    40  // InstanceStopCmd singularity instance stop
    41  var InstanceStopCmd = &cobra.Command{
    42  	DisableFlagsInUseLine: true,
    43  	RunE: func(cmd *cobra.Command, args []string) error {
    44  		if len(args) > 0 && !stopAll {
    45  			stopInstance(args[0])
    46  			return nil
    47  		} else if stopAll {
    48  			stopInstance("*")
    49  			return nil
    50  		} else {
    51  			return errors.New("Invalid command")
    52  		}
    53  	},
    54  
    55  	Use:     docs.InstanceStopUse,
    56  	Short:   docs.InstanceStopShort,
    57  	Long:    docs.InstanceStopLong,
    58  	Example: docs.InstanceStopExample,
    59  }