Skip to content

Commit

Permalink
modify install flow for windows msi
Browse files Browse the repository at this point in the history
  • Loading branch information
Son Roy Almerol committed Nov 29, 2024
1 parent 1fe4d2a commit 1b4c111
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 57 deletions.
10 changes: 1 addition & 9 deletions build/package/windows/wix.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,9 @@
"command": "[INSTALLDIR]pbs-plus-agent.exe install",
"when": "install"
},
{
"command": "[INSTALLDIR]pbs-plus-agent.exe start",
"when": "install"
},
{
"command": "[INSTALLDIR]pbs-plus-agent.exe stop",
"when": "uninstall"
},
{
"command": "[INSTALLDIR]pbs-plus-agent.exe uninstall",
"when": "uninstall"
}
]
}
}
63 changes: 15 additions & 48 deletions cmd/windows_agent/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package main
import (
"fmt"
"os"
"time"

"github.com/kardianos/service"
"github.com/sonroyaalmerol/pbs-plus/internal/syslog"
Expand Down Expand Up @@ -53,60 +54,26 @@ func main() {

if len(os.Args) > 1 {
cmd := os.Args[1]
switch cmd {
case "install":
status, err := s.Status()
if err == nil {
switch status {
case service.StatusStopped:
_ = s.Uninstall()
case service.StatusRunning:
_ = s.Stop()
_ = s.Uninstall()
case service.StatusUnknown:
}
}

if cmd == "install" || cmd == "uninstall" {
for _, drive := range getLocalDrives() {
_ = registry.DeleteKey(registry.LOCAL_MACHINE, fmt.Sprintf(`Software\PBSPlus\Config\SFTP-%s`, drive.Letter))
}
}

err = s.Install()
if err != nil {
logger.Errorf("Failed to install service: %s", err)
} else {
logger.Info("Service installed")
}
return
case "uninstall":
err = s.Uninstall()
if err != nil {
logger.Errorf("Failed to uninstall service: %s", err)
} else {
logger.Info("Service uninstalled")
}
return
case "start":
err = s.Start()
if err != nil {
logger.Errorf("Failed to start service: %s", err)
} else {
logger.Info("Service started")
}
return
case "stop":
err = s.Stop()
if err != nil {
logger.Errorf("Failed to stop service: %s", err)
} else {
logger.Info("Service stopped")
}
return
default:
logger.Errorf("Unknown command: %s", cmd)
logger.Info("Available commands: install, uninstall, start, stop")
err = service.Control(s, cmd)
if err != nil {
logger.Errorf("Failed to %s service: %s", cmd, err)
return
}

if cmd == "install" {
go func() {
<-time.After(10 * time.Second)
_ = s.Start()
}()
}

return
}

if !service.Interactive() {
Expand Down

0 comments on commit 1b4c111

Please sign in to comment.