mirror of
https://github.com/gravitl/netmaker.git
synced 2024-09-20 15:26:04 +08:00
revert to old way for windows
This commit is contained in:
parent
7e2e89e029
commit
fcedf7b60f
|
@ -33,6 +33,9 @@ func InstallDaemon() error {
|
|||
|
||||
// Restart - restarts a system daemon
|
||||
func Restart() error {
|
||||
if ncutils.IsWindows() {
|
||||
RestartWindowsDaemon()
|
||||
}
|
||||
pid, err := ncutils.ReadPID()
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to find pid %w", err)
|
||||
|
|
|
@ -8,16 +8,22 @@ import (
|
|||
|
||||
// PIDFILE - path/name of pid file
|
||||
const PIDFILE = "/var/run/netclient.pid"
|
||||
const WIN_PIDFILE = "C:\\Windows\\Temp\\netclient.pid"
|
||||
|
||||
// WindowsPIDError - error returned from pid function on windows
|
||||
type WindowsPIDError struct{}
|
||||
|
||||
// Error generates error for windows os
|
||||
func (*WindowsPIDError) Error() string {
|
||||
return "pid tracking not supported on windows"
|
||||
}
|
||||
|
||||
// SavePID - saves the pid of running program to disk
|
||||
func SavePID() error {
|
||||
pidfile := PIDFILE
|
||||
if IsWindows() {
|
||||
pidfile = WIN_PIDFILE
|
||||
return &WindowsPIDError{}
|
||||
}
|
||||
pid := os.Getpid()
|
||||
if err := os.WriteFile(pidfile, []byte(fmt.Sprintf("%d", pid)), 0644); err != nil {
|
||||
if err := os.WriteFile(PIDFILE, []byte(fmt.Sprintf("%d", pid)), 0644); err != nil {
|
||||
return fmt.Errorf("could not write to pid file %w", err)
|
||||
}
|
||||
return nil
|
||||
|
@ -25,11 +31,10 @@ func SavePID() error {
|
|||
|
||||
// ReadPID - reads a previously saved pid from disk
|
||||
func ReadPID() (int, error) {
|
||||
pidfile := PIDFILE
|
||||
if IsWindows() {
|
||||
pidfile = WIN_PIDFILE
|
||||
return 0, &WindowsPIDError{}
|
||||
}
|
||||
bytes, err := os.ReadFile(pidfile)
|
||||
bytes, err := os.ReadFile(PIDFILE)
|
||||
if err != nil {
|
||||
return 0, fmt.Errorf("could not read pid file %w", err)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue