Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -773,6 +773,19 @@ sh aemw instance stop
sh aemw instance delete
```

### Upgrading Local Instances

`instance upgrade` prepares an in-place Quickstart upgrade for stopped local
instances. It unpacks and temporarily starts the new Quickstart distribution so
AEM can apply its startup-resource upgrades, then stops it again.

Start the instance normally after the command completes:

```shell
sh aemw instance upgrade
sh aemw instance start
```

## Deploying Packages

```shell
Expand Down
2 changes: 1 addition & 1 deletion cmd/aem/instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ func (c *CLI) instanceCreateCmd() *cobra.Command {
func (c *CLI) instanceUpgradeCmd() *cobra.Command {
return &cobra.Command{
Use: "upgrade",
Short: "Upgrades AEM instance(s) if needed",
Short: "Upgrades AEM instance(s) using the new Quickstart JAR",
Aliases: []string{"update"},
Run: func(cmd *cobra.Command, args []string) {
localInstances, err := c.aem.InstanceManager().SomeLocals()
Expand Down
83 changes: 74 additions & 9 deletions pkg/local_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,9 @@ func (li LocalInstance) Upgrade() error {
if err := li.adapt(); err != nil {
return err
}
if err := li.startUpgradeJar(); err != nil {
return err
}

log.Infof("%s > upgraded", li.instance.IDColor())
return nil
Expand Down Expand Up @@ -481,17 +484,9 @@ func (li LocalInstance) Start() error {
if !li.IsCreated() {
return fmt.Errorf("%s > cannot start as it is not created", li.instance.IDColor())
}
if !li.LocalOpts().ServiceMode {
if err := li.update(); err != nil {
return err
}
}
log.Infof("%s > starting", li.instance.IDColor())
if err := li.CheckPortsOpen(); err != nil {
return err
}
defer func() { pathx.DeleteIfExists(li.passwordFile()) }()
if err := li.savePasswordFile(); err != nil {
if err := li.prepareStart(); err != nil {
return err
}
cmd, err := li.binScriptCommand(LocalInstanceScriptStart, true)
Expand Down Expand Up @@ -519,6 +514,61 @@ func (li LocalInstance) Start() error {
return nil
}

func (li LocalInstance) startUpgradeJar() error {
defer func() { pathx.DeleteIfExists(li.passwordFile()) }()
if err := li.prepareStart(); err != nil {
return err
}
jar, err := li.VendorManager().InstanceJar()
if err != nil {
return err
}
args := li.upgradeJarArgs(jar)
cmd, err := li.JavaManager().Command(args...)
if err != nil {
return err
}
cmd.Dir = li.Dir()
cmd.Env = append(cmd.Env, li.EnvVars...)
li.instance.manager.aem.CommandOutput(cmd)
if err := cmd.Start(); err != nil {
return fmt.Errorf("%s > cannot execute upgrade start command: %w", li.instance.IDColor(), err)
}
defer li.stopUpgradeJar(cmd)
if err := li.awaitAuth(); err != nil {
return err
}
if err := li.instance.manager.AwaitStartedOne(*li.instance); err != nil {
return err
}
return nil
}

func (li LocalInstance) stopUpgradeJar(cmd *exec.Cmd) {
if cmd.Process == nil || cmd.ProcessState != nil {
return
}
if err := cmd.Process.Signal(os.Interrupt); err != nil {
log.Warnf("%s > cannot stop upgrade start command: %s", li.instance.IDColor(), err)
}
if err := cmd.Wait(); err != nil {
if _, ok := err.(*exec.ExitError); !ok {
log.Warnf("%s > cannot await upgrade start command: %s", li.instance.IDColor(), err)
}
}
}

func (li LocalInstance) upgradeJarArgs(jar string) []string {
args := append([]string{}, li.JvmOpts...)
return append(args,
"-jar", pathx.Canonical(jar),
"-nofork",
"-nointeractive",
"-r", li.RunModesString(),
"-p", li.instance.http.Port(),
)
}

func (li LocalInstance) StartAndAwait() error {
if err := li.Start(); err != nil {
return err
Expand All @@ -529,6 +579,21 @@ func (li LocalInstance) StartAndAwait() error {
return nil
}

func (li LocalInstance) prepareStart() error {
if !li.LocalOpts().ServiceMode {
if err := li.update(); err != nil {
return err
}
}
if err := li.CheckPortsOpen(); err != nil {
return err
}
if err := li.savePasswordFile(); err != nil {
return err
}
return nil
}

func (li LocalInstance) update() error {
if !li.IsInitialized() { // first boot
if err := li.copyOverrideDirs(); err != nil {
Expand Down
Loading