From f3033df79acb7e13462265fadfbfeb835336883e Mon Sep 17 00:00:00 2001 From: Krystian Panek Date: Thu, 26 Jan 2023 13:19:01 +0100 Subject: [PATCH] Start opts support & more error-prone JVM opt defaults --- pkg/cfg/values.go | 13 +++++++------ pkg/common/constants.go | 2 ++ pkg/common/tplx/tplx.go | 5 +++++ pkg/instance_manager.go | 3 +++ pkg/local_instance.go | 30 +++++++++++++++++++++--------- project/aem/default/etc/aem.yml | 6 ++++-- 6 files changed, 42 insertions(+), 17 deletions(-) diff --git a/pkg/cfg/values.go b/pkg/cfg/values.go index 52471347..1e180065 100644 --- a/pkg/cfg/values.go +++ b/pkg/cfg/values.go @@ -39,12 +39,13 @@ type ConfigValues struct { ConfigURL string `mapstructure:"config_url" yaml:"config_url"` Config map[string]struct { - HTTPURL string `mapstructure:"http_url" yaml:"http_url"` - User string `mapstructure:"user"` - Password string `mapstructure:"password"` - JVMOpts []string `mapstructure:"jvm_opts" yaml:"jvm_opts"` - RunModes []string `mapstructure:"run_modes" yaml:"run_modes"` - Version string `mapstructure:"version" yaml:"version"` + HTTPURL string `mapstructure:"http_url" yaml:"http_url"` + User string `mapstructure:"user"` + Password string `mapstructure:"password"` + StartOpts []string `mapstructure:"start_opts" yaml:"start_opts"` + JVMOpts []string `mapstructure:"jvm_opts" yaml:"jvm_opts"` + RunModes []string `mapstructure:"run_modes" yaml:"run_modes"` + Version string `mapstructure:"version" yaml:"version"` } `mapstructure:"config" yaml:"config"` Filter struct { diff --git a/pkg/common/constants.go b/pkg/common/constants.go index b482b06e..95a06a20 100644 --- a/pkg/common/constants.go +++ b/pkg/common/constants.go @@ -1,6 +1,8 @@ package common const ( + AppId = "aem-compose" + AppName = "AEM Compose" MainDir = "aem" HomeDirName = "home" HomeDir = MainDir + "/" + HomeDirName diff --git a/pkg/common/tplx/tplx.go b/pkg/common/tplx/tplx.go index 1f075758..842d58a8 100644 --- a/pkg/common/tplx/tplx.go +++ b/pkg/common/tplx/tplx.go @@ -4,6 +4,7 @@ import ( "bytes" "fmt" "github.com/wttech/aemc/pkg/common/filex" + "github.com/wttech/aemc/pkg/common/pathx" "reflect" "text/template" ) @@ -31,6 +32,10 @@ var funcMap = template.FuncMap{ } return value }, + "pathabs": func(path string) string { + defer recovery() + return pathx.Abs(path) + }, } func recovery() { diff --git a/pkg/instance_manager.go b/pkg/instance_manager.go index 13be92d4..39bee4be 100644 --- a/pkg/instance_manager.go +++ b/pkg/instance_manager.go @@ -282,6 +282,9 @@ func (im *InstanceManager) configureInstances(config *cfg.Config) { } if i.IsLocal() { if len(iCfg.RunModes) > 0 { + if len(iCfg.StartOpts) > 0 { + i.local.StartOpts = iCfg.StartOpts + } if len(iCfg.JVMOpts) > 0 { i.local.JvmOpts = iCfg.JVMOpts } diff --git a/pkg/local_instance.go b/pkg/local_instance.go index 79f1547d..eecde372 100644 --- a/pkg/local_instance.go +++ b/pkg/local_instance.go @@ -2,6 +2,7 @@ package pkg import ( "fmt" + "github.com/wttech/aemc/pkg/common" "github.com/wttech/aemc/pkg/common/cryptox" "github.com/wttech/aemc/pkg/common/execx" "github.com/wttech/aemc/pkg/common/filex" @@ -24,9 +25,10 @@ import ( type LocalInstance struct { instance *Instance - Version string - JvmOpts []string - RunModes []string + Version string + JvmOpts []string + StartOpts []string + RunModes []string } type LocalInstanceState struct { @@ -42,7 +44,7 @@ const ( LocalInstanceScriptStatus = "status" LocalInstanceBackupExtension = "aemb.tar.zst" LocalInstanceUser = "admin" - LocalInstanceWorkDirName = "aem-compose" + LocalInstanceWorkDirName = common.AppId ) func (li LocalInstance) Instance() *Instance { @@ -52,8 +54,12 @@ func (li LocalInstance) Instance() *Instance { func NewLocal(i *Instance) *LocalInstance { li := &LocalInstance{instance: i} li.Version = "1" - li.JvmOpts = []string{"-server", "-Xmx1024m", "-Djava.awt.headless=true"} - li.RunModes = []string{} + li.StartOpts = []string{} + li.RunModes = []string{"local"} + li.JvmOpts = []string{ + "-Djava.io.tmpdir=" + pathx.Abs(common.TmpDir), + "-Duser.language=en", "-Duser.country=US", "-Duser.timezone=UTC", "-Duser.name=" + common.AppId, + } return li } @@ -424,6 +430,7 @@ func (li LocalInstance) awaitAuth() error { return nil } // TODO 'local_author | auth not ready (1/588=2%): xtg' + // TODO at first await reachable (with the same message), then check auth return li.Await("auth ready", func() bool { _, err := li.instance.osgi.bundleManager.List() return err == nil @@ -498,7 +505,7 @@ func (li LocalInstance) Delete() error { if li.IsRunning() { return fmt.Errorf("cannot delete instance as it is running") } - log.Infof("deleting instance '%s' ", li.instance.ID()) + log.Infof("deleting instance '%s'", li.instance.ID()) if err := pathx.Delete(li.Dir()); err != nil { return fmt.Errorf("cannot delete instance properly: %w", err) @@ -521,6 +528,7 @@ func (li LocalInstance) binScriptCommand(name string, verbose bool) *exec.Cmd { "CQ_PORT="+li.instance.http.Port(), "CQ_RUNMODE="+li.instance.local.RunModesString(), "CQ_JVM_OPTS="+li.instance.local.JVMOptsString(), + "CQ_START_OPTS"+li.instance.local.StartOptsString(), ) if verbose { li.instance.manager.aem.CommandOutput(cmd) @@ -539,13 +547,17 @@ func (li LocalInstance) JVMOptsString() string { result := append([]string{}, li.JvmOpts...) // at the first boot admin password could be customized via property, at the next boot only via Oak Run - if !li.IsInitialized() { - result = append(result, fmt.Sprintf("-Dadmin.password=%s", li.instance.password)) + if !li.IsInitialized() && li.instance.password != instance.PasswordDefault { + result = append(result, fmt.Sprintf("-Dadmin.password='%s'", li.instance.password)) } sort.Strings(result) return strings.Join(result, " ") } +func (li LocalInstance) StartOptsString() string { + return strings.Join(li.StartOpts, " ") +} + func (li LocalInstance) OutOfDate() bool { return !li.UpToDate() } diff --git a/project/aem/default/etc/aem.yml b/project/aem/default/etc/aem.yml index 119a8339..dbe52574 100755 --- a/project/aem/default/etc/aem.yml +++ b/project/aem/default/etc/aem.yml @@ -11,13 +11,15 @@ instance: user: admin password: admin run_modes: [ local ] - jvm_opts: -Djava.io.tmpdir=aem/home/tmp -Duser.timezone=UTC -Duser.language=en-EN + jvm_opts: -Djava.io.tmpdir={{ pathabs "aem/home/tmp" }} -Duser.language=en -Duser.country=US -Duser.timezone=UTC -Duser.name=aem-compose + start_opts: [] local_publish: http_url: http://127.0.0.1:4503 user: admin password: admin run_modes: [ local ] - jvm_opts: -Djava.io.tmpdir=aem/home/tmp -Duser.timezone=UTC -Duser.language=en-EN + jvm_opts: -Djava.io.tmpdir={{ pathabs "aem/home/tmp" }} -Duser.language=en -Duser.country=US -Duser.timezone=UTC -Duser.name=aem-compose + start_opts: [] # Filters for defined filter: