Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

initial SysTray PR #48

Closed
wants to merge 50 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
8387104
Add SysTray
conlan0 Apr 3, 2024
b1701de
Add case "systrayconfig"
conlan0 Apr 3, 2024
a1b6336
Start systray process on startup
conlan0 Apr 3, 2024
df94341
Update systray.go
conlan0 Apr 3, 2024
a5f7eed
Add tray flag
conlan0 Apr 3, 2024
e133c5f
Rename systray.go to systray_windows.go
conlan0 Apr 3, 2024
53d8a44
Update and rename main.go to tray_windows.go
conlan0 Apr 3, 2024
11234f9
Update and rename pipe.go to pipe_windows.go
conlan0 Apr 3, 2024
35ee16f
Rename icon.go to icon_windows.go
conlan0 Apr 3, 2024
28a549a
add tray_unix
conlan0 Apr 4, 2024
6ea3d69
Update agent_unix.go for systray
conlan0 Apr 4, 2024
14edf27
update go.mod and go.sum
conlan0 Apr 4, 2024
1463ab2
update go.mod and go.sum again
conlan0 Apr 4, 2024
25395e0
Delete go.sum
conlan0 Apr 4, 2024
7002efe
Delete go.mod
conlan0 Apr 4, 2024
fd45a9b
add go.mod
conlan0 Apr 4, 2024
3985395
add sum
conlan0 Apr 4, 2024
ecad4d0
update bundled python version on windows >= 8.1 to 3.11.9
wh1te909 Jun 23, 2024
5fef58f
update reqs
wh1te909 Jun 23, 2024
c64fc85
update cmd
wh1te909 Jun 30, 2024
687e890
bump version
wh1te909 Jul 8, 2024
08cf78c
Add SysTray
conlan0 Apr 3, 2024
88b7dd4
Add case "systrayconfig"
conlan0 Apr 3, 2024
322ba0e
Start systray process on startup
conlan0 Apr 3, 2024
38e9bf6
Update systray.go
conlan0 Apr 3, 2024
03c90f1
Add tray flag
conlan0 Apr 3, 2024
32aa608
Rename systray.go to systray_windows.go
conlan0 Apr 3, 2024
639a04e
Update and rename main.go to tray_windows.go
conlan0 Apr 3, 2024
5369902
Update and rename pipe.go to pipe_windows.go
conlan0 Apr 3, 2024
83d1689
Rename icon.go to icon_windows.go
conlan0 Apr 3, 2024
1febe80
add tray_unix
conlan0 Apr 4, 2024
d247c8c
Update agent_unix.go for systray
conlan0 Apr 4, 2024
67dcd5e
update go.mod and go.sum
conlan0 Apr 4, 2024
59317fb
update go.mod and go.sum again
conlan0 Apr 4, 2024
4a9be4e
Update filepaths, requests and more
conlan0 Aug 5, 2024
766b930
Merge branch 'develop' of https://github.com/conlan0/rmmagent into de…
conlan0 Aug 5, 2024
7ce4bbc
Update go.sum
conlan0 Aug 5, 2024
f5a4463
Update go.mod
conlan0 Aug 5, 2024
723982f
Delete duplicate function
conlan0 Aug 5, 2024
6825abf
Update go.mod
conlan0 Aug 5, 2024
3a67218
Delete agent/support directory
conlan0 Aug 5, 2024
43861ff
Update go.sum
conlan0 Aug 5, 2024
cb666e8
Update go.sum
conlan0 Aug 5, 2024
ac20609
Update go.mod
conlan0 Aug 5, 2024
fc82407
Update go.mod
conlan0 Aug 5, 2024
4bca338
Update go.sum
conlan0 Aug 5, 2024
014a3cf
Update go.sum
conlan0 Aug 5, 2024
c48afe0
Update go.sum
conlan0 Aug 5, 2024
bab9189
Update go.sum
conlan0 Aug 5, 2024
7cbb297
Update main.go to use tray not support
conlan0 Aug 5, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 24 additions & 6 deletions agent/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ type Agent struct {
MeshSystemEXE string
MeshSVC string
PyBin string
PyVer string
PyBaseDir string
PyDir string
NuBin string
DenoBin string
AgentHeader string
Expand Down Expand Up @@ -116,12 +119,24 @@ func New(logger *logrus.Logger, version string) *Agent {
hostname = info.Hostname
}

var pybin string
switch runtime.GOARCH {
case "amd64":
pybin = filepath.Join(pd, "py38-x64", "python.exe")
case "386":
pybin = filepath.Join(pd, "py38-x32", "python.exe")
pyver := "n/a"
pybin := "n/a"
pyBaseDir := "n/a"
pydir := "n/a"

if runtime.GOOS == "windows" {
major := info.OS.Major
minor := info.OS.Minor
if major > 6 || (major == 6 && minor >= 3) {
// Windows 8.1 or higher
pyver = "3.11.9"
} else {
pyver = "3.8.7"
}

pydir = "py" + pyver + "_" + runtime.GOARCH
pyBaseDir = filepath.Join(pd, "python")
pybin = filepath.Join(pyBaseDir, pydir, "python.exe")
}

var nuBin string
Expand Down Expand Up @@ -254,6 +269,9 @@ func New(logger *logrus.Logger, version string) *Agent {
MeshSystemEXE: MeshSysExe,
MeshSVC: meshSvcName,
PyBin: pybin,
PyVer: pyver,
PyBaseDir: pyBaseDir,
PyDir: pydir,
NuBin: nuBin,
DenoBin: denoBin,
Headers: headers,
Expand Down
4 changes: 4 additions & 0 deletions agent/agent_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -970,3 +970,7 @@ func (a *Agent) Start(_ service.Service) error { return nil }
func (a *Agent) Stop(_ service.Service) error { return nil }

func (a *Agent) InstallService() error { return nil }

func (a *Agent) GetSystrayConfig() {
fmt.Println("System trays are only supported on windows at this time.")
}
44 changes: 23 additions & 21 deletions agent/agent_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -752,6 +752,15 @@ func (a *Agent) AgentUninstall(code string) {

// RunMigrations cleans up unused stuff from older agents
func (a *Agent) RunMigrations() {

// changed pybin dirs in v2.8.0
for _, i := range []string{"py38-x64", "py38-x32"} {
py := filepath.Join(a.ProgramDir, i)
if trmm.FileExists(py) {
os.RemoveAll(py)
}
}

for _, i := range []string{"nssm.exe", "nssm-x86.exe"} {
nssm := filepath.Join(a.ProgramDir, i)
if trmm.FileExists(nssm) {
Expand Down Expand Up @@ -845,30 +854,23 @@ func (a *Agent) GetPython(force bool) {
return
}

if force {
os.RemoveAll(a.PyBaseDir)
}

sleepDelay := randRange(1, 10)
a.Logger.Debugf("GetPython() sleeping for %v seconds", sleepDelay)
a.Logger.Debugf("GetPython() sleeping for %v seconds\n", sleepDelay)
time.Sleep(time.Duration(sleepDelay) * time.Second)

var archZip string
var folder string
switch runtime.GOARCH {
case "amd64":
archZip = "py38-x64.zip"
folder = "py38-x64"
case "386":
archZip = "py38-x32.zip"
folder = "py38-x32"
}
pyFolder := filepath.Join(a.ProgramDir, folder)
pyZip := filepath.Join(a.ProgramDir, archZip)
a.Logger.Debugln(pyZip)
a.Logger.Debugln(a.PyBin)
defer os.Remove(pyZip)

if force {
os.RemoveAll(pyFolder)
if !trmm.FileExists(a.PyBaseDir) {
os.MkdirAll(a.PyBaseDir, 0775)
}

archZip := a.PyDir + ".zip"

pyZip := filepath.Join(a.PyBaseDir, archZip)
defer os.Remove(pyZip)

rClient := resty.New()
rClient.SetTimeout(20 * time.Minute)
rClient.SetRetryCount(10)
Expand All @@ -878,7 +880,7 @@ func (a *Agent) GetPython(force bool) {
rClient.SetProxy(a.Proxy)
}

url := fmt.Sprintf("https://github.com/amidaware/rmmagent/releases/download/v2.0.0/%s", archZip)
url := fmt.Sprintf("https://github.com/amidaware/rmmagent/releases/download/v2.8.0/%s", archZip)
a.Logger.Debugln(url)
r, err := rClient.R().SetOutput(pyZip).Get(url)
if err != nil {
Expand All @@ -890,7 +892,7 @@ func (a *Agent) GetPython(force bool) {
return
}

err = Unzip(pyZip, a.ProgramDir)
err = Unzip(pyZip, a.PyBaseDir)
if err != nil {
a.Logger.Errorln(err)
}
Expand Down
10 changes: 10 additions & 0 deletions agent/rpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,16 @@ func (a *Agent) RunRPC() {
msg.Respond(resp)
}()

case "systrayconfig":
go func() {
a.Logger.Debugln("Updating systray")
var resp []byte
ret := codec.NewEncoderBytes(&resp, new(codec.MsgpackHandle))
a.GetSystrayConfig()
ret.Encode("ok")
msg.Respond(resp)
}()

case "shutdown":
go func() {
a.Logger.Debugln("Scheduling immediate shutdown")
Expand Down
8 changes: 6 additions & 2 deletions agent/svc.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ type AgentCheckInConfig struct {
}

func (a *Agent) AgentSvc(nc *nats.Conn) {
a.RunMigrations()

if runtime.GOOS == "windows" {
go a.GetPython(false)

Expand All @@ -58,8 +60,6 @@ func (a *Agent) AgentSvc(nc *nats.Conn) {
}
}

a.RunMigrations()

sleepDelay := randRange(7, 25)
a.Logger.Debugf("AgentSvc() sleeping for %v seconds", sleepDelay)
time.Sleep(time.Duration(sleepDelay) * time.Second)
Expand All @@ -70,6 +70,10 @@ func (a *Agent) AgentSvc(nc *nats.Conn) {
a.CleanupAgentUpdates()
}

if runtime.GOOS == "windows" {
go a.GetSystrayConfig()
}

// Windows has GetAgentCheckInConfig() while unix has a stub GetAgentCheckInConfig()
conf := a.GetAgentCheckInConfig(a.GetCheckInConfFromAPI())
a.Logger.Debugf("AgentCheckInConf: %+v\n", conf)
Expand Down
Loading