mirror of
https://github.com/gravitl/netmaker.git
synced 2025-11-11 01:01:05 +08:00
GRA-408: check if netclient daemon exists to start client daemon service
This commit is contained in:
parent
c537722b76
commit
c772d15080
3 changed files with 28 additions and 2 deletions
|
|
@ -13,6 +13,11 @@ import (
|
||||||
|
|
||||||
// InstallDaemon - Calls the correct function to install the netclient as a daemon service on the given operating system.
|
// InstallDaemon - Calls the correct function to install the netclient as a daemon service on the given operating system.
|
||||||
func InstallDaemon() error {
|
func InstallDaemon() error {
|
||||||
|
|
||||||
|
if ncutils.CheckIfDaemonExists() {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
os := runtime.GOOS
|
os := runtime.GOOS
|
||||||
var err error
|
var err error
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -205,7 +205,7 @@ func JoinNetwork(cfg *config.ClientConfig, privateKey string) error {
|
||||||
logger.Log(0, "network:", cfg.Network, "failed to publish update for join", err.Error())
|
logger.Log(0, "network:", cfg.Network, "failed to publish update for join", err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
if cfg.Daemon == "install" || ncutils.IsFreeBSD() {
|
if cfg.Daemon == "on" || ncutils.IsFreeBSD() {
|
||||||
err = daemon.InstallDaemon()
|
err = daemon.InstallDaemon()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|
|
||||||
|
|
@ -17,6 +17,7 @@ import (
|
||||||
"runtime"
|
"runtime"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
"syscall"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/c-robinson/iplib"
|
"github.com/c-robinson/iplib"
|
||||||
|
|
@ -89,7 +90,7 @@ func IsLinux() bool {
|
||||||
return runtime.GOOS == "linux"
|
return runtime.GOOS == "linux"
|
||||||
}
|
}
|
||||||
|
|
||||||
// IsLinux - checks if is linux
|
// IsFreeBSD - checks if is freebsd
|
||||||
func IsFreeBSD() bool {
|
func IsFreeBSD() bool {
|
||||||
return runtime.GOOS == "freebsd"
|
return runtime.GOOS == "freebsd"
|
||||||
}
|
}
|
||||||
|
|
@ -592,3 +593,23 @@ func ModPort(node *models.Node) error {
|
||||||
}
|
}
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func CheckIfDaemonExists() bool {
|
||||||
|
daemonExists := false
|
||||||
|
pid, err := ReadPID()
|
||||||
|
if err != nil {
|
||||||
|
logger.Log(1, "failed to get netclient PID: ", err.Error())
|
||||||
|
return daemonExists
|
||||||
|
}
|
||||||
|
process, err := os.FindProcess(pid)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Printf("Failed to find process: %s\n", err)
|
||||||
|
return daemonExists
|
||||||
|
}
|
||||||
|
err = process.Signal(syscall.Signal(0))
|
||||||
|
if err == nil {
|
||||||
|
daemonExists = true
|
||||||
|
}
|
||||||
|
|
||||||
|
return daemonExists
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue