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

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

42 lines
1010 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
2024-05-22 11:11:48 -07:00
package cache
2023-06-11 20:40:47 -04:00
import (
"context"
"errors"
"fmt"
2023-06-11 20:40:47 -04:00
"path/filepath"
"syscall"
"github.com/hashicorp/boundary/internal/util"
)
2024-05-22 11:11:48 -07:00
// stop will send a term signal to the cache to shut down.
2024-01-04 12:51:21 -08:00
func (c *StopCommand) stop(ctx context.Context) error {
2023-06-11 20:40:47 -04:00
switch {
case util.IsNil(ctx):
return errors.New("Invalid parameter provided to stop: context is missing")
2023-06-11 20:40:47 -04:00
}
dotPath, err := DefaultDotDirectory(ctx)
if err != nil {
return fmt.Errorf("Error when getting default dot directory: %w", err)
2023-06-11 20:40:47 -04:00
}
pidPath := filepath.Join(dotPath, pidFileName)
p, err := pidFileInUse(ctx, pidPath)
if err != nil {
2024-05-22 11:11:48 -07:00
return fmt.Errorf("Error when checking if the cache's pid file is in use: %w", err)
2023-06-11 20:40:47 -04:00
}
if p == nil {
2024-05-22 11:11:48 -07:00
return errors.New("The cache is not running.")
2023-06-11 20:40:47 -04:00
}
if err := p.Signal(syscall.SIGTERM); err != nil {
2024-05-22 11:11:48 -07:00
return fmt.Errorf("Error when sending sigterm to cache process: %w", err)
2023-06-11 20:40:47 -04:00
}
return nil
}