github.com/coreos/rocket@v1.30.1-0.20200224141603-171c416fac02/stage0/stop.go (about)

     1  // Copyright 2016 The rkt Authors
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //     http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  //+build linux
    16  
    17  package stage0
    18  
    19  import (
    20  	"fmt"
    21  	"os"
    22  	"os/exec"
    23  	"path/filepath"
    24  
    25  	"github.com/rkt/rkt/common"
    26  
    27  	"github.com/appc/spec/schema/types"
    28  )
    29  
    30  // StopPod stops the given pod.
    31  func StopPod(dir string, force bool, uuid *types.UUID) error {
    32  	s1rootfs := common.Stage1RootfsPath(dir)
    33  
    34  	if err := os.Chdir(dir); err != nil {
    35  		return fmt.Errorf("failed changing to dir: %v", err)
    36  	}
    37  
    38  	ep, err := getStage1Entrypoint(dir, stopEntrypoint)
    39  	if err != nil {
    40  		return fmt.Errorf("rkt stop not implemented for pod's stage1: %v", err)
    41  	}
    42  	args := []string{filepath.Join(s1rootfs, ep)}
    43  	debug("Execing %s", ep)
    44  
    45  	if force {
    46  		args = append(args, "--force")
    47  	}
    48  
    49  	args = append(args, uuid.String())
    50  
    51  	c := exec.Cmd{
    52  		Path:   args[0],
    53  		Args:   args,
    54  		Stdout: os.Stdout,
    55  		Stderr: os.Stderr,
    56  	}
    57  
    58  	return c.Run()
    59  }