netmaker/netclient/daemon/common.go

74 lines
1.4 KiB
Go
Raw Normal View History

2021-09-20 02:03:47 +08:00
package daemon
import (
"errors"
"runtime"
2022-02-02 13:02:36 +08:00
"time"
2021-09-20 02:03:47 +08:00
"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 {
2021-09-20 02:03:47 +08:00
os := runtime.GOOS
var err error
2021-09-20 02:03:47 +08:00
switch os {
case "windows":
err = SetupWindowsDaemon()
case "darwin":
2022-02-19 04:18:50 +08:00
err = SetupMacDaemon()
2021-09-20 02:03:47 +08:00
case "linux":
2022-02-19 04:18:50 +08:00
err = SetupSystemDDaemon()
2022-02-09 11:06:41 +08:00
case "freebsd":
err = SetupFreebsdDaemon()
2021-09-20 02:03:47 +08:00
default:
err = errors.New("this os is not yet supported for daemon mode. Run join cmd with flag '--daemon off'")
}
return err
}
2022-02-02 13:02:36 +08:00
// Restart - restarts a system daemon
2022-02-02 13:02:36 +08:00
func Restart() error {
os := runtime.GOOS
var err error
time.Sleep(time.Second)
switch os {
case "windows":
RestartWindowsDaemon()
case "darwin":
RestartLaunchD()
case "linux":
RestartSystemD()
2022-02-09 11:06:41 +08:00
case "freebsd":
FreebsdDaemon("restart")
2022-02-02 13:02:36 +08:00
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":
2022-05-16 08:26:38 +08:00
RunWinSWCMD("stop")
case "darwin":
StopLaunchD()
case "linux":
StopSystemD()
2022-02-09 11:06:41 +08:00
case "freebsd":
FreebsdDaemon("stop")
default:
err = errors.New("no OS daemon to stop")
}
return err
}