github.com/hugh712/snapd@v0.0.0-20200910133618-1a99902bd583/overlord/hookstate/ctlcmd/stop.go (about)

     1  // -*- Mode: Go; indent-tabs-mode: t -*-
     2  
     3  /*
     4   * Copyright (C) 2016-2017 Canonical Ltd
     5   *
     6   * This program is free software: you can redistribute it and/or modify
     7   * it under the terms of the GNU General Public License version 3 as
     8   * published by the Free Software Foundation.
     9   *
    10   * This program is distributed in the hope that it will be useful,
    11   * but WITHOUT ANY WARRANTY; without even the implied warranty of
    12   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    13   * GNU General Public License for more details.
    14   *
    15   * You should have received a copy of the GNU General Public License
    16   * along with this program.  If not, see <http://www.gnu.org/licenses/>.
    17   *
    18   */
    19  
    20  package ctlcmd
    21  
    22  import (
    23  	"github.com/snapcore/snapd/client"
    24  	"github.com/snapcore/snapd/i18n"
    25  	"github.com/snapcore/snapd/overlord/servicestate"
    26  )
    27  
    28  type stopCommand struct {
    29  	baseCommand
    30  	Positional struct {
    31  		ServiceNames []string `positional-arg-name:"<service>" required:"yes"`
    32  	} `positional-args:"yes" required:"yes"`
    33  	Disable bool `long:"disable" description:"Disable the specified services (see man systemctl for details)"`
    34  }
    35  
    36  var (
    37  	shortStopHelp = i18n.G("Stop services")
    38  	longStopHelp  = i18n.G(`
    39  The stop command stops the given services of the snap. If executed from the
    40  "configure" hook, the services will be stopped after the hook finishes.`)
    41  )
    42  
    43  func init() {
    44  	addCommand("stop", shortStopHelp, longStopHelp, func() command { return &stopCommand{} })
    45  }
    46  
    47  func (c *stopCommand) Execute(args []string) error {
    48  	inst := servicestate.Instruction{
    49  		Action: "stop",
    50  		Names:  c.Positional.ServiceNames,
    51  		StopOptions: client.StopOptions{
    52  			Disable: c.Disable,
    53  		},
    54  	}
    55  	return runServiceCommand(c.context(), &inst, c.Positional.ServiceNames)
    56  }