mirror of
https://github.com/gravitl/netmaker.git
synced 2024-11-11 01:54:34 +08:00
updated service files for linux and darwin to start netclient daemon vice netclient checkin
This commit is contained in:
parent
746d90d109
commit
6a30bca315
2 changed files with 16 additions and 46 deletions
|
@ -19,8 +19,8 @@ func SetupMacDaemon(interval string) error {
|
|||
}
|
||||
binarypath := dir + "/netclient"
|
||||
|
||||
if !ncutils.FileExists("/etc/netclient/netclient") {
|
||||
err = ncutils.Copy(binarypath, "/etc/netclient/netclient")
|
||||
if !ncutils.FileExists("/sbin/netclient") {
|
||||
err = ncutils.Copy(binarypath, "/sbin/netclient")
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
return err
|
||||
|
@ -49,6 +49,7 @@ func CleanupMac() {
|
|||
}
|
||||
|
||||
os.RemoveAll(ncutils.GetNetclientPath())
|
||||
os.Remove("/sbin/netclient")
|
||||
}
|
||||
|
||||
func CreateMacService(servicename string, interval string) error {
|
||||
|
@ -76,10 +77,8 @@ func MacDaemonString(interval string) string {
|
|||
<key>Label</key><string>com.gravitl.netclient</string>
|
||||
<key>ProgramArguments</key>
|
||||
<array>
|
||||
<string>/etc/netclient/netclient</string>
|
||||
<string>checkin</string>
|
||||
<string>-n</string>
|
||||
<string>all</string>
|
||||
<string>/sbin/netclient</string>
|
||||
<string>daemon</string>
|
||||
</array>
|
||||
<key>StandardOutPath</key><string>/etc/netclient/com.gravitl.netclient.log</string>
|
||||
<key>StandardErrorPath</key><string>/etc/netclient/com.gravitl.netclient.log</string>
|
||||
|
|
|
@ -29,12 +29,10 @@ func SetupSystemDDaemon(interval string) error {
|
|||
log.Println("couldnt find or create /etc/netclient")
|
||||
return err
|
||||
}
|
||||
|
||||
if !ncutils.FileExists("/usr/local/bin/netclient") {
|
||||
os.Symlink("/etc/netclient/netclient", "/usr/local/bin/netclient")
|
||||
}
|
||||
if !ncutils.FileExists("/etc/netclient/netclient") {
|
||||
err = ncutils.Copy(binarypath, "/etc/netclient/netclient")
|
||||
//install binary
|
||||
//should check if the existing binary is the corect version -- for now only copy if file doesn't exist
|
||||
if !ncutils.FileExists("/usr/sbin/netclient") {
|
||||
err = ncutils.Copy(binarypath, "/usr/sbin/netclient")
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
return err
|
||||
|
@ -42,36 +40,17 @@ func SetupSystemDDaemon(interval string) error {
|
|||
}
|
||||
|
||||
systemservice := `[Unit]
|
||||
Description=Network Check
|
||||
Wants=netclient.timer
|
||||
Description=Netclient message queue
|
||||
|
||||
[Service]
|
||||
Type=simple
|
||||
ExecStart=/etc/netclient/netclient checkin -n all
|
||||
ExecStart=/usr/sbin/netclient daemon
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
`
|
||||
|
||||
systemtimer := `[Unit]
|
||||
Description=Calls the Netmaker Mesh Client Service
|
||||
Requires=netclient.service
|
||||
|
||||
[Timer]
|
||||
Unit=netclient.service
|
||||
|
||||
`
|
||||
systemtimer = systemtimer + "OnCalendar=*:*:0/" + interval
|
||||
|
||||
systemtimer = systemtimer +
|
||||
`
|
||||
|
||||
[Install]
|
||||
WantedBy=timers.target
|
||||
`
|
||||
|
||||
servicebytes := []byte(systemservice)
|
||||
timerbytes := []byte(systemtimer)
|
||||
|
||||
if !ncutils.FileExists("/etc/systemd/system/netclient.service") {
|
||||
err = os.WriteFile("/etc/systemd/system/netclient.service", servicebytes, 0644)
|
||||
|
@ -80,25 +59,17 @@ WantedBy=timers.target
|
|||
return err
|
||||
}
|
||||
}
|
||||
|
||||
if !ncutils.FileExists("/etc/systemd/system/netclient.timer") {
|
||||
err = os.WriteFile("/etc/systemd/system/netclient.timer", timerbytes, 0644)
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
_, _ = ncutils.RunCmd("systemctl enable netclient.service", true)
|
||||
_, _ = ncutils.RunCmd("systemctl daemon-reload", true)
|
||||
_, _ = ncutils.RunCmd("systemctl enable netclient.timer", true)
|
||||
_, _ = ncutils.RunCmd("systemctl start netclient.timer", true)
|
||||
_, _ = ncutils.RunCmd("systemctl start netclient.server", true)
|
||||
return nil
|
||||
}
|
||||
|
||||
func CleanupLinux() {
|
||||
err := os.RemoveAll(ncutils.GetNetclientPath())
|
||||
if err != nil {
|
||||
if err := os.RemoveAll(ncutils.GetNetclientPath()); err != nil {
|
||||
ncutils.PrintLog("Removing netclient configs: "+err.Error(), 1)
|
||||
}
|
||||
if err := os.Remove("/usr/sbin/netclient"); err != nil {
|
||||
ncutils.PrintLog("Removing netclient binary: "+err.Error(), 1)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue