mirror of
https://github.com/gravitl/netmaker.git
synced 2024-11-11 18:32:08 +08:00
72 lines
1.4 KiB
Go
72 lines
1.4 KiB
Go
package daemon
|
|
|
|
import (
|
|
"errors"
|
|
"runtime"
|
|
"time"
|
|
|
|
"github.com/gravitl/netmaker/netclient/config"
|
|
)
|
|
|
|
// InstallDaemon - Calls the correct function to install the netclient as a daemon service on the given operating system.
|
|
func InstallDaemon(cfg config.ClientConfig) error {
|
|
os := runtime.GOOS
|
|
var err error
|
|
|
|
interval := "15"
|
|
if cfg.Server.CheckinInterval != "" {
|
|
interval = cfg.Server.CheckinInterval
|
|
}
|
|
|
|
switch os {
|
|
case "windows":
|
|
err = SetupWindowsDaemon()
|
|
case "darwin":
|
|
err = SetupMacDaemon(interval)
|
|
case "linux":
|
|
err = SetupSystemDDaemon(interval)
|
|
default:
|
|
err = errors.New("this os is not yet supported for daemon mode. Run join cmd with flag '--daemon off'")
|
|
}
|
|
return err
|
|
}
|
|
|
|
// Restart - restarts a system daemon
|
|
func Restart() error {
|
|
os := runtime.GOOS
|
|
var err error
|
|
|
|
time.Sleep(time.Second)
|
|
|
|
switch os {
|
|
case "windows":
|
|
RestartWindowsDaemon()
|
|
case "darwin":
|
|
RestartLaunchD()
|
|
case "linux":
|
|
RestartSystemD()
|
|
default:
|
|
err = errors.New("this os is not yet supported for daemon mode. Run join cmd with flag '--daemon off'")
|
|
}
|
|
return err
|
|
}
|
|
|
|
// Stop - stops a system daemon
|
|
func Stop() error {
|
|
os := runtime.GOOS
|
|
var err error
|
|
|
|
time.Sleep(time.Second)
|
|
|
|
switch os {
|
|
case "windows":
|
|
StopWindowsDaemon()
|
|
case "darwin":
|
|
StopLaunchD()
|
|
case "linux":
|
|
StopSystemD()
|
|
default:
|
|
err = errors.New("no OS daemon to stop")
|
|
}
|
|
return err
|
|
}
|