mirror of
https://github.com/gravitl/netmaker.git
synced 2025-10-26 05:56:36 +08:00
Merge pull request #308 from gravitl/hotfix_v0.8.1_netclient
IsServer can be set, Checkin is configurable, Moved Config Files
This commit is contained in:
commit
fa2d6cfbde
18 changed files with 121 additions and 74 deletions
|
|
@ -56,6 +56,7 @@ type ServerConfig struct {
|
||||||
SQLConn string `yaml:"sqlconn"`
|
SQLConn string `yaml:"sqlconn"`
|
||||||
Platform string `yaml:"platform"`
|
Platform string `yaml:"platform"`
|
||||||
Database string `yaml:database`
|
Database string `yaml:database`
|
||||||
|
CheckinInterval string `yaml:checkininterval`
|
||||||
DefaultNodeLimit int32 `yaml:"defaultnodelimit"`
|
DefaultNodeLimit int32 `yaml:"defaultnodelimit"`
|
||||||
Verbosity int32 `yaml:"verbosity"`
|
Verbosity int32 `yaml:"verbosity"`
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -249,9 +249,7 @@ func CreateNode(node models.Node, networkName string) (models.Node, error) {
|
||||||
|
|
||||||
node.Network = networkName
|
node.Network = networkName
|
||||||
if node.Name == models.NODE_SERVER_NAME {
|
if node.Name == models.NODE_SERVER_NAME {
|
||||||
if node.CheckIsServer() {
|
node.IsServer = "yes"
|
||||||
node.IsServer = "yes"
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if servercfg.IsDNSMode() && node.DNSOn == ""{
|
if servercfg.IsDNSMode() && node.DNSOn == ""{
|
||||||
node.DNSOn = "yes"
|
node.DNSOn = "yes"
|
||||||
|
|
|
||||||
|
|
@ -473,6 +473,7 @@ func CreateAccessKey(accesskey models.AccessKey, network models.Network) (models
|
||||||
GRPCHost: s.GRPCHost,
|
GRPCHost: s.GRPCHost,
|
||||||
GRPCPort: s.GRPCPort,
|
GRPCPort: s.GRPCPort,
|
||||||
GRPCSSL: s.GRPCSSL,
|
GRPCSSL: s.GRPCSSL,
|
||||||
|
CheckinInterval: s.CheckinInterval,
|
||||||
}
|
}
|
||||||
accessToken.ServerConfig = servervals
|
accessToken.ServerConfig = servervals
|
||||||
accessToken.ClientConfig.Network = netID
|
accessToken.ClientConfig.Network = netID
|
||||||
|
|
|
||||||
|
|
@ -106,6 +106,7 @@ func CreateServerToken(netID string) (string, error) {
|
||||||
APIConnString: "127.0.0.1:" + servercfg.GetAPIPort(),
|
APIConnString: "127.0.0.1:" + servercfg.GetAPIPort(),
|
||||||
GRPCConnString: "127.0.0.1:" + servercfg.GetGRPCPort(),
|
GRPCConnString: "127.0.0.1:" + servercfg.GetGRPCPort(),
|
||||||
GRPCSSL: "off",
|
GRPCSSL: "off",
|
||||||
|
CheckinInterval: servercfg.GetCheckinInterval(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
log.Println("APIConnString:", servervals.APIConnString)
|
log.Println("APIConnString:", servervals.APIConnString)
|
||||||
|
|
|
||||||
|
|
@ -21,6 +21,7 @@ type ServerConfig struct {
|
||||||
GRPCHost string `json:"grpchost"`
|
GRPCHost string `json:"grpchost"`
|
||||||
GRPCPort string `json:"grpcport"`
|
GRPCPort string `json:"grpcport"`
|
||||||
GRPCSSL string `json:"grpcssl"`
|
GRPCSSL string `json:"grpcssl"`
|
||||||
|
CheckinInterval string `json:"checkininterval"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type WG struct {
|
type WG struct {
|
||||||
|
|
|
||||||
|
|
@ -37,6 +37,8 @@ type Network struct {
|
||||||
IsIPv6 string `json:"isipv6" bson:"isipv6" validate:"checkyesorno"`
|
IsIPv6 string `json:"isipv6" bson:"isipv6" validate:"checkyesorno"`
|
||||||
IsGRPCHub string `json:"isgrpchub" bson:"isgrpchub" validate:"checkyesorno"`
|
IsGRPCHub string `json:"isgrpchub" bson:"isgrpchub" validate:"checkyesorno"`
|
||||||
LocalRange string `json:"localrange" bson:"localrange" validate:"omitempty,cidr"`
|
LocalRange string `json:"localrange" bson:"localrange" validate:"omitempty,cidr"`
|
||||||
|
|
||||||
|
// checkin interval is depreciated at the network level. Set on server with CHECKIN_INTERVAL
|
||||||
DefaultCheckInInterval int32 `json:"checkininterval,omitempty" bson:"checkininterval,omitempty" validate:"omitempty,numeric,min=2,max=100000"`
|
DefaultCheckInInterval int32 `json:"checkininterval,omitempty" bson:"checkininterval,omitempty" validate:"omitempty,numeric,min=2,max=100000"`
|
||||||
DefaultUDPHolePunch string `json:"defaultudpholepunch" bson:"defaultudpholepunch" validate:"checkyesorno"`
|
DefaultUDPHolePunch string `json:"defaultudpholepunch" bson:"defaultudpholepunch" validate:"checkyesorno"`
|
||||||
DefaultExtClientDNS string `json:"defaultextclientdns" bson:"defaultextclientdns"`
|
DefaultExtClientDNS string `json:"defaultextclientdns" bson:"defaultextclientdns"`
|
||||||
|
|
|
||||||
|
|
@ -49,6 +49,7 @@ type Node struct {
|
||||||
LastPeerUpdate int64 `json:"lastpeerupdate" bson:"lastpeerupdate" yaml:"lastpeerupdate"`
|
LastPeerUpdate int64 `json:"lastpeerupdate" bson:"lastpeerupdate" yaml:"lastpeerupdate"`
|
||||||
LastCheckIn int64 `json:"lastcheckin" bson:"lastcheckin" yaml:"lastcheckin"`
|
LastCheckIn int64 `json:"lastcheckin" bson:"lastcheckin" yaml:"lastcheckin"`
|
||||||
MacAddress string `json:"macaddress" bson:"macaddress" yaml:"macaddress" validate:"required,mac,macaddress_unique"`
|
MacAddress string `json:"macaddress" bson:"macaddress" yaml:"macaddress" validate:"required,mac,macaddress_unique"`
|
||||||
|
// checkin interval is depreciated at the network level. Set on server with CHECKIN_INTERVAL
|
||||||
CheckInInterval int32 `json:"checkininterval" bson:"checkininterval" yaml:"checkininterval"`
|
CheckInInterval int32 `json:"checkininterval" bson:"checkininterval" yaml:"checkininterval"`
|
||||||
Password string `json:"password" bson:"password" yaml:"password" validate:"required,min=6"`
|
Password string `json:"password" bson:"password" yaml:"password" validate:"required,min=6"`
|
||||||
Network string `json:"network" bson:"network" yaml:"network" validate:"network_exists"`
|
Network string `json:"network" bson:"network" yaml:"network" validate:"network_exists"`
|
||||||
|
|
@ -414,7 +415,9 @@ func (newNode *Node) Fill(currentNode *Node) {
|
||||||
if newNode.Action == "" {
|
if newNode.Action == "" {
|
||||||
newNode.Action = currentNode.Action
|
newNode.Action = currentNode.Action
|
||||||
}
|
}
|
||||||
newNode.IsServer = currentNode.IsServer
|
if newNode.IsServer == "" {
|
||||||
|
newNode.IsServer = currentNode.IsServer
|
||||||
|
}
|
||||||
if newNode.IsServer == "yes" {
|
if newNode.IsServer == "yes" {
|
||||||
newNode.IsStatic = "yes"
|
newNode.IsStatic = "yes"
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@ import (
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
"strconv"
|
||||||
nodepb "github.com/gravitl/netmaker/grpc"
|
nodepb "github.com/gravitl/netmaker/grpc"
|
||||||
"github.com/gravitl/netmaker/netclient/config"
|
"github.com/gravitl/netmaker/netclient/config"
|
||||||
"github.com/gravitl/netmaker/netclient/daemon"
|
"github.com/gravitl/netmaker/netclient/daemon"
|
||||||
|
|
@ -56,15 +56,35 @@ func Join(cfg config.ClientConfig, privateKey string) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func getWindowsInterval() int {
|
||||||
|
interval := 15
|
||||||
|
networks, err := functions.GetNetworks()
|
||||||
|
if err != nil {
|
||||||
|
return interval
|
||||||
|
}
|
||||||
|
cfg, err := config.ReadConfig(networks[0])
|
||||||
|
if err != nil {
|
||||||
|
return interval
|
||||||
|
}
|
||||||
|
netint, err := strconv.Atoi(cfg.Server.CheckinInterval)
|
||||||
|
if err == nil && netint != 0 {
|
||||||
|
interval = netint
|
||||||
|
}
|
||||||
|
return interval
|
||||||
|
}
|
||||||
|
|
||||||
func RunUserspaceDaemon() {
|
func RunUserspaceDaemon() {
|
||||||
|
|
||||||
cfg := config.ClientConfig{
|
cfg := config.ClientConfig{
|
||||||
Network: "all",
|
Network: "all",
|
||||||
}
|
}
|
||||||
|
interval := getWindowsInterval()
|
||||||
|
dur := time.Duration(interval) * time.Second
|
||||||
for {
|
for {
|
||||||
if err := CheckIn(cfg); err != nil {
|
if err := CheckIn(cfg); err != nil {
|
||||||
// pass
|
// pass
|
||||||
}
|
}
|
||||||
time.Sleep(15 * time.Second)
|
time.Sleep(dur)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -35,6 +35,7 @@ type ServerConfig struct {
|
||||||
AccessKey string `yaml:"accesskey"`
|
AccessKey string `yaml:"accesskey"`
|
||||||
GRPCSSL string `yaml:"grpcssl"`
|
GRPCSSL string `yaml:"grpcssl"`
|
||||||
GRPCWireGuard string `yaml:"grpcwg"`
|
GRPCWireGuard string `yaml:"grpcwg"`
|
||||||
|
CheckinInterval string `yaml:"checkininterval"`
|
||||||
}
|
}
|
||||||
|
|
||||||
//reading in the env file
|
//reading in the env file
|
||||||
|
|
@ -43,9 +44,9 @@ func Write(config *ClientConfig, network string) error {
|
||||||
err := errors.New("no network provided - exiting")
|
err := errors.New("no network provided - exiting")
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
_, err := os.Stat(ncutils.GetNetclientPath())
|
_, err := os.Stat(ncutils.GetNetclientPath()+"/config")
|
||||||
if os.IsNotExist(err) {
|
if os.IsNotExist(err) {
|
||||||
os.Mkdir(ncutils.GetNetclientPath(), 0744)
|
os.MkdirAll(ncutils.GetNetclientPath()+"/config", 0744)
|
||||||
} else if err != nil {
|
} else if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
@ -72,9 +73,9 @@ func WriteServer(server string, accesskey string, network string) error {
|
||||||
}
|
}
|
||||||
nofile := false
|
nofile := false
|
||||||
//home, err := homedir.Dir()
|
//home, err := homedir.Dir()
|
||||||
_, err := os.Stat(ncutils.GetNetclientPath())
|
_, err := os.Stat(ncutils.GetNetclientPath()+"/config")
|
||||||
if os.IsNotExist(err) {
|
if os.IsNotExist(err) {
|
||||||
os.Mkdir(ncutils.GetNetclientPath(), 0744)
|
os.MkdirAll(ncutils.GetNetclientPath()+"/config", 0744)
|
||||||
} else if err != nil {
|
} else if err != nil {
|
||||||
fmt.Println("couldnt find or create", ncutils.GetNetclientPath())
|
fmt.Println("couldnt find or create", ncutils.GetNetclientPath())
|
||||||
return err
|
return err
|
||||||
|
|
@ -230,11 +231,13 @@ func GetCLIConfig(c *cli.Context) (ClientConfig, string, error) {
|
||||||
cfg.Server.GRPCAddress = cfg.Server.GRPCAddress + ":" + accesstoken.ServerConfig.GRPCPort
|
cfg.Server.GRPCAddress = cfg.Server.GRPCAddress + ":" + accesstoken.ServerConfig.GRPCPort
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
cfg.Network = accesstoken.ClientConfig.Network
|
cfg.Network = accesstoken.ClientConfig.Network
|
||||||
cfg.Node.Network = accesstoken.ClientConfig.Network
|
cfg.Node.Network = accesstoken.ClientConfig.Network
|
||||||
cfg.Server.AccessKey = accesstoken.ClientConfig.Key
|
cfg.Server.AccessKey = accesstoken.ClientConfig.Key
|
||||||
cfg.Node.LocalRange = accesstoken.ClientConfig.LocalRange
|
cfg.Node.LocalRange = accesstoken.ClientConfig.LocalRange
|
||||||
cfg.Server.GRPCSSL = accesstoken.ServerConfig.GRPCSSL
|
cfg.Server.GRPCSSL = accesstoken.ServerConfig.GRPCSSL
|
||||||
|
cfg.Server.CheckinInterval = accesstoken.ServerConfig.CheckinInterval
|
||||||
cfg.Server.GRPCWireGuard = accesstoken.WG.GRPCWireGuard
|
cfg.Server.GRPCWireGuard = accesstoken.WG.GRPCWireGuard
|
||||||
cfg.Server.CoreDNSAddr = accesstoken.ServerConfig.CoreDNSAddr
|
cfg.Server.CoreDNSAddr = accesstoken.ServerConfig.CoreDNSAddr
|
||||||
if c.String("grpcserver") != "" {
|
if c.String("grpcserver") != "" {
|
||||||
|
|
@ -262,6 +265,9 @@ func GetCLIConfig(c *cli.Context) (ClientConfig, string, error) {
|
||||||
if c.String("grpcwg") != "" {
|
if c.String("grpcwg") != "" {
|
||||||
cfg.Server.GRPCWireGuard = c.String("grpcwg")
|
cfg.Server.GRPCWireGuard = c.String("grpcwg")
|
||||||
}
|
}
|
||||||
|
if c.String("checkininterval") != "" {
|
||||||
|
cfg.Server.CheckinInterval = c.String("checkininterval")
|
||||||
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
cfg.Server.GRPCAddress = c.String("grpcserver")
|
cfg.Server.GRPCAddress = c.String("grpcserver")
|
||||||
|
|
@ -273,6 +279,7 @@ func GetCLIConfig(c *cli.Context) (ClientConfig, string, error) {
|
||||||
cfg.Server.GRPCWireGuard = c.String("grpcwg")
|
cfg.Server.GRPCWireGuard = c.String("grpcwg")
|
||||||
cfg.Server.GRPCSSL = c.String("grpcssl")
|
cfg.Server.GRPCSSL = c.String("grpcssl")
|
||||||
cfg.Server.CoreDNSAddr = c.String("corednsaddr")
|
cfg.Server.CoreDNSAddr = c.String("corednsaddr")
|
||||||
|
cfg.Server.CheckinInterval = c.String("checkininterval")
|
||||||
}
|
}
|
||||||
cfg.Node.Name = c.String("name")
|
cfg.Node.Name = c.String("name")
|
||||||
cfg.Node.Interface = c.String("interface")
|
cfg.Node.Interface = c.String("interface")
|
||||||
|
|
@ -298,6 +305,10 @@ func GetCLIConfig(c *cli.Context) (ClientConfig, string, error) {
|
||||||
cfg.Node.UDPHolePunch = c.String("udpholepunch")
|
cfg.Node.UDPHolePunch = c.String("udpholepunch")
|
||||||
cfg.Node.MTU = int32(c.Int("mtu"))
|
cfg.Node.MTU = int32(c.Int("mtu"))
|
||||||
|
|
||||||
|
if cfg.Server.CheckinInterval == "" {
|
||||||
|
cfg.Server.CheckinInterval = "15"
|
||||||
|
}
|
||||||
|
|
||||||
return cfg, privateKey, nil
|
return cfg, privateKey, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -10,13 +10,19 @@ import (
|
||||||
func InstallDaemon(cfg config.ClientConfig) error {
|
func InstallDaemon(cfg config.ClientConfig) error {
|
||||||
os := runtime.GOOS
|
os := runtime.GOOS
|
||||||
var err error
|
var err error
|
||||||
|
|
||||||
|
interval := "15"
|
||||||
|
if cfg.Server.CheckinInterval != "" {
|
||||||
|
interval = cfg.Server.CheckinInterval
|
||||||
|
}
|
||||||
|
|
||||||
switch os {
|
switch os {
|
||||||
case "windows":
|
case "windows":
|
||||||
err = SetupWindowsDaemon()
|
err = SetupWindowsDaemon()
|
||||||
case "darwin":
|
case "darwin":
|
||||||
err = SetupMacDaemon()
|
err = SetupMacDaemon(interval)
|
||||||
case "linux":
|
case "linux":
|
||||||
err = SetupSystemDDaemon(cfg.Network)
|
err = SetupSystemDDaemon(interval)
|
||||||
default:
|
default:
|
||||||
err = errors.New("this os is not yet supported for daemon mode. Run join cmd with flag '--daemon off'")
|
err = errors.New("this os is not yet supported for daemon mode. Run join cmd with flag '--daemon off'")
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,13 +4,14 @@ import (
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
|
"fmt"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"github.com/gravitl/netmaker/netclient/ncutils"
|
"github.com/gravitl/netmaker/netclient/ncutils"
|
||||||
)
|
)
|
||||||
|
|
||||||
const MAC_SERVICE_NAME = "com.gravitl.netclient"
|
const MAC_SERVICE_NAME = "com.gravitl.netclient"
|
||||||
|
|
||||||
func SetupMacDaemon() error {
|
func SetupMacDaemon(interval string) error {
|
||||||
|
|
||||||
dir, err := filepath.Abs(filepath.Dir(os.Args[0]))
|
dir, err := filepath.Abs(filepath.Dir(os.Args[0]))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
@ -30,7 +31,7 @@ func SetupMacDaemon() error {
|
||||||
if os.IsNotExist(errN) {
|
if os.IsNotExist(errN) {
|
||||||
os.Mkdir("~/Library/LaunchAgents", 0755)
|
os.Mkdir("~/Library/LaunchAgents", 0755)
|
||||||
}
|
}
|
||||||
err = CreateMacService(MAC_SERVICE_NAME)
|
err = CreateMacService(MAC_SERVICE_NAME, interval)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
@ -50,7 +51,7 @@ func CleanupMac() {
|
||||||
os.RemoveAll(ncutils.GetNetclientPath())
|
os.RemoveAll(ncutils.GetNetclientPath())
|
||||||
}
|
}
|
||||||
|
|
||||||
func CreateMacService(servicename string) error {
|
func CreateMacService(servicename string, interval string) error {
|
||||||
_, err := os.Stat("/Library/LaunchDaemons")
|
_, err := os.Stat("/Library/LaunchDaemons")
|
||||||
if os.IsNotExist(err) {
|
if os.IsNotExist(err) {
|
||||||
os.Mkdir("/Library/LaunchDaemons", 0755)
|
os.Mkdir("/Library/LaunchDaemons", 0755)
|
||||||
|
|
@ -58,7 +59,7 @@ func CreateMacService(servicename string) error {
|
||||||
log.Println("couldnt find or create /Library/LaunchDaemons")
|
log.Println("couldnt find or create /Library/LaunchDaemons")
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
daemonstring := MacDaemonString()
|
daemonstring := MacDaemonString(interval)
|
||||||
daemonbytes := []byte(daemonstring)
|
daemonbytes := []byte(daemonstring)
|
||||||
|
|
||||||
if !ncutils.FileExists("/Library/LaunchDaemons/com.gravitl.netclient.plist") {
|
if !ncutils.FileExists("/Library/LaunchDaemons/com.gravitl.netclient.plist") {
|
||||||
|
|
@ -67,8 +68,8 @@ func CreateMacService(servicename string) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func MacDaemonString() string {
|
func MacDaemonString(interval string) string {
|
||||||
return `<?xml version='1.0' encoding='UTF-8'?>
|
return fmt.Sprintf(`<?xml version='1.0' encoding='UTF-8'?>
|
||||||
<!DOCTYPE plist PUBLIC \"-//Apple Computer//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\" >
|
<!DOCTYPE plist PUBLIC \"-//Apple Computer//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\" >
|
||||||
<plist version='1.0'>
|
<plist version='1.0'>
|
||||||
<dict>
|
<dict>
|
||||||
|
|
@ -84,7 +85,7 @@ func MacDaemonString() string {
|
||||||
<key>StandardErrorPath</key><string>/etc/netclient/com.gravitl.netclient.log</string>
|
<key>StandardErrorPath</key><string>/etc/netclient/com.gravitl.netclient.log</string>
|
||||||
<key>AbandonProcessGroup</key><true/>
|
<key>AbandonProcessGroup</key><true/>
|
||||||
<key>StartInterval</key>
|
<key>StartInterval</key>
|
||||||
<integer>15</integer>
|
<integer>%s</integer>
|
||||||
<key>EnvironmentVariables</key>
|
<key>EnvironmentVariables</key>
|
||||||
<dict>
|
<dict>
|
||||||
<key>PATH</key>
|
<key>PATH</key>
|
||||||
|
|
@ -92,7 +93,7 @@ func MacDaemonString() string {
|
||||||
</dict>
|
</dict>
|
||||||
</dict>
|
</dict>
|
||||||
</plist>
|
</plist>
|
||||||
`
|
`,interval)
|
||||||
}
|
}
|
||||||
|
|
||||||
type MacTemplateData struct {
|
type MacTemplateData struct {
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,8 @@ import (
|
||||||
"github.com/gravitl/netmaker/netclient/ncutils"
|
"github.com/gravitl/netmaker/netclient/ncutils"
|
||||||
)
|
)
|
||||||
|
|
||||||
func SetupSystemDDaemon(network string) error {
|
func SetupSystemDDaemon(interval string) error {
|
||||||
|
|
||||||
if ncutils.IsWindows() {
|
if ncutils.IsWindows() {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
@ -21,9 +22,9 @@ func SetupSystemDDaemon(network string) error {
|
||||||
}
|
}
|
||||||
binarypath := dir + "/netclient"
|
binarypath := dir + "/netclient"
|
||||||
|
|
||||||
_, err = os.Stat("/etc/netclient")
|
_, err = os.Stat("/etc/netclient/config")
|
||||||
if os.IsNotExist(err) {
|
if os.IsNotExist(err) {
|
||||||
os.Mkdir("/etc/netclient", 744)
|
os.MkdirAll("/etc/netclient/config", 0744)
|
||||||
} else if err != nil {
|
} else if err != nil {
|
||||||
log.Println("couldnt find or create /etc/netclient")
|
log.Println("couldnt find or create /etc/netclient")
|
||||||
return err
|
return err
|
||||||
|
|
@ -46,7 +47,7 @@ Wants=netclient.timer
|
||||||
|
|
||||||
[Service]
|
[Service]
|
||||||
Type=simple
|
Type=simple
|
||||||
ExecStart=/etc/netclient/netclient checkin -n %i
|
ExecStart=/etc/netclient/netclient checkin -n all
|
||||||
|
|
||||||
[Install]
|
[Install]
|
||||||
WantedBy=multi-user.target
|
WantedBy=multi-user.target
|
||||||
|
|
@ -54,23 +55,17 @@ WantedBy=multi-user.target
|
||||||
|
|
||||||
systemtimer := `[Unit]
|
systemtimer := `[Unit]
|
||||||
Description=Calls the Netmaker Mesh Client Service
|
Description=Calls the Netmaker Mesh Client Service
|
||||||
|
Requires=netclient.service
|
||||||
`
|
|
||||||
systemtimer = systemtimer + "Requires=netclient@" + network + ".service"
|
|
||||||
|
|
||||||
systemtimer = systemtimer +
|
|
||||||
`
|
|
||||||
|
|
||||||
[Timer]
|
[Timer]
|
||||||
|
Unit=netclient.service
|
||||||
|
|
||||||
`
|
`
|
||||||
systemtimer = systemtimer + "Unit=netclient@" + network + ".service"
|
systemtimer = systemtimer + "OnCalendar=*:*:0/" + interval
|
||||||
|
|
||||||
systemtimer = systemtimer +
|
systemtimer = systemtimer +
|
||||||
`
|
`
|
||||||
|
|
||||||
OnCalendar=*:*:0/15
|
|
||||||
|
|
||||||
[Install]
|
[Install]
|
||||||
WantedBy=timers.target
|
WantedBy=timers.target
|
||||||
`
|
`
|
||||||
|
|
@ -78,26 +73,26 @@ WantedBy=timers.target
|
||||||
servicebytes := []byte(systemservice)
|
servicebytes := []byte(systemservice)
|
||||||
timerbytes := []byte(systemtimer)
|
timerbytes := []byte(systemtimer)
|
||||||
|
|
||||||
if !ncutils.FileExists("/etc/systemd/system/netclient@.service") {
|
if !ncutils.FileExists("/etc/systemd/system/netclient.service") {
|
||||||
err = ioutil.WriteFile("/etc/systemd/system/netclient@.service", servicebytes, 0644)
|
err = ioutil.WriteFile("/etc/systemd/system/netclient.service", servicebytes, 0644)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println(err)
|
log.Println(err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if !ncutils.FileExists("/etc/systemd/system/netclient-" + network + ".timer") {
|
if !ncutils.FileExists("/etc/systemd/system/netclient.timer") {
|
||||||
err = ioutil.WriteFile("/etc/systemd/system/netclient-"+network+".timer", timerbytes, 0644)
|
err = ioutil.WriteFile("/etc/systemd/system/netclient.timer", timerbytes, 0644)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println(err)
|
log.Println(err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_, _ = ncutils.RunCmd("systemctl enable netclient@.service", true)
|
_, _ = ncutils.RunCmd("systemctl enable netclient.service", true)
|
||||||
_, _ = ncutils.RunCmd("systemctl daemon-reload", true)
|
_, _ = ncutils.RunCmd("systemctl daemon-reload", true)
|
||||||
_, _ = ncutils.RunCmd("systemctl enable netclient-"+network+".timer", true)
|
_, _ = ncutils.RunCmd("systemctl enable netclient.timer", true)
|
||||||
_, _ = ncutils.RunCmd("systemctl start netclient-"+network+".timer", true)
|
_, _ = ncutils.RunCmd("systemctl start netclient.timer", true)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -110,20 +105,20 @@ func RemoveSystemDServices(network string) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
if fullremove {
|
if fullremove {
|
||||||
_, err = ncutils.RunCmd("systemctl disable netclient@.service", true)
|
_, err = ncutils.RunCmd("systemctl disable netclient.service", true)
|
||||||
}
|
}
|
||||||
_, _ = ncutils.RunCmd("systemctl daemon-reload", true)
|
_, _ = ncutils.RunCmd("systemctl daemon-reload", true)
|
||||||
|
|
||||||
if ncutils.FileExists("/etc/systemd/system/netclient-" + network + ".timer") {
|
if ncutils.FileExists("/etc/systemd/system/netclient.timer") {
|
||||||
_, _ = ncutils.RunCmd("systemctl disable netclient-"+network+".timer", true)
|
_, _ = ncutils.RunCmd("systemctl disable netclient.timer", true)
|
||||||
}
|
}
|
||||||
if fullremove {
|
if fullremove {
|
||||||
if ncutils.FileExists("/etc/systemd/system/netclient@.service") {
|
if ncutils.FileExists("/etc/systemd/system/netclient.service") {
|
||||||
err = os.Remove("/etc/systemd/system/netclient@.service")
|
err = os.Remove("/etc/systemd/system/netclient.service")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ncutils.FileExists("/etc/systemd/system/netclient-" + network + ".timer") {
|
if ncutils.FileExists("/etc/systemd/system/netclient.timer") {
|
||||||
err = os.Remove("/etc/systemd/system/netclient-" + network + ".timer")
|
err = os.Remove("/etc/systemd/system/netclient.timer")
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println("Error removing file. Please investigate.")
|
log.Println("Error removing file. Please investigate.")
|
||||||
|
|
@ -135,9 +130,10 @@ func RemoveSystemDServices(network string) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func isOnlyService(network string) (bool, error) {
|
func isOnlyService(network string) (bool, error) {
|
||||||
isonly := false
|
isonly := false
|
||||||
files, err := filepath.Glob("/etc/netclient/netconfig-*")
|
files, err := filepath.Glob("/etc/netclient/config/netconfig-*")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return isonly, err
|
return isonly, err
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -269,7 +269,7 @@ func List() error {
|
||||||
|
|
||||||
func GetNetworks() ([]string, error) {
|
func GetNetworks() ([]string, error) {
|
||||||
var networks []string
|
var networks []string
|
||||||
files, err := ioutil.ReadDir(ncutils.GetNetclientPath())
|
files, err := ioutil.ReadDir(ncutils.GetNetclientPathSpecific())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return networks, err
|
return networks, err
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -91,10 +91,5 @@ func GetMacIface(ipstring string) (string, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func HasNetwork(network string) bool {
|
func HasNetwork(network string) bool {
|
||||||
|
|
||||||
if ncutils.IsWindows() {
|
|
||||||
return ncutils.FileExists(ncutils.GetNetclientPathSpecific() + "netconfig-" + network)
|
return ncutils.FileExists(ncutils.GetNetclientPathSpecific() + "netconfig-" + network)
|
||||||
}
|
|
||||||
return ncutils.FileExists("/etc/systemd/system/netclient-"+network+".timer") ||
|
|
||||||
ncutils.FileExists(ncutils.GetNetclientPathSpecific()+"netconfig-"+network)
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -358,6 +358,7 @@ func main() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if len(os.Args) == 1 && ncutils.IsWindows() {
|
if len(os.Args) == 1 && ncutils.IsWindows() {
|
||||||
|
|
||||||
c := make(chan os.Signal)
|
c := make(chan os.Signal)
|
||||||
signal.Notify(c, os.Interrupt, syscall.SIGTERM)
|
signal.Notify(c, os.Interrupt, syscall.SIGTERM)
|
||||||
go func() {
|
go func() {
|
||||||
|
|
|
||||||
|
|
@ -284,9 +284,9 @@ func GetNetclientPathSpecific() string {
|
||||||
if IsWindows() {
|
if IsWindows() {
|
||||||
return WINDOWS_APP_DATA_PATH + "\\"
|
return WINDOWS_APP_DATA_PATH + "\\"
|
||||||
} else if IsMac() {
|
} else if IsMac() {
|
||||||
return "/etc/netclient/"
|
return "/etc/netclient/config/"
|
||||||
} else {
|
} else {
|
||||||
return LINUX_APP_DATA_PATH + "/"
|
return LINUX_APP_DATA_PATH + "/config/"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -31,6 +31,7 @@ func GetServerConfig() config.ServerConfig {
|
||||||
cfg.AllowedOrigin = GetAllowedOrigin()
|
cfg.AllowedOrigin = GetAllowedOrigin()
|
||||||
cfg.RestBackend = "off"
|
cfg.RestBackend = "off"
|
||||||
cfg.Verbosity = GetVerbose()
|
cfg.Verbosity = GetVerbose()
|
||||||
|
cfg.CheckinInterval = GetCheckinInterval()
|
||||||
if IsRestBackend() {
|
if IsRestBackend() {
|
||||||
cfg.RestBackend = "on"
|
cfg.RestBackend = "on"
|
||||||
}
|
}
|
||||||
|
|
@ -122,6 +123,16 @@ func GetAPIPort() string {
|
||||||
return apiport
|
return apiport
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func GetCheckinInterval() string {
|
||||||
|
seconds := "15"
|
||||||
|
if os.Getenv("CHECKIN_INTERVAL") != "" {
|
||||||
|
seconds = os.Getenv("CHECKIN_INTERVAL")
|
||||||
|
} else if config.Config.Server.CheckinInterval != "" {
|
||||||
|
seconds = config.Config.Server.CheckinInterval
|
||||||
|
}
|
||||||
|
return seconds
|
||||||
|
}
|
||||||
|
|
||||||
func GetDefaultNodeLimit() int32 {
|
func GetDefaultNodeLimit() int32 {
|
||||||
var limit int32
|
var limit int32
|
||||||
limit = 999999999
|
limit = 999999999
|
||||||
|
|
|
||||||
|
|
@ -32,16 +32,16 @@ func GetServerWGConf() (models.IntClient, error) {
|
||||||
|
|
||||||
func InstallNetclient() error {
|
func InstallNetclient() error {
|
||||||
|
|
||||||
netclientPath := ncutils.GetNetclientPathSpecific()
|
netclientPath := ncutils.GetNetclientPath()
|
||||||
if !FileExists(netclientPath + "netclient") {
|
if !FileExists(netclientPath + "netclient") {
|
||||||
var err error
|
var err error
|
||||||
if ncutils.IsWindows() {
|
if ncutils.IsWindows() {
|
||||||
_, err = copy(".\\netclient\\netclient", netclientPath+"netclient")
|
_, err = copy(".\\netclient\\netclient", netclientPath+"\\netclient")
|
||||||
} else {
|
} else {
|
||||||
_, err = copy("./netclient/netclient", netclientPath+"netclient")
|
_, err = copy("./netclient/netclient", netclientPath+"/netclient")
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println("could not create " + netclientPath + "netclient")
|
log.Println("could not create " + netclientPath + "/netclient")
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -86,13 +86,13 @@ func copy(src, dst string) (int64, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func RemoveNetwork(network string) (bool, error) {
|
func RemoveNetwork(network string) (bool, error) {
|
||||||
netclientPath := ncutils.GetNetclientPathSpecific()
|
netclientPath := ncutils.GetNetclientPath()
|
||||||
_, err := os.Stat(netclientPath + "netclient")
|
_, err := os.Stat(netclientPath + "/netclient")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println("could not find " + netclientPath + "netclient")
|
log.Println("could not find " + netclientPath + "/netclient")
|
||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
_, err = ncutils.RunCmd(netclientPath+"netclient leave -n "+network, true)
|
_, err = ncutils.RunCmd(netclientPath+"/netclient leave -n "+network, true)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
log.Println("Server removed from network " + network)
|
log.Println("Server removed from network " + network)
|
||||||
}
|
}
|
||||||
|
|
@ -102,22 +102,21 @@ func RemoveNetwork(network string) (bool, error) {
|
||||||
|
|
||||||
func InitServerNetclient() error {
|
func InitServerNetclient() error {
|
||||||
netclientDir := ncutils.GetNetclientPath()
|
netclientDir := ncutils.GetNetclientPath()
|
||||||
netclientPath := ncutils.GetNetclientPathSpecific()
|
_, err := os.Stat(netclientDir+"/config")
|
||||||
_, err := os.Stat(netclientDir)
|
|
||||||
if os.IsNotExist(err) {
|
if os.IsNotExist(err) {
|
||||||
os.Mkdir(netclientDir, 744)
|
os.MkdirAll(netclientDir+"/config", 744)
|
||||||
} else if err != nil {
|
} else if err != nil {
|
||||||
log.Println("could not find or create", netclientDir)
|
log.Println("could not find or create", netclientDir)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
_, err = os.Stat(netclientPath + "netclient")
|
_, err = os.Stat(netclientDir + "/netclient")
|
||||||
if os.IsNotExist(err) {
|
if os.IsNotExist(err) {
|
||||||
err = InstallNetclient()
|
err = InstallNetclient()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
err = os.Chmod(netclientPath+"netclient", 0755)
|
err = os.Chmod(netclientDir+"/netclient", 0755)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println("could not change netclient binary permissions")
|
log.Println("could not change netclient binary permissions")
|
||||||
return err
|
return err
|
||||||
|
|
@ -128,8 +127,8 @@ func InitServerNetclient() error {
|
||||||
func HandleContainedClient() error {
|
func HandleContainedClient() error {
|
||||||
log.SetFlags(log.Flags() &^ (log.Llongfile | log.Lshortfile))
|
log.SetFlags(log.Flags() &^ (log.Llongfile | log.Lshortfile))
|
||||||
|
|
||||||
netclientPath := ncutils.GetNetclientPathSpecific()
|
netclientPath := ncutils.GetNetclientPath()
|
||||||
checkinCMD := exec.Command(netclientPath+"netclient", "checkin", "-n", "all")
|
checkinCMD := exec.Command(netclientPath+"/netclient", "checkin", "-n", "all")
|
||||||
if servercfg.GetVerbose() >= 2 {
|
if servercfg.GetVerbose() >= 2 {
|
||||||
checkinCMD.Stdout = os.Stdout
|
checkinCMD.Stdout = os.Stdout
|
||||||
}
|
}
|
||||||
|
|
@ -158,7 +157,7 @@ func AddNetwork(network string) (bool, error) {
|
||||||
log.Println("could not get public IP.")
|
log.Println("could not get public IP.")
|
||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
netclientPath := ncutils.GetNetclientPathSpecific()
|
netclientPath := ncutils.GetNetclientPath()
|
||||||
|
|
||||||
token, err := functions.CreateServerToken(network)
|
token, err := functions.CreateServerToken(network)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
@ -169,9 +168,9 @@ func AddNetwork(network string) (bool, error) {
|
||||||
functions.PrintUserLog(models.NODE_SERVER_NAME, "executing network join: "+netclientPath+"netclient "+"join "+"-t "+token+" -name "+models.NODE_SERVER_NAME+" -endpoint "+pubip, 0)
|
functions.PrintUserLog(models.NODE_SERVER_NAME, "executing network join: "+netclientPath+"netclient "+"join "+"-t "+token+" -name "+models.NODE_SERVER_NAME+" -endpoint "+pubip, 0)
|
||||||
var joinCMD *exec.Cmd
|
var joinCMD *exec.Cmd
|
||||||
if servercfg.IsClientMode() == "contained" {
|
if servercfg.IsClientMode() == "contained" {
|
||||||
joinCMD = exec.Command(netclientPath+"netclient", "join", "-t", token, "-name", models.NODE_SERVER_NAME, "-endpoint", pubip, "-daemon", "off", "-dnson", "no")
|
joinCMD = exec.Command(netclientPath+"/netclient", "join", "-t", token, "-name", models.NODE_SERVER_NAME, "-endpoint", pubip, "-daemon", "off", "-dnson", "no")
|
||||||
} else {
|
} else {
|
||||||
joinCMD = exec.Command(netclientPath+"netclient", "join", "-t", token, "-name", models.NODE_SERVER_NAME, "-endpoint", pubip)
|
joinCMD = exec.Command(netclientPath+"/netclient", "join", "-t", token, "-name", models.NODE_SERVER_NAME, "-endpoint", pubip)
|
||||||
}
|
}
|
||||||
joinCMD.Stdout = os.Stdout
|
joinCMD.Stdout = os.Stdout
|
||||||
joinCMD.Stderr = os.Stderr
|
joinCMD.Stderr = os.Stderr
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue