Skip to content

Commit

Permalink
windows fixes and changes
Browse files Browse the repository at this point in the history
  • Loading branch information
et-nik committed Feb 21, 2024
1 parent c5fc4a5 commit 66e83f1
Show file tree
Hide file tree
Showing 17 changed files with 306 additions and 66 deletions.
3 changes: 2 additions & 1 deletion internal/app/components/extendable_executor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package components_test
import (
"context"
"os"
"path/filepath"
"runtime"
"syscall"
"testing"
Expand Down Expand Up @@ -37,7 +38,7 @@ func TestExtendableExecutor_ExecGetTool_ExpectToolDownloaded(t *testing.T) {
require.NoError(t, err)
require.Equal(t, 0, code)
require.NotEmpty(t, result)
path := tmpDir + "/fastdl.sh"
path := filepath.Join(tmpDir, "/fastdl.sh")
assert.FileExists(t, path)
assertFileIsExecutableByOwner(t, path)
}
Expand Down
12 changes: 11 additions & 1 deletion internal/app/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ package config

import (
"os"
"path/filepath"
"time"

"github.com/gameap/daemon/internal/processmanager"
)

type Scripts struct {
Expand Down Expand Up @@ -73,6 +76,11 @@ type Config struct {
RunTaskPeriod time.Duration `yaml:"run_task_period"`
WorkersCount int `yaml:"workers_count"`
} `yaml:"task_manager"`

ProcessManager struct {
Name string `yaml:"name"`
Config map[string]string `yaml:"config"`
} `yaml:"process_manager"`
}

func NewConfig() *Config {
Expand All @@ -86,7 +94,7 @@ func NewConfig() *Config {

func (cfg *Config) Init() error {
if cfg.ToolsPath == "" {
cfg.ToolsPath = cfg.WorkPath + "/tools"
cfg.ToolsPath = filepath.Join(cfg.WorkPath, "tools")
}

if cfg.TaskManager.UpdatePeriod == 0 {
Expand All @@ -97,6 +105,8 @@ func (cfg *Config) Init() error {
cfg.TaskManager.RunTaskPeriod = 10 * time.Millisecond
}

cfg.ProcessManager.Name = processmanager.Default

return cfg.validate()
}

Expand Down
2 changes: 2 additions & 0 deletions internal/app/config/loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ func loadIni(path string) (*Config, error) {
cfg.PrivateKeyPassword = c.Section("").Key("private_key_password").String()
cfg.DHFile = c.Section("").Key("dh_file").String()

cfg.ProcessManager.Name = c.Section("").Key("process_manager").String()

cfg.LogLevel = c.Section("").Key("log_level").MustString("debug")
cfg.OutputLog = c.Section("").Key("output_log").MustString("")

Expand Down
9 changes: 8 additions & 1 deletion internal/app/di/internal/definitions/services.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,17 @@ func CreateServiceExtendableExecutor(ctx context.Context, c Container) contracts
}

func CreateServicesProcessManager(ctx context.Context, c Container) contracts.ProcessManager {
return processmanager.NewSystemD(
pm, err := processmanager.Load(
c.Cfg(ctx).ProcessManager.Name,
c.Cfg(ctx),
c.Services().Executor(ctx),
)
if err != nil {
c.SetError(err)
return nil
}

return pm
}

func CreateServicesGdTaskManager(ctx context.Context, c Container) *gdaemonscheduler.TaskManager {
Expand Down
4 changes: 2 additions & 2 deletions internal/app/game_server_commands/delete_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,8 @@ func (suite *deleteSuite) TestDeleteServerByScriptSuccess() {
suite.Require().Nil(err)
suite.Assert().Equal(SuccessResult, deleteServerCommand.Result())
suite.Assert().NoFileExists(server.WorkDir(cfg))
suite.Assert().NoFileExists(server.WorkDir(cfg) + "/" + "run.sh")
suite.Assert().NoFileExists(server.WorkDir(cfg) + "/" + "run2.sh")
suite.Assert().NoFileExists(filepath.Join(server.WorkDir(cfg), "run.sh"))
suite.Assert().NoFileExists(filepath.Join(server.WorkDir(cfg), "run2.sh"))
}

func (suite *deleteSuite) TestDeleteServerByScript_CommandFail() {
Expand Down
4 changes: 4 additions & 0 deletions internal/processmanager/loader_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ import (
"github.com/gameap/daemon/internal/app/contracts"
)

const (
Default = "tmux"
)

func Load(name string, cfg *config.Config, executor contracts.Executor) (contracts.ProcessManager, error) {
switch name {
case "tmux":
Expand Down
4 changes: 4 additions & 0 deletions internal/processmanager/loader_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ import (
"github.com/gameap/daemon/internal/app/contracts"
)

const (
Default = "tmux"
)

func Load(name string, cfg *config.Config, executor contracts.Executor) (contracts.ProcessManager, error) {
switch name {
case "tmux":
Expand Down
6 changes: 5 additions & 1 deletion internal/processmanager/loader_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,14 @@ import (
"github.com/gameap/daemon/internal/app/contracts"
)

const (
Default = "winsw"
)

func Load(name string, cfg *config.Config, executor contracts.Executor) (contracts.ProcessManager, error) {
switch name {
case "winsw":
return NewWindowsService(cfg, executor), nil
return NewWinSW(cfg, executor), nil
case "simple":
return NewSimple(cfg, executor), nil
default:
Expand Down
7 changes: 4 additions & 3 deletions internal/processmanager/systemd.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
const (
systemdFilesDir = ".systemd-services"
systemdServicesDir = "/etc/systemd/system"
servicePrefix = "gameap-server-"

// https://www.freedesktop.org/software/systemd/man/latest/systemctl.html#Exit%20status
statusIsDeadPidExists = 1
Expand Down Expand Up @@ -388,7 +389,7 @@ func (pm *SystemD) buildSocketConfig(server *domain.Server) string {
builder.WriteString("\n")

builder.WriteString("Service=")
builder.WriteString("gameap-")
builder.WriteString(servicePrefix)
builder.WriteString(server.UUID())
builder.WriteString(".service\n")

Expand Down Expand Up @@ -427,7 +428,7 @@ func (pm *SystemD) serviceName(server *domain.Server) string {
builder := strings.Builder{}
builder.Grow(50)

builder.WriteString("gameap-")
builder.WriteString(servicePrefix)
builder.WriteString(server.UUID())
builder.WriteString(".service")

Expand All @@ -442,7 +443,7 @@ func (pm *SystemD) socketName(server *domain.Server) string {
builder := strings.Builder{}
builder.Grow(50)

builder.WriteString("gameap-")
builder.WriteString(servicePrefix)
builder.WriteString(server.UUID())
builder.WriteString(".socket")

Expand Down
Loading

0 comments on commit 66e83f1

Please sign in to comment.