Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
21 changes: 20 additions & 1 deletion agent/installer/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,26 @@ func main() {
h.FatalError("Error installing the UTMStack Agent: one or more of the requiered ports are closed. Please open ports 9000 and 50051.")
}

err := utils.CreatePathIfNotExist(filepath.Join(path, "locks"))
if err != nil {
fmt.Printf("error creating locks path: %v", err)
h.FatalError("error creating locks path: %v", err)
}

err = utils.SetLock(filepath.Join(path, "locks", "setup.lock"))
if err != nil {
fmt.Printf("error setting setup.lock: %v", err)
h.FatalError("error setting setup.lock: %v", err)
}

err = checkversion.CleanOldVersions(h)
if err != nil {
fmt.Printf("error cleaning old versions: %v", err)
h.FatalError("error cleaning old versions: %v", err)
}

// Download dependencies
err := depend.DownloadDependencies(servBins, ip, skip)
err = depend.DownloadDependencies(servBins, ip, skip)
if err != nil {
fmt.Printf("error downloading dependencies: %v", err)
h.FatalError("error downloading dependencies: %v", err)
Expand All @@ -85,6 +97,13 @@ func main() {

h.Info("UTMStack Agent services installed correctly.")
fmt.Println("UTMStack Agent services installed correctly.")

err = utils.RemoveLock(filepath.Join(path, "locks", "setup.lock"))
if err != nil {
fmt.Printf("error removing setup.lock: %v", err)
h.FatalError("error removing setup.lock: %v", err)
}

time.Sleep(5 * time.Second)
os.Exit(0)

Expand Down
13 changes: 13 additions & 0 deletions agent/installer/utils/files.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package utils

import (
"encoding/json"
"fmt"
"os"
"path/filepath"

Expand Down Expand Up @@ -81,3 +82,15 @@ func WriteJSON(path string, data interface{}) error {

return nil
}

// CreatePathIfNotExist creates a specific path if not exist
func CreatePathIfNotExist(path string) error {
if _, err := os.Stat(path); os.IsNotExist(err) {
if err := os.Mkdir(path, 0755); err != nil {
return fmt.Errorf("error creating path: %v", err)
}
} else if err != nil {
return fmt.Errorf("error checking path: %v", err)
}
return nil
}
29 changes: 29 additions & 0 deletions agent/installer/utils/lock.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package utils

import (
"fmt"
"os"
)

func SetLock(lockdir string) error {
if !CheckIfPathExist(lockdir) {
file, err := os.OpenFile(lockdir, os.O_CREATE|os.O_RDWR|os.O_TRUNC, os.ModePerm)
if err != nil {
return err
}
defer file.Close()
}
return nil
}

func RemoveLock(lockdir string) error {
if CheckIfPathExist(lockdir) {
err := os.Remove(lockdir)
if err != nil {
return err
}
} else {
return fmt.Errorf("lock file %s not exists", lockdir)
}
return nil
}
1 change: 0 additions & 1 deletion agent/redline/protector/protector.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,5 @@ func ProtectService(servName, lockName string, h *holmes.Logger) {
time.Sleep(time.Second * 5)
continue
}

}
}
21 changes: 10 additions & 11 deletions agent/redline/serv/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package serv
import (
"os"
"os/signal"
"path/filepath"
"syscall"
"time"

Expand All @@ -27,21 +28,19 @@ func (p *program) Stop(s service.Service) error {
}

func (p *program) run() {
checkall:
path, err := utils.GetMyPath()
if err != nil {
h.FatalError("Failed to get current path: %v", err)
}

for {
for servName := range constants.GetServicesLock() {
isActive, err := utils.CheckIfServiceIsActive(servName)
if err != nil {
time.Sleep(time.Second * 5)
h.Error("error checking if %s service is active: %v", servName, err)
continue checkall
} else if !isActive {
time.Sleep(time.Second * 5)
continue checkall
}
if utils.CheckIfPathExist(filepath.Join(path, "locks", "setup.lock")) {
time.Sleep(time.Second * 5)
continue
}
break
}

h.Info("UTMStackRedline started correctly")
for servName, lockName := range constants.GetServicesLock() {
go protector.ProtectService(servName, lockName, h)
Expand Down
2 changes: 1 addition & 1 deletion agent/versions.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"master_version": "10.2.0",
"agent_version": "10.2.0",
"updater_version": "10.1.2",
"redline_version": "10.1.1"
"redline_version": "10.2.0"
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export class GuideWinlogbeatComponent implements OnInit {
getCommand(): string {
const ip = window.location.host.includes(':') ? window.location.host.split(':')[0] : window.location.host;
return `New-Item -ItemType Directory -Force -Path "C:\\Program Files\\UTMStack\\UTMStack Agent"; ` +
`Invoke-WebRequest -Uri "https://cdn.utmstack.com/agent_updates/release/installer/v10.1.2/utmstack_agent_installer.exe" ` +
`Invoke-WebRequest -Uri "https://cdn.utmstack.com/agent_updates/release/installer/v10.2.0/utmstack_agent_installer.exe" ` +
`-OutFile "C:\\Program Files\\UTMStack\\UTMStack Agent\\utmstack_agent_installer.exe"; ` +
`Start-Process "C:\\Program Files\\UTMStack\\UTMStack Agent\\utmstack_agent_installer.exe" ` +
`-ArgumentList 'install', '` + ip + `', '<secret>` + this.token + `</secret>', 'yes' -NoNewWindow -Wait`;
Expand Down