mirror of
https://github.com/siderolabs/talos.git
synced 2025-08-21 14:41:12 +02:00
This change is only moving packages and updating import paths. Goal: expose `internal/pkg/provision` as `pkg/provision` to enable other projects to import Talos provisioning library. As cluster checks are almost always required as part of provisioning process, package `internal/pkg/cluster` was also made public as `pkg/cluster`. Other changes were direct dependencies discovered by `importvet` which were updated. Public packages (useful, general purpose packages with stable API): * `internal/pkg/conditions` -> `pkg/conditions` * `internal/pkg/tail` -> `pkg/tail` Private packages (used only on provisioning library internally): * `internal/pkg/inmemhttp` -> `pkg/provision/internal/inmemhttp` * `internal/pkg/kernel/vmlinuz` -> `pkg/provision/internal/vmlinuz` * `internal/pkg/cniutils` -> `pkg/provision/internal/cniutils` Signed-off-by: Andrey Smirnov <smirnov.andrey@gmail.com>
55 lines
1.2 KiB
Go
55 lines
1.2 KiB
Go
// This Source Code Form is subject to the terms of the Mozilla Public
|
|
// License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
package vm
|
|
|
|
import (
|
|
"errors"
|
|
"fmt"
|
|
"os"
|
|
"syscall"
|
|
)
|
|
|
|
func stopProcessByPidfile(pidPath string) error {
|
|
pidFile, err := os.Open(pidPath)
|
|
if err != nil {
|
|
if os.IsNotExist(err) {
|
|
return nil
|
|
}
|
|
|
|
return fmt.Errorf("error checking PID file %q: %w", pidPath, err)
|
|
}
|
|
|
|
defer pidFile.Close() //nolint: errcheck
|
|
|
|
var pid int
|
|
|
|
if _, err = fmt.Fscanf(pidFile, "%d", &pid); err != nil {
|
|
return fmt.Errorf("error reading PID for %q: %w", pidPath, err)
|
|
}
|
|
|
|
proc, err := os.FindProcess(pid)
|
|
if err != nil {
|
|
return fmt.Errorf("error finding process %d for %q: %w", pid, pidPath, err)
|
|
}
|
|
|
|
if err = proc.Signal(syscall.SIGTERM); err != nil {
|
|
if err.Error() == "os: process already finished" {
|
|
return nil
|
|
}
|
|
|
|
return fmt.Errorf("error sending SIGTERM to %d (path %q): %w", pid, pidPath, err)
|
|
}
|
|
|
|
if _, err = proc.Wait(); err != nil {
|
|
if errors.Is(err, syscall.ECHILD) {
|
|
return nil
|
|
}
|
|
|
|
return fmt.Errorf("error waiting for %d to exit (path %q): %w", pid, pidPath, err)
|
|
}
|
|
|
|
return nil
|
|
}
|