Skip to content

Commit

Permalink
Start opts support & more error-prone JVM opt defaults
Browse files Browse the repository at this point in the history
  • Loading branch information
krystian-panek-vmltech committed Jan 26, 2023
1 parent ec05388 commit f3033df
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 17 deletions.
13 changes: 7 additions & 6 deletions pkg/cfg/values.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 2 additions & 0 deletions pkg/common/constants.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package common

const (
AppId = "aem-compose"
AppName = "AEM Compose"
MainDir = "aem"
HomeDirName = "home"
HomeDir = MainDir + "/" + HomeDirName
Expand Down
5 changes: 5 additions & 0 deletions pkg/common/tplx/tplx.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"bytes"
"fmt"
"github.com/wttech/aemc/pkg/common/filex"
"github.com/wttech/aemc/pkg/common/pathx"
"reflect"
"text/template"
)
Expand Down Expand Up @@ -31,6 +32,10 @@ var funcMap = template.FuncMap{
}
return value
},
"pathabs": func(path string) string {
defer recovery()
return pathx.Abs(path)
},
}

func recovery() {
Expand Down
3 changes: 3 additions & 0 deletions pkg/instance_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
30 changes: 21 additions & 9 deletions pkg/local_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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 {
Expand All @@ -42,7 +44,7 @@ const (
LocalInstanceScriptStatus = "status"
LocalInstanceBackupExtension = "aemb.tar.zst"
LocalInstanceUser = "admin"
LocalInstanceWorkDirName = "aem-compose"
LocalInstanceWorkDirName = common.AppId
)

func (li LocalInstance) Instance() *Instance {
Expand All @@ -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
}

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)

Expand All @@ -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)
Expand All @@ -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()
}
Expand Down
6 changes: 4 additions & 2 deletions project/aem/default/etc/aem.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit f3033df

Please sign in to comment.