@@ -429,6 +429,69 @@ polls, in the logs files, for all members or the selected role by using the -r f
429429 },
430430}
431431
432+ // shutdownMemberCmd represents the shutdown member command
433+ var shutdownMemberCmd = & cobra.Command {
434+ Use : "member node-id" ,
435+ Short : "Shutdown a members services" ,
436+ Long : `The 'shutdown member' command shuts down all the clustered services that are
437+ running on a specific member via a controlled shutdown. A new member will be started in its place.` ,
438+ Args : func (cmd * cobra.Command , args []string ) error {
439+ if len (args ) != 1 {
440+ displayErrorAndExit (cmd , "you must provide a node id" )
441+ }
442+ return nil
443+ },
444+ RunE : func (cmd * cobra.Command , args []string ) error {
445+ var (
446+ dataFetcher fetcher.Fetcher
447+ connection string
448+ err error
449+ response string
450+ nodeIDArray []string
451+ nodeID = args [0 ]
452+ )
453+
454+ // retrieve the current context or the value from "-c"
455+ connection , dataFetcher , err = GetConnectionAndDataFetcher ()
456+ if err != nil {
457+ return err
458+ }
459+
460+ cmd .Println (FormatCurrentCluster (connection ))
461+
462+ nodeIDArray , err = GetNodeIds (dataFetcher )
463+ if err != nil {
464+ return err
465+ }
466+
467+ if ! utils .IsValidInt (nodeID ) {
468+ return fmt .Errorf ("invalid value for node id of %s" , nodeID )
469+ }
470+
471+ if ! utils .SliceContains (nodeIDArray , nodeID ) {
472+ return fmt .Errorf ("no node with node id %s exists in this cluster" , nodeID )
473+ }
474+
475+ // confirmation
476+ if ! automaticallyConfirm {
477+ cmd .Printf ("Are you sure you want to shutdown member %s? (y/n) " , nodeID )
478+ _ , err = fmt .Scanln (& response )
479+ if response != "y" || err != nil {
480+ cmd .Println (constants .NoOperation )
481+ return nil
482+ }
483+ }
484+
485+ _ , err = dataFetcher .ShutdownMember (nodeID )
486+ if err != nil {
487+ return err
488+ }
489+
490+ cmd .Println ("operation completed" )
491+ return nil
492+ },
493+ }
494+
432495// issueClusterCommand issues a variety of cluster commands
433496func issueClusterCommand (cmd * cobra.Command , command string ) error {
434497 var (
@@ -722,4 +785,6 @@ func init() {
722785 configureTracingCmd .Flags ().Float32VarP (& tracingRatio , "tracingRatio" , "t" , 1.0 , "Tracing ratio to set. -1.0 turns off tracing" )
723786 _ = configureTracingCmd .MarkFlagRequired ("tracingRatio" )
724787 configureTracingCmd .Flags ().BoolVarP (& automaticallyConfirm , "yes" , "y" , false , confirmOptionMessage )
788+
789+ shutdownMemberCmd .Flags ().BoolVarP (& automaticallyConfirm , "yes" , "y" , false , confirmOptionMessage )
725790}
0 commit comments