github.com/mhilton/juju-juju@v0.0.0-20150901100907-a94dd2c73455/cmd/juju/commands/removeservice.go (about) 1 // Copyright 2013 Canonical Ltd. 2 // Licensed under the AGPLv3, see LICENCE file for details. 3 4 package commands 5 6 import ( 7 "fmt" 8 9 "github.com/juju/cmd" 10 "github.com/juju/names" 11 12 "github.com/juju/juju/cmd/envcmd" 13 "github.com/juju/juju/cmd/juju/block" 14 ) 15 16 // RemoveServiceCommand causes an existing service to be destroyed. 17 type RemoveServiceCommand struct { 18 envcmd.EnvCommandBase 19 ServiceName string 20 } 21 22 const removeServiceDoc = ` 23 Removing a service will remove all its units and relations. 24 25 If this is the only service running, the machine on which 26 the service is hosted will also be destroyed, if possible. 27 The machine will be destroyed if: 28 - it is not a state server 29 - it is not hosting any Juju managed containers 30 ` 31 32 func (c *RemoveServiceCommand) Info() *cmd.Info { 33 return &cmd.Info{ 34 Name: "remove-service", 35 Args: "<service>", 36 Purpose: "remove a service from the environment", 37 Doc: removeServiceDoc, 38 Aliases: []string{"destroy-service"}, 39 } 40 } 41 42 func (c *RemoveServiceCommand) Init(args []string) error { 43 if len(args) == 0 { 44 return fmt.Errorf("no service specified") 45 } 46 if !names.IsValidService(args[0]) { 47 return fmt.Errorf("invalid service name %q", args[0]) 48 } 49 c.ServiceName, args = args[0], args[1:] 50 return cmd.CheckEmpty(args) 51 } 52 53 func (c *RemoveServiceCommand) Run(_ *cmd.Context) error { 54 client, err := c.NewAPIClient() 55 if err != nil { 56 return err 57 } 58 defer client.Close() 59 return block.ProcessBlockedError(client.ServiceDestroy(c.ServiceName), block.BlockRemove) 60 }