From 4c6c83d75105e2d27955927dd750f32fce73f7e2 Mon Sep 17 00:00:00 2001 From: Callum Jones Date: Tue, 17 Dec 2019 15:48:44 +0000 Subject: [PATCH 1/3] deprecate run_on_start, add plugins to server options, with more specific separation of executable and arguments (fixes an issue where plugins with spaces in their paths not start) --- CHANGELOG.md | 3 ++ cmd/server-manager/config.example.yml | 11 +++--- server_process.go | 56 ++++++++++++++++++++++++++- servermanager_config.go | 16 ++++++++ 4 files changed, 79 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3ae5f2191..6dbd1b902 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,8 @@ v1.6.1 ------ +**Please note, this release deprecates use of "run_on_start" in config.yml. Please read the new config.yml "plugins" section if you were using run_on_start!** + Added: * Added send chat to driver option to the admin panel on the Live Timings page. @@ -8,6 +10,7 @@ Added: * Added configurable Open Graph images to both the manager as a whole and championships, with these you can link to images that will be shown whenever you share a link of the manager/championship pages on social media (premium). * Optimised the handling of UDP messages to improve performance. * When using "Any Available Car", one of each car is added to the EntryList (so long as there are enough entrants!) and then after that Entrant cars are randomised. +* Added a new 'plugins' section to config.yml. Please use this instead of 'run_on_start'. This has been added to fix issues with spaces in plugin path names. Fixes: diff --git a/cmd/server-manager/config.example.yml b/cmd/server-manager/config.example.yml index 307794624..23e032948 100644 --- a/cmd/server-manager/config.example.yml +++ b/cmd/server-manager/config.example.yml @@ -219,14 +219,15 @@ server: # each executable specified is run from the directory it is inside, for example, # the command: # - # ./my/cool/plugin/path/run.sh --some-opt config.json + # /my/cool/plugin/path/run.sh --some-opt config.json # now actually performs the following two commands: # - # 1. cd ./my/cool/plugin/path + # 1. cd /my/cool/plugin/path # 2. ./run.sh --some-opt config.json - run_on_start: - # e.g. uncomment the line below to run a 'start.sh' for kissmyrank - # - ./assetto/kissmyrank/start.sh + plugins: + # uncomment the two lines below to run the command '/my/cool/plugin/path/run.sh --some-opt config.json' + # - executable: /my/cool/plugin/path/run.sh + # arguments: ["--some-opt", "config.json"] ################################################################################ # diff --git a/server_process.go b/server_process.go index e8d1f70d9..efd3dbaef 100644 --- a/server_process.go +++ b/server_process.go @@ -4,7 +4,6 @@ import ( "bytes" "context" "errors" - "fmt" "net" "os" "os/exec" @@ -164,7 +163,13 @@ func (as *AssettoServerProcess) Start(cfg ServerConfig, entryList EntryList, for return err } - err = as.startChildProcess(wd, fmt.Sprintf("%s --stracker_ini %s", StrackerExecutablePath(), filepath.Join(StrackerFolderPath(), strackerConfigIniFilename))) + err = as.startPlugin(wd, &CommandPlugin{ + Executable: StrackerExecutablePath(), + Arguments: []string{ + "--stracker_ini", + filepath.Join(StrackerFolderPath(), strackerConfigIniFilename), + }, + }) if err != nil { return err @@ -176,6 +181,18 @@ func (as *AssettoServerProcess) Start(cfg ServerConfig, entryList EntryList, for } } + for _, plugin := range config.Server.Plugins { + err = as.startPlugin(wd, plugin) + + if err != nil { + logrus.WithError(err).Errorf("Could not run extra command: %s", plugin.String()) + } + } + + if len(config.Server.RunOnStart) > 0 { + logrus.Warnf("Use of run_on_start in config.yml is deprecated. Please use 'plugins' instead") + } + for _, command := range config.Server.RunOnStart { err = as.startChildProcess(wd, command) @@ -193,7 +210,42 @@ func (as *AssettoServerProcess) Start(cfg ServerConfig, entryList EntryList, for return nil } +func (as *AssettoServerProcess) startPlugin(wd string, plugin *CommandPlugin) error { + commandFullPath, err := filepath.Abs(plugin.Executable) + + if err != nil { + as.cmd = nil + return err + } + + cmd := buildCommand(as.ctx, commandFullPath, plugin.Arguments...) + + pluginDir, err := filepath.Abs(filepath.Dir(commandFullPath)) + + if err != nil { + logrus.WithError(err).Warnf("Could not determine plugin directory. Setting working dir to: %s", wd) + pluginDir = wd + } + + cmd.Stdout = pluginsOutput + cmd.Stderr = pluginsOutput + + cmd.Dir = pluginDir + + err = cmd.Start() + + if err != nil { + return err + } + + as.extraProcesses = append(as.extraProcesses, cmd) + + return nil +} + +// Deprecated: use startPlugin instead func (as *AssettoServerProcess) startChildProcess(wd string, command string) error { + // BUG(cj): splitting commands on spaces breaks child processes that have a space in their path name parts := strings.Split(command, " ") if len(parts) == 0 { diff --git a/servermanager_config.go b/servermanager_config.go index 7899e3810..09f16162d 100644 --- a/servermanager_config.go +++ b/servermanager_config.go @@ -4,6 +4,7 @@ import ( "errors" "fmt" "os" + "strings" "github.com/cj123/sessions" "github.com/etcd-io/bbolt" @@ -141,6 +142,9 @@ func (s *StoreConfig) BuildStore() (Store, error) { } type ServerExtraConfig struct { + Plugins []*CommandPlugin `yaml:"plugins"` + + // Deprecated; use Plugins instead RunOnStart []string `yaml:"run_on_start"` AuditLogging bool `yaml:"audit_logging"` PerformanceMode bool `yaml:"performance_mode"` @@ -148,6 +152,18 @@ type ServerExtraConfig struct { ScanContentFolderForChanges bool `yaml:"scan_content_folder_for_changes"` } +type CommandPlugin struct { + Executable string `yaml:"executable"` + Arguments []string `yaml:"arguments"` +} + +func (c *CommandPlugin) String() string { + out := c.Executable + out += strings.Join(c.Arguments, " ") + + return out +} + const acsrURL = "https://acsr.assettocorsaservers.com" func ReadConfig(location string) (conf *Configuration, err error) { From 9ce3091b395ef127a80d918d083805c68197a554 Mon Sep 17 00:00:00 2001 From: Callum Jones Date: Tue, 17 Dec 2019 15:54:58 +0000 Subject: [PATCH 2/3] add a missing space --- cmd/server-manager/config.example.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/server-manager/config.example.yml b/cmd/server-manager/config.example.yml index 23e032948..a034984bd 100644 --- a/cmd/server-manager/config.example.yml +++ b/cmd/server-manager/config.example.yml @@ -227,7 +227,7 @@ server: plugins: # uncomment the two lines below to run the command '/my/cool/plugin/path/run.sh --some-opt config.json' # - executable: /my/cool/plugin/path/run.sh - # arguments: ["--some-opt", "config.json"] + # arguments: ["--some-opt", "config.json"] ################################################################################ # From 23e215f28cbdd505210f4e2c7f2f47827ab0f5ec Mon Sep 17 00:00:00 2001 From: Callum Jones Date: Tue, 17 Dec 2019 15:58:09 +0000 Subject: [PATCH 3/3] move runonstart to bottom of serverextraconfig struct --- servermanager_config.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/servermanager_config.go b/servermanager_config.go index 09f16162d..06b2a7cae 100644 --- a/servermanager_config.go +++ b/servermanager_config.go @@ -142,14 +142,14 @@ func (s *StoreConfig) BuildStore() (Store, error) { } type ServerExtraConfig struct { - Plugins []*CommandPlugin `yaml:"plugins"` + Plugins []*CommandPlugin `yaml:"plugins"` + AuditLogging bool `yaml:"audit_logging"` + PerformanceMode bool `yaml:"performance_mode"` + DisableWindowsBrowserOpen bool `yaml:"dont_open_browser"` + ScanContentFolderForChanges bool `yaml:"scan_content_folder_for_changes"` // Deprecated; use Plugins instead - RunOnStart []string `yaml:"run_on_start"` - AuditLogging bool `yaml:"audit_logging"` - PerformanceMode bool `yaml:"performance_mode"` - DisableWindowsBrowserOpen bool `yaml:"dont_open_browser"` - ScanContentFolderForChanges bool `yaml:"scan_content_folder_for_changes"` + RunOnStart []string `yaml:"run_on_start"` } type CommandPlugin struct {