Files
threshold/internal/clientcache/cmd/daemon/stop_nonwindows.go
T

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

42 lines
1017 B
Go
Raw Normal View History

2023-06-11 20:40:47 -04:00
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: BUSL-1.1
//go:build !windows
// +build !windows
package daemon
import (
"context"
"path/filepath"
"syscall"
"github.com/hashicorp/boundary/internal/errors"
"github.com/hashicorp/boundary/internal/util"
)
// stop will send a term signal to the daemon to shut down.
func (s *StopCommand) stop(ctx context.Context) error {
const op = "daemon.(StopCommand).stop"
switch {
case util.IsNil(ctx):
return errors.New(ctx, errors.InvalidParameter, op, "context is missing")
}
dotPath, err := DefaultDotDirectory(ctx)
if err != nil {
return errors.Wrap(ctx, err, op)
}
pidPath := filepath.Join(dotPath, pidFileName)
p, err := pidFileInUse(ctx, pidPath)
if err != nil {
return errors.Wrap(ctx, err, op)
}
if p == nil {
return errors.New(ctx, errors.NotFound, op, "daemon not running")
}
if err := p.Signal(syscall.SIGTERM); err != nil {
return errors.Wrap(ctx, err, op, errors.WithMsg("sending sigterm to process"))
}
return nil
}