gemmellr commented on code in PR #4246:
URL: https://github.com/apache/activemq-artemis/pull/4246#discussion_r1010367104


##########
docs/user-manual/en/versions.md:
##########
@@ -8,7 +8,8 @@ This chapter provides the following information for each 
release:
   - **Note:** Follow the general upgrade procedure outlined in the [Upgrading 
the Broker](upgrading.md) 
     chapter in addition to any version-specific upgrade instructions outlined 
here.
 
-## 2.27.0
+
+### 2.27.0

Review Comment:
   All the prior versions used ##, this is now inconsistent.
   
   Also, the steps below dont mention the upgrade command.



##########
artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/Upgrade.java:
##########
@@ -0,0 +1,299 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.activemq.artemis.cli.commands;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.io.PrintStream;
+import java.nio.file.Files;
+import java.nio.file.StandardCopyOption;
+import java.util.Iterator;
+import java.util.stream.Stream;
+
+import io.airlift.airline.Command;
+
+@Command(name = "upgrade", description = "Update an artemis instance to the 
current artemis.home, keeping all the data and broker.xml. Warning: backup your 
instance before using this command and compare the files.")
+public class Upgrade extends InstallAbstract {
+
+   /**
+    * Checks that the directory provided either exists and is writable or 
doesn't exist but can be created.
+    */
+   protected void checkDirectory() {
+      if (!directory.exists()) {
+         throw new RuntimeException(String.format("Could not find path '%s' to 
upgrade.", directory));
+      } else if (!directory.canWrite()) {
+         throw new RuntimeException(String.format("The path '%s' is not 
writable.", directory));
+      }
+   }
+
+
+   @Override
+   public Object execute(ActionContext context) throws Exception {
+      this.checkDirectory();
+      super.execute(context);
+
+      return run(context);
+   }
+
+
+   public Object run(ActionContext context) throws Exception {
+      File bkpFolder = findBackup();
+      File bkpBin = new File(bkpFolder, "bin");
+      File etcBkp = new File(bkpFolder, "etc");
+      bkpBin.mkdirs();
+      etcBkp.mkdirs();
+
+      File bin = new File(directory, "bin");
+      File etcFolder = new File(directory, etc);
+
+      if (!bin.exists()) {
+         throw new IOException(bin.getAbsolutePath() + " does not exist");
+      }
+
+      
System.out.println("*******************************************************************************************************************************");
+      System.out.println("Upgrading broker instance " + directory + " to use 
artemis.home=" + getBrokerHome());
+
+      upgradeArtemis(bkpBin, bin, etcFolder);
+      upgradeArtemisCmd(bkpBin, bin, etcFolder);
+      upgradeArtemisProfile(etcBkp, etcFolder, directory);
+      upgradeBootstrap(etcBkp, etcFolder, directory);
+      upgradeLogging(etcBkp, etcFolder, directory);
+      System.out.println();
+      System.out.println("Warning: ./artemis upgrade does not bring new 
functionality on the script itself from newer artemis versions. Please check 
for any differences on artemis script in the current release!");
+      
System.out.println("*******************************************************************************************************************************");
+
+      return null;
+   }
+
+   private void upgradeLogging(File bkpFolder, File etc, File instance) throws 
Exception {
+      File oldLogging = new File(etc, "logging.properties");
+
+      if (oldLogging.exists()) {
+         System.out.println("Moving " + oldLogging + " under " + bkpFolder);
+         File oldLoggingCopy = new File(bkpFolder, "logging.properties");
+         Files.copy(oldLogging.toPath(), oldLoggingCopy.toPath(), 
StandardCopyOption.REPLACE_EXISTING);
+         oldLogging.delete();
+         File newLogging = new File(etc, Create.ETC_LOG4J2_PROPERTIES);
+
+
+         if (!newLogging.exists()) {
+            System.out.println("Creating " + newLogging);
+            InputStream inputStream = getClass().getResourceAsStream("etc/" + 
Create.ETC_LOG4J2_PROPERTIES);
+            OutputStream outputStream = new FileOutputStream(newLogging);
+            outputStream.write(inputStream.readAllBytes());
+            inputStream.close();
+         }
+      }
+   }
+
+
+
+   private void upgradeBootstrap(File bkpFolder, File etc, File instance) 
throws Exception {
+      File bootstrap = new File(etc, "bootstrap.xml");
+      if (bootstrap.exists()) {
+         File bootstrapCopy = new File(bkpFolder, "bootstrap.xml");
+         Files.copy(bootstrap.toPath(), bootstrapCopy.toPath(), 
StandardCopyOption.REPLACE_EXISTING);
+         System.out.println("Converting bootstrap.xml. Original file backed up 
at " + bkpFolder.getAbsolutePath());
+
+         upgrade(bootstrapCopy, bootstrap, (input, iterator, out) -> {
+            if (input.trim().startsWith("<server configuration=")) {
+               return "   <server configuration=\"" + etc.toURI() + 
"/broker.xml" + "\"/>";
+            }
+
+            return input;
+         });
+      } else {
+         System.out.println("Could not find bootstrap.xml");
+      }
+   }
+
+
+   private void upgradeArtemisProfile(File bkpFolder, File etc, File instance) 
throws Exception {
+      File artemisProfile = new File(etc, "artemis.profile");
+      if (artemisProfile.exists()) {
+         File artemisProfileCopy = new File(bkpFolder, "artemis.profile");
+         Files.copy(artemisProfile.toPath(), artemisProfileCopy.toPath(), 
StandardCopyOption.REPLACE_EXISTING);
+         System.out.println("Converting artemis profile. Original file backed 
up at " + bkpFolder.getAbsolutePath());
+
+         upgrade(artemisProfileCopy, artemisProfile, (input, iterator, out) -> 
{
+
+            if (input.startsWith("ARTEMIS_HOME=")) {
+               return "ARTEMIS_HOME='" + getHome().getAbsolutePath() + "'";
+            }
+
+            if (input.startsWith("ARTEMIS_INSTANCE=")) {
+               return "ARTEMIS_INSTANCE='" + instance.getAbsolutePath() + "'";
+            }
+
+            if (input.startsWith("ARTEMIS_DATA_DIR=")) {
+               // TODO: this variable is not really used, we should get rid of 
it
+               return "ARTEMIS_DATA_DIR='" + instance.getAbsolutePath() + 
"/data'";
+            }
+
+            if (input.startsWith("ARTEMIS_ETC_DIR=")) {
+               return "ARTEMIS_ETC_DIR='" + etc.getAbsolutePath() + "'";
+            }
+
+            if (input.startsWith("ARTEMIS_OOME_DUMP=")) {
+               return "ARTEMIS_OOME_DUMP='" + instance.getAbsolutePath() + 
"/log/oom_dump.hprof'";
+            }
+
+            if (input.startsWith("ARTEMIS_INSTANCE_URI=")) {
+               return "ARTEMIS_INSTANCE_URI='" + instance.toURI() + "'";
+            }
+
+            if (input.startsWith("ARTEMIS_INSTANCE_ETC_URI=")) {
+               return "ARTEMIS_INSTANCE_ETC_URI='" + etc.toURI() + "'";
+            }
+
+            return input;
+         });
+      }
+   }
+
+   private void upgradeArtemis(File bkpFolder, File bin, File etc) throws 
Exception {
+      File artemis = new File(bin, "artemis");
+      if (artemis.exists()) {
+         File artemisCopy = new File(bkpFolder, "artemis");
+         Files.copy(artemis.toPath(), artemisCopy.toPath(), 
StandardCopyOption.REPLACE_EXISTING);
+         System.out.println("Converting artemis script. Original file backed 
up at " + bkpFolder.getAbsolutePath());
+
+         upgrade(artemisCopy, artemis, (input, iterator, out) -> {
+
+            if (input.startsWith("ARTEMIS_INSTANCE_ETC=")) {
+               return "ARTEMIS_INSTANCE_ETC='" + etc.getAbsolutePath() + "'";
+            }
+
+            if (input.trim().startsWith("-Xbootclasspath/a:\"$LOG_MANAGER:")) {
+               return null;
+            }
+
+            if (input.trim().startsWith("-Djava.util.logging.manager")) {
+               return null;
+            }
+
+            if (input.trim().startsWith("-Dlogging.configuration=")) {
+               return null;
+            }
+
+            switch (input.trim()) {
+               case "if [ -z \"$WILDFLY_COMMON\" ] ; then": {
+                  String nextLine = iterator.next().trim();
+                  if (!nextLine.startsWith("# this is the one")) {
+                     throw new RuntimeException("Script artemis was manually 
updated. Can't proceed with upgrade");
+                  }
+                  nextLine = iterator.next().trim();
+                  if (!nextLine.startsWith("WILDFLY_COMMON=")) {
+                     throw new RuntimeException("Script artemis was manually 
updated. Can't proceed with upgrade");
+                  }
+
+                  nextLine = iterator.next().trim();
+                  if (!nextLine.startsWith("fi")) {
+                     throw new RuntimeException("Script artemis was manually 
updated. Can't proceed with upgrade");
+                  }
+                  return null;
+               }
+
+               case "if [ -z \"$LOG_MANAGER\" ] ; then":
+                  return null;
+               case "# this is the one found when the server was created": {
+                  // looking for the following snippet:
+                  // 
https://github.com/apache/activemq-artemis/blob/fb1b362b473cad51ae5d05a897be02b1fa8461d4/artemis-cli/src/main/resources/org/apache/activemq/artemis/cli/commands/bin/artemis#L103-L109
+                  String nextLine = iterator.next().trim();
+                  if (!nextLine.startsWith("LOG_MANAGER=")) {
+                     throw new RuntimeException("Script artemis was manually 
updated. Can't proceed with upgrade");
+                  }
+                  nextLine = iterator.next().trim();
+                  if (!nextLine.startsWith("fi")) {
+                     throw new RuntimeException("Script artemis was manually 
updated. Can't proceed with upgrade");
+                  }
+                  return null;
+               }
+
+               case "# Set Defaults Properties":
+               case 
"ARTEMIS_LOGGING_CONF=\"$ARTEMIS_INSTANCE_ETC_URI/logging.properties\"":
+               case "ARTEMIS_LOG_MANAGER=org.jboss.logmanager.LogManager":
+               case "# finding the Log Manager":
+               case "LOG_MANAGER=`ls $ARTEMIS_HOME/lib/jboss-logmanager*jar 
2>/dev/null`":
+               case "WILDFLY_COMMON=`ls $ARTEMIS_HOME/lib/wildfly-common*jar 
2>/dev/null`":
+                  return null;
+            }
+            return input;
+         });
+      }
+   }
+
+   private void upgradeArtemisCmd(File bkpFolder, File bin, File etc) throws 
Exception {
+      File artemis = new File(bin, "artemis.cmd");
+      if (artemis.exists()) {
+         File artemisCopy = new File(bkpFolder, "artemis.cmd");
+         Files.copy(artemis.toPath(), artemisCopy.toPath(), 
StandardCopyOption.REPLACE_EXISTING);
+         System.out.println("Converting artemis script. Original file backed 
up at " + bkpFolder.getAbsolutePath());
+
+         upgrade(artemisCopy, artemis, (input, iterator, out) -> {
+            switch (input.trim()) {
+               case "rem \"Set Defaults.\"":
+               case "set 
ARTEMIS_LOGGING_CONF=%ARTEMIS_INSTANCE_ETC_URI%/logging.properties":
+               case "set ARTEMIS_LOG_MANAGER=org.jboss.logmanager.LogManager":
+               case "set JVM_ARGS=%JVM_ARGS% 
-Djava.util.logging.manager=%ARTEMIS_LOG_MANAGER%":
+               case "set JVM_ARGS=%JVM_ARGS% 
-Dlogging.configuration=%ARTEMIS_LOGGING_CONF%":
+                  return null;
+            }
+            return input;
+         });
+      }
+   }
+
+
+   private void upgrade(File sourceFile, File targetFile, IteratorFunction 
interceptorString) throws Exception {
+
+      PrintStream streamOutput = new PrintStream(new 
FileOutputStream(targetFile));
+
+      try (Stream<String> lines = Files.lines(sourceFile.toPath())) {
+
+         Iterator<String> linesIterator = lines.iterator();
+         while (linesIterator.hasNext()) {
+            String line = linesIterator.next();
+            line = interceptorString.process(line, linesIterator, 
streamOutput);
+            if (line != null) {
+               streamOutput.println(line);
+            }
+         }
+      }
+   }
+
+   private interface IteratorFunction {
+      String process(String line, Iterator<String> iteratorSource, PrintStream 
output);
+   }
+
+   protected File findBackup() {
+      for (int bkp = 0; bkp < 10; bkp++) {
+         File bkpFolder = new File(directory, "bkp." + bkp);
+         if (!bkpFolder.exists()) {
+            bkpFolder.mkdirs();
+            System.out.println("Using " + bkpFolder.getAbsolutePath() + " as a 
backup folder for the modified files");
+            return bkpFolder;
+         }
+      }
+      throw new RuntimeException("Too many bckup folders in place already. 
Please clean some of the older bkp folders");

Review Comment:
   bckup  -> backup



##########
artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/Run.java:
##########
@@ -225,4 +227,21 @@ protected void stop() {
          e.printStackTrace();
       }
    }
+
+
+   public static final String OLD_LOG_NAME = "logging.properties";
+
+   public static void verifyOlderLogging(File fileInstance) throws Exception {

Review Comment:
   If the --etc option allows configuring that location, is this necessarily 
looking in the right place?



##########
artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/Upgrade.java:
##########
@@ -0,0 +1,299 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.activemq.artemis.cli.commands;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.io.PrintStream;
+import java.nio.file.Files;
+import java.nio.file.StandardCopyOption;
+import java.util.Iterator;
+import java.util.stream.Stream;
+
+import io.airlift.airline.Command;
+
+@Command(name = "upgrade", description = "Update an artemis instance to the 
current artemis.home, keeping all the data and broker.xml. Warning: backup your 
instance before using this command and compare the files.")
+public class Upgrade extends InstallAbstract {
+
+   /**
+    * Checks that the directory provided either exists and is writable or 
doesn't exist but can be created.
+    */
+   protected void checkDirectory() {
+      if (!directory.exists()) {
+         throw new RuntimeException(String.format("Could not find path '%s' to 
upgrade.", directory));
+      } else if (!directory.canWrite()) {
+         throw new RuntimeException(String.format("The path '%s' is not 
writable.", directory));
+      }
+   }
+
+
+   @Override
+   public Object execute(ActionContext context) throws Exception {
+      this.checkDirectory();
+      super.execute(context);
+
+      return run(context);
+   }
+
+
+   public Object run(ActionContext context) throws Exception {
+      File bkpFolder = findBackup();
+      File bkpBin = new File(bkpFolder, "bin");
+      File etcBkp = new File(bkpFolder, "etc");
+      bkpBin.mkdirs();
+      etcBkp.mkdirs();
+
+      File bin = new File(directory, "bin");
+      File etcFolder = new File(directory, etc);
+
+      if (!bin.exists()) {
+         throw new IOException(bin.getAbsolutePath() + " does not exist");
+      }
+
+      
System.out.println("*******************************************************************************************************************************");
+      System.out.println("Upgrading broker instance " + directory + " to use 
artemis.home=" + getBrokerHome());
+
+      upgradeArtemis(bkpBin, bin, etcFolder);
+      upgradeArtemisCmd(bkpBin, bin, etcFolder);
+      upgradeArtemisProfile(etcBkp, etcFolder, directory);
+      upgradeBootstrap(etcBkp, etcFolder, directory);
+      upgradeLogging(etcBkp, etcFolder, directory);
+      System.out.println();
+      System.out.println("Warning: ./artemis upgrade does not bring new 
functionality on the script itself from newer artemis versions. Please check 
for any differences on artemis script in the current release!");
+      
System.out.println("*******************************************************************************************************************************");
+
+      return null;
+   }
+
+   private void upgradeLogging(File bkpFolder, File etc, File instance) throws 
Exception {
+      File oldLogging = new File(etc, "logging.properties");
+
+      if (oldLogging.exists()) {
+         System.out.println("Moving " + oldLogging + " under " + bkpFolder);
+         File oldLoggingCopy = new File(bkpFolder, "logging.properties");
+         Files.copy(oldLogging.toPath(), oldLoggingCopy.toPath(), 
StandardCopyOption.REPLACE_EXISTING);
+         oldLogging.delete();
+         File newLogging = new File(etc, Create.ETC_LOG4J2_PROPERTIES);
+
+
+         if (!newLogging.exists()) {
+            System.out.println("Creating " + newLogging);
+            InputStream inputStream = getClass().getResourceAsStream("etc/" + 
Create.ETC_LOG4J2_PROPERTIES);
+            OutputStream outputStream = new FileOutputStream(newLogging);
+            outputStream.write(inputStream.readAllBytes());
+            inputStream.close();
+         }
+      }
+   }
+
+
+
+   private void upgradeBootstrap(File bkpFolder, File etc, File instance) 
throws Exception {
+      File bootstrap = new File(etc, "bootstrap.xml");
+      if (bootstrap.exists()) {
+         File bootstrapCopy = new File(bkpFolder, "bootstrap.xml");
+         Files.copy(bootstrap.toPath(), bootstrapCopy.toPath(), 
StandardCopyOption.REPLACE_EXISTING);
+         System.out.println("Converting bootstrap.xml. Original file backed up 
at " + bkpFolder.getAbsolutePath());
+
+         upgrade(bootstrapCopy, bootstrap, (input, iterator, out) -> {
+            if (input.trim().startsWith("<server configuration=")) {
+               return "   <server configuration=\"" + etc.toURI() + 
"/broker.xml" + "\"/>";
+            }
+
+            return input;
+         });
+      } else {
+         System.out.println("Could not find bootstrap.xml");
+      }
+   }
+
+
+   private void upgradeArtemisProfile(File bkpFolder, File etc, File instance) 
throws Exception {
+      File artemisProfile = new File(etc, "artemis.profile");
+      if (artemisProfile.exists()) {
+         File artemisProfileCopy = new File(bkpFolder, "artemis.profile");
+         Files.copy(artemisProfile.toPath(), artemisProfileCopy.toPath(), 
StandardCopyOption.REPLACE_EXISTING);
+         System.out.println("Converting artemis profile. Original file backed 
up at " + bkpFolder.getAbsolutePath());
+
+         upgrade(artemisProfileCopy, artemisProfile, (input, iterator, out) -> 
{
+
+            if (input.startsWith("ARTEMIS_HOME=")) {
+               return "ARTEMIS_HOME='" + getHome().getAbsolutePath() + "'";
+            }
+
+            if (input.startsWith("ARTEMIS_INSTANCE=")) {
+               return "ARTEMIS_INSTANCE='" + instance.getAbsolutePath() + "'";
+            }
+
+            if (input.startsWith("ARTEMIS_DATA_DIR=")) {
+               // TODO: this variable is not really used, we should get rid of 
it
+               return "ARTEMIS_DATA_DIR='" + instance.getAbsolutePath() + 
"/data'";
+            }
+
+            if (input.startsWith("ARTEMIS_ETC_DIR=")) {
+               return "ARTEMIS_ETC_DIR='" + etc.getAbsolutePath() + "'";
+            }
+
+            if (input.startsWith("ARTEMIS_OOME_DUMP=")) {
+               return "ARTEMIS_OOME_DUMP='" + instance.getAbsolutePath() + 
"/log/oom_dump.hprof'";
+            }
+
+            if (input.startsWith("ARTEMIS_INSTANCE_URI=")) {
+               return "ARTEMIS_INSTANCE_URI='" + instance.toURI() + "'";
+            }
+
+            if (input.startsWith("ARTEMIS_INSTANCE_ETC_URI=")) {
+               return "ARTEMIS_INSTANCE_ETC_URI='" + etc.toURI() + "'";
+            }
+
+            return input;
+         });
+      }
+   }
+
+   private void upgradeArtemis(File bkpFolder, File bin, File etc) throws 
Exception {
+      File artemis = new File(bin, "artemis");
+      if (artemis.exists()) {
+         File artemisCopy = new File(bkpFolder, "artemis");
+         Files.copy(artemis.toPath(), artemisCopy.toPath(), 
StandardCopyOption.REPLACE_EXISTING);
+         System.out.println("Converting artemis script. Original file backed 
up at " + bkpFolder.getAbsolutePath());
+
+         upgrade(artemisCopy, artemis, (input, iterator, out) -> {
+
+            if (input.startsWith("ARTEMIS_INSTANCE_ETC=")) {
+               return "ARTEMIS_INSTANCE_ETC='" + etc.getAbsolutePath() + "'";
+            }
+
+            if (input.trim().startsWith("-Xbootclasspath/a:\"$LOG_MANAGER:")) {
+               return null;
+            }
+
+            if (input.trim().startsWith("-Djava.util.logging.manager")) {
+               return null;
+            }
+
+            if (input.trim().startsWith("-Dlogging.configuration=")) {
+               return null;
+            }
+
+            switch (input.trim()) {
+               case "if [ -z \"$WILDFLY_COMMON\" ] ; then": {
+                  String nextLine = iterator.next().trim();
+                  if (!nextLine.startsWith("# this is the one")) {
+                     throw new RuntimeException("Script artemis was manually 
updated. Can't proceed with upgrade");
+                  }
+                  nextLine = iterator.next().trim();
+                  if (!nextLine.startsWith("WILDFLY_COMMON=")) {
+                     throw new RuntimeException("Script artemis was manually 
updated. Can't proceed with upgrade");
+                  }
+
+                  nextLine = iterator.next().trim();
+                  if (!nextLine.startsWith("fi")) {
+                     throw new RuntimeException("Script artemis was manually 
updated. Can't proceed with upgrade");
+                  }
+                  return null;
+               }
+
+               case "if [ -z \"$LOG_MANAGER\" ] ; then":
+                  return null;
+               case "# this is the one found when the server was created": {
+                  // looking for the following snippet:
+                  // 
https://github.com/apache/activemq-artemis/blob/fb1b362b473cad51ae5d05a897be02b1fa8461d4/artemis-cli/src/main/resources/org/apache/activemq/artemis/cli/commands/bin/artemis#L103-L109
+                  String nextLine = iterator.next().trim();
+                  if (!nextLine.startsWith("LOG_MANAGER=")) {
+                     throw new RuntimeException("Script artemis was manually 
updated. Can't proceed with upgrade");
+                  }
+                  nextLine = iterator.next().trim();
+                  if (!nextLine.startsWith("fi")) {
+                     throw new RuntimeException("Script artemis was manually 
updated. Can't proceed with upgrade");
+                  }
+                  return null;
+               }
+
+               case "# Set Defaults Properties":
+               case 
"ARTEMIS_LOGGING_CONF=\"$ARTEMIS_INSTANCE_ETC_URI/logging.properties\"":
+               case "ARTEMIS_LOG_MANAGER=org.jboss.logmanager.LogManager":
+               case "# finding the Log Manager":
+               case "LOG_MANAGER=`ls $ARTEMIS_HOME/lib/jboss-logmanager*jar 
2>/dev/null`":
+               case "WILDFLY_COMMON=`ls $ARTEMIS_HOME/lib/wildfly-common*jar 
2>/dev/null`":
+                  return null;
+            }
+            return input;
+         });
+      }
+   }
+
+   private void upgradeArtemisCmd(File bkpFolder, File bin, File etc) throws 
Exception {
+      File artemis = new File(bin, "artemis.cmd");
+      if (artemis.exists()) {
+         File artemisCopy = new File(bkpFolder, "artemis.cmd");
+         Files.copy(artemis.toPath(), artemisCopy.toPath(), 
StandardCopyOption.REPLACE_EXISTING);
+         System.out.println("Converting artemis script. Original file backed 
up at " + bkpFolder.getAbsolutePath());

Review Comment:
   artemis.cmd rather than just artemis?
   
   Probably worth being specific about the backup file rather than the dir 
(here and in other similar places), especially if already printing the absolute 
dir path. That way its not printing the exact same value (only the dir) 
multiple times but rather the specific backup file of interest. It could print 
the dir once at the start seperately.



##########
artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/Upgrade.java:
##########
@@ -0,0 +1,299 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.activemq.artemis.cli.commands;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.io.PrintStream;
+import java.nio.file.Files;
+import java.nio.file.StandardCopyOption;
+import java.util.Iterator;
+import java.util.stream.Stream;
+
+import io.airlift.airline.Command;
+
+@Command(name = "upgrade", description = "Update an artemis instance to the 
current artemis.home, keeping all the data and broker.xml. Warning: backup your 
instance before using this command and compare the files.")
+public class Upgrade extends InstallAbstract {
+
+   /**
+    * Checks that the directory provided either exists and is writable or 
doesn't exist but can be created.
+    */
+   protected void checkDirectory() {
+      if (!directory.exists()) {
+         throw new RuntimeException(String.format("Could not find path '%s' to 
upgrade.", directory));
+      } else if (!directory.canWrite()) {
+         throw new RuntimeException(String.format("The path '%s' is not 
writable.", directory));
+      }
+   }
+
+
+   @Override
+   public Object execute(ActionContext context) throws Exception {
+      this.checkDirectory();
+      super.execute(context);
+
+      return run(context);
+   }
+
+
+   public Object run(ActionContext context) throws Exception {
+      File bkpFolder = findBackup();
+      File bkpBin = new File(bkpFolder, "bin");
+      File etcBkp = new File(bkpFolder, "etc");
+      bkpBin.mkdirs();
+      etcBkp.mkdirs();
+
+      File bin = new File(directory, "bin");
+      File etcFolder = new File(directory, etc);
+
+      if (!bin.exists()) {
+         throw new IOException(bin.getAbsolutePath() + " does not exist");
+      }
+
+      
System.out.println("*******************************************************************************************************************************");
+      System.out.println("Upgrading broker instance " + directory + " to use 
artemis.home=" + getBrokerHome());
+
+      upgradeArtemis(bkpBin, bin, etcFolder);
+      upgradeArtemisCmd(bkpBin, bin, etcFolder);
+      upgradeArtemisProfile(etcBkp, etcFolder, directory);
+      upgradeBootstrap(etcBkp, etcFolder, directory);
+      upgradeLogging(etcBkp, etcFolder, directory);
+      System.out.println();
+      System.out.println("Warning: ./artemis upgrade does not bring new 
functionality on the script itself from newer artemis versions. Please check 
for any differences on artemis script in the current release!");
+      
System.out.println("*******************************************************************************************************************************");
+
+      return null;
+   }
+
+   private void upgradeLogging(File bkpFolder, File etc, File instance) throws 
Exception {
+      File oldLogging = new File(etc, "logging.properties");
+
+      if (oldLogging.exists()) {
+         System.out.println("Moving " + oldLogging + " under " + bkpFolder);
+         File oldLoggingCopy = new File(bkpFolder, "logging.properties");
+         Files.copy(oldLogging.toPath(), oldLoggingCopy.toPath(), 
StandardCopyOption.REPLACE_EXISTING);
+         oldLogging.delete();
+         File newLogging = new File(etc, Create.ETC_LOG4J2_PROPERTIES);
+
+
+         if (!newLogging.exists()) {
+            System.out.println("Creating " + newLogging);
+            InputStream inputStream = getClass().getResourceAsStream("etc/" + 
Create.ETC_LOG4J2_PROPERTIES);
+            OutputStream outputStream = new FileOutputStream(newLogging);
+            outputStream.write(inputStream.readAllBytes());
+            inputStream.close();
+         }
+      }
+   }
+
+
+
+   private void upgradeBootstrap(File bkpFolder, File etc, File instance) 
throws Exception {
+      File bootstrap = new File(etc, "bootstrap.xml");
+      if (bootstrap.exists()) {
+         File bootstrapCopy = new File(bkpFolder, "bootstrap.xml");
+         Files.copy(bootstrap.toPath(), bootstrapCopy.toPath(), 
StandardCopyOption.REPLACE_EXISTING);
+         System.out.println("Converting bootstrap.xml. Original file backed up 
at " + bkpFolder.getAbsolutePath());
+
+         upgrade(bootstrapCopy, bootstrap, (input, iterator, out) -> {
+            if (input.trim().startsWith("<server configuration=")) {
+               return "   <server configuration=\"" + etc.toURI() + 
"/broker.xml" + "\"/>";
+            }
+
+            return input;
+         });
+      } else {
+         System.out.println("Could not find bootstrap.xml");
+      }
+   }
+
+
+   private void upgradeArtemisProfile(File bkpFolder, File etc, File instance) 
throws Exception {
+      File artemisProfile = new File(etc, "artemis.profile");
+      if (artemisProfile.exists()) {
+         File artemisProfileCopy = new File(bkpFolder, "artemis.profile");
+         Files.copy(artemisProfile.toPath(), artemisProfileCopy.toPath(), 
StandardCopyOption.REPLACE_EXISTING);
+         System.out.println("Converting artemis profile. Original file backed 
up at " + bkpFolder.getAbsolutePath());
+
+         upgrade(artemisProfileCopy, artemisProfile, (input, iterator, out) -> 
{
+
+            if (input.startsWith("ARTEMIS_HOME=")) {
+               return "ARTEMIS_HOME='" + getHome().getAbsolutePath() + "'";
+            }
+
+            if (input.startsWith("ARTEMIS_INSTANCE=")) {
+               return "ARTEMIS_INSTANCE='" + instance.getAbsolutePath() + "'";
+            }
+
+            if (input.startsWith("ARTEMIS_DATA_DIR=")) {
+               // TODO: this variable is not really used, we should get rid of 
it
+               return "ARTEMIS_DATA_DIR='" + instance.getAbsolutePath() + 
"/data'";
+            }
+
+            if (input.startsWith("ARTEMIS_ETC_DIR=")) {
+               return "ARTEMIS_ETC_DIR='" + etc.getAbsolutePath() + "'";
+            }
+
+            if (input.startsWith("ARTEMIS_OOME_DUMP=")) {
+               return "ARTEMIS_OOME_DUMP='" + instance.getAbsolutePath() + 
"/log/oom_dump.hprof'";
+            }
+
+            if (input.startsWith("ARTEMIS_INSTANCE_URI=")) {
+               return "ARTEMIS_INSTANCE_URI='" + instance.toURI() + "'";
+            }
+
+            if (input.startsWith("ARTEMIS_INSTANCE_ETC_URI=")) {
+               return "ARTEMIS_INSTANCE_ETC_URI='" + etc.toURI() + "'";
+            }
+
+            return input;
+         });
+      }
+   }
+
+   private void upgradeArtemis(File bkpFolder, File bin, File etc) throws 
Exception {
+      File artemis = new File(bin, "artemis");
+      if (artemis.exists()) {
+         File artemisCopy = new File(bkpFolder, "artemis");
+         Files.copy(artemis.toPath(), artemisCopy.toPath(), 
StandardCopyOption.REPLACE_EXISTING);
+         System.out.println("Converting artemis script. Original file backed 
up at " + bkpFolder.getAbsolutePath());
+
+         upgrade(artemisCopy, artemis, (input, iterator, out) -> {
+
+            if (input.startsWith("ARTEMIS_INSTANCE_ETC=")) {
+               return "ARTEMIS_INSTANCE_ETC='" + etc.getAbsolutePath() + "'";
+            }
+
+            if (input.trim().startsWith("-Xbootclasspath/a:\"$LOG_MANAGER:")) {
+               return null;
+            }
+
+            if (input.trim().startsWith("-Djava.util.logging.manager")) {
+               return null;
+            }
+
+            if (input.trim().startsWith("-Dlogging.configuration=")) {
+               return null;
+            }
+
+            switch (input.trim()) {
+               case "if [ -z \"$WILDFLY_COMMON\" ] ; then": {
+                  String nextLine = iterator.next().trim();
+                  if (!nextLine.startsWith("# this is the one")) {
+                     throw new RuntimeException("Script artemis was manually 
updated. Can't proceed with upgrade");
+                  }
+                  nextLine = iterator.next().trim();
+                  if (!nextLine.startsWith("WILDFLY_COMMON=")) {
+                     throw new RuntimeException("Script artemis was manually 
updated. Can't proceed with upgrade");
+                  }
+
+                  nextLine = iterator.next().trim();
+                  if (!nextLine.startsWith("fi")) {
+                     throw new RuntimeException("Script artemis was manually 
updated. Can't proceed with upgrade");
+                  }
+                  return null;
+               }
+
+               case "if [ -z \"$LOG_MANAGER\" ] ; then":
+                  return null;
+               case "# this is the one found when the server was created": {
+                  // looking for the following snippet:
+                  // 
https://github.com/apache/activemq-artemis/blob/fb1b362b473cad51ae5d05a897be02b1fa8461d4/artemis-cli/src/main/resources/org/apache/activemq/artemis/cli/commands/bin/artemis#L103-L109
+                  String nextLine = iterator.next().trim();
+                  if (!nextLine.startsWith("LOG_MANAGER=")) {
+                     throw new RuntimeException("Script artemis was manually 
updated. Can't proceed with upgrade");
+                  }
+                  nextLine = iterator.next().trim();
+                  if (!nextLine.startsWith("fi")) {
+                     throw new RuntimeException("Script artemis was manually 
updated. Can't proceed with upgrade");
+                  }
+                  return null;
+               }
+
+               case "# Set Defaults Properties":
+               case 
"ARTEMIS_LOGGING_CONF=\"$ARTEMIS_INSTANCE_ETC_URI/logging.properties\"":
+               case "ARTEMIS_LOG_MANAGER=org.jboss.logmanager.LogManager":
+               case "# finding the Log Manager":
+               case "LOG_MANAGER=`ls $ARTEMIS_HOME/lib/jboss-logmanager*jar 
2>/dev/null`":
+               case "WILDFLY_COMMON=`ls $ARTEMIS_HOME/lib/wildfly-common*jar 
2>/dev/null`":
+                  return null;
+            }
+            return input;
+         });
+      }
+   }
+
+   private void upgradeArtemisCmd(File bkpFolder, File bin, File etc) throws 
Exception {
+      File artemis = new File(bin, "artemis.cmd");
+      if (artemis.exists()) {
+         File artemisCopy = new File(bkpFolder, "artemis.cmd");
+         Files.copy(artemis.toPath(), artemisCopy.toPath(), 
StandardCopyOption.REPLACE_EXISTING);
+         System.out.println("Converting artemis script. Original file backed 
up at " + bkpFolder.getAbsolutePath());
+
+         upgrade(artemisCopy, artemis, (input, iterator, out) -> {
+            switch (input.trim()) {
+               case "rem \"Set Defaults.\"":
+               case "set 
ARTEMIS_LOGGING_CONF=%ARTEMIS_INSTANCE_ETC_URI%/logging.properties":
+               case "set ARTEMIS_LOG_MANAGER=org.jboss.logmanager.LogManager":
+               case "set JVM_ARGS=%JVM_ARGS% 
-Djava.util.logging.manager=%ARTEMIS_LOG_MANAGER%":
+               case "set JVM_ARGS=%JVM_ARGS% 
-Dlogging.configuration=%ARTEMIS_LOGGING_CONF%":
+                  return null;
+            }
+            return input;
+         });
+      }
+   }
+
+
+   private void upgrade(File sourceFile, File targetFile, IteratorFunction 
interceptorString) throws Exception {
+
+      PrintStream streamOutput = new PrintStream(new 
FileOutputStream(targetFile));
+
+      try (Stream<String> lines = Files.lines(sourceFile.toPath())) {
+
+         Iterator<String> linesIterator = lines.iterator();
+         while (linesIterator.hasNext()) {
+            String line = linesIterator.next();
+            line = interceptorString.process(line, linesIterator, 
streamOutput);
+            if (line != null) {
+               streamOutput.println(line);

Review Comment:
   The output doesnt look to be closed as this is the last apparent use of it.



##########
tests/smoke-tests/src/test/java/org/apache/activemq/artemis/tests/smoke/upgradeTest/UpgradeTest.java:
##########
@@ -0,0 +1,72 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ * <br>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <br>
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.activemq.artemis.tests.smoke.upgradeTest;
+
+import javax.jms.Connection;
+import javax.jms.ConnectionFactory;
+import javax.jms.MessageConsumer;
+import javax.jms.MessageProducer;
+import javax.jms.Session;
+import javax.jms.TextMessage;
+import java.io.File;
+
+import org.apache.activemq.artemis.tests.smoke.common.SmokeTestBase;
+import org.apache.activemq.artemis.tests.util.CFUtil;
+import org.apache.activemq.artemis.util.ServerUtil;
+import org.apache.activemq.artemis.utils.RandomUtil;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+/** This test is making sure the upgrade command would be able to upgrade a 
test I created with artemis 2.25.0 */
+public class UpgradeTest extends SmokeTestBase {

Review Comment:
   I think a far better test would be for the output of the upgrade command to 
be compared with expected output to ensure it makes [only] the expected changes 
to the config/scripts.
   
   As is the test could probably still pass even supposing the upgrade command 
did some totally incorrect and unexpected thing.



##########
artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/Upgrade.java:
##########
@@ -0,0 +1,299 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.activemq.artemis.cli.commands;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.io.PrintStream;
+import java.nio.file.Files;
+import java.nio.file.StandardCopyOption;
+import java.util.Iterator;
+import java.util.stream.Stream;
+
+import io.airlift.airline.Command;
+
+@Command(name = "upgrade", description = "Update an artemis instance to the 
current artemis.home, keeping all the data and broker.xml. Warning: backup your 
instance before using this command and compare the files.")
+public class Upgrade extends InstallAbstract {
+
+   /**
+    * Checks that the directory provided either exists and is writable or 
doesn't exist but can be created.
+    */
+   protected void checkDirectory() {
+      if (!directory.exists()) {
+         throw new RuntimeException(String.format("Could not find path '%s' to 
upgrade.", directory));
+      } else if (!directory.canWrite()) {
+         throw new RuntimeException(String.format("The path '%s' is not 
writable.", directory));
+      }
+   }
+
+
+   @Override
+   public Object execute(ActionContext context) throws Exception {
+      this.checkDirectory();
+      super.execute(context);
+
+      return run(context);
+   }
+
+
+   public Object run(ActionContext context) throws Exception {
+      File bkpFolder = findBackup();
+      File bkpBin = new File(bkpFolder, "bin");
+      File etcBkp = new File(bkpFolder, "etc");
+      bkpBin.mkdirs();
+      etcBkp.mkdirs();
+
+      File bin = new File(directory, "bin");
+      File etcFolder = new File(directory, etc);

Review Comment:
   The '--etc' option says it can be absolute or relative...this seems like it 
is assuming relative to 'directory'.



##########
tests/smoke-tests/src/main/resources/servers/toUpgradeTest/etc/artemis.profile:
##########
@@ -0,0 +1,63 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+ARTEMIS_HOME='/Users/someUser/Downloads/upgrade/apache-artemis-2.25.0'

Review Comment:
   Is this actually from 2.25.0? (EDIT: I can see form other differents that it 
is from 2.25.0). If so why that, rather than the current 2.26.0 ?



##########
artemis-cli/src/test/resources/toUpgradeTest/etc/artemis.profile:
##########
@@ -0,0 +1,63 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+ARTEMIS_HOME='/Users/someUser/Downloads/upgrade/apache-artemis-2.25.0'
+ARTEMIS_INSTANCE='/Users/someUser/Downloads/toUpgradeTest'
+ARTEMIS_DATA_DIR='/Users/someUser/Downloads/toUpgradeTest/data'
+ARTEMIS_ETC_DIR='/Users/someUser/Downloads/toUpgradeTest/etc'
+ARTEMIS_OOME_DUMP='/Users/someUser/Downloads/toUpgradeTest/log/oom_dump.hprof'

Review Comment:
   These seem like they should be set to the expected values in the target dir 
(ditto other related ones below) like they would be in other 'create' test 
cases. They shouldnt be/need to be changed? This might be related to the other 
earlier comments in the command itself.



##########
artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/Upgrade.java:
##########
@@ -0,0 +1,299 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.activemq.artemis.cli.commands;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.io.PrintStream;
+import java.nio.file.Files;
+import java.nio.file.StandardCopyOption;
+import java.util.Iterator;
+import java.util.stream.Stream;
+
+import io.airlift.airline.Command;
+
+@Command(name = "upgrade", description = "Update an artemis instance to the 
current artemis.home, keeping all the data and broker.xml. Warning: backup your 
instance before using this command and compare the files.")
+public class Upgrade extends InstallAbstract {
+
+   /**
+    * Checks that the directory provided either exists and is writable or 
doesn't exist but can be created.
+    */
+   protected void checkDirectory() {
+      if (!directory.exists()) {
+         throw new RuntimeException(String.format("Could not find path '%s' to 
upgrade.", directory));
+      } else if (!directory.canWrite()) {
+         throw new RuntimeException(String.format("The path '%s' is not 
writable.", directory));
+      }
+   }
+
+
+   @Override
+   public Object execute(ActionContext context) throws Exception {
+      this.checkDirectory();
+      super.execute(context);
+
+      return run(context);
+   }
+
+
+   public Object run(ActionContext context) throws Exception {
+      File bkpFolder = findBackup();
+      File bkpBin = new File(bkpFolder, "bin");
+      File etcBkp = new File(bkpFolder, "etc");
+      bkpBin.mkdirs();
+      etcBkp.mkdirs();
+
+      File bin = new File(directory, "bin");
+      File etcFolder = new File(directory, etc);
+
+      if (!bin.exists()) {
+         throw new IOException(bin.getAbsolutePath() + " does not exist");
+      }
+
+      
System.out.println("*******************************************************************************************************************************");
+      System.out.println("Upgrading broker instance " + directory + " to use 
artemis.home=" + getBrokerHome());
+
+      upgradeArtemis(bkpBin, bin, etcFolder);
+      upgradeArtemisCmd(bkpBin, bin, etcFolder);
+      upgradeArtemisProfile(etcBkp, etcFolder, directory);
+      upgradeBootstrap(etcBkp, etcFolder, directory);
+      upgradeLogging(etcBkp, etcFolder, directory);
+      System.out.println();
+      System.out.println("Warning: ./artemis upgrade does not bring new 
functionality on the script itself from newer artemis versions. Please check 
for any differences on artemis script in the current release!");
+      
System.out.println("*******************************************************************************************************************************");
+
+      return null;
+   }
+
+   private void upgradeLogging(File bkpFolder, File etc, File instance) throws 
Exception {
+      File oldLogging = new File(etc, "logging.properties");
+
+      if (oldLogging.exists()) {
+         System.out.println("Moving " + oldLogging + " under " + bkpFolder);
+         File oldLoggingCopy = new File(bkpFolder, "logging.properties");
+         Files.copy(oldLogging.toPath(), oldLoggingCopy.toPath(), 
StandardCopyOption.REPLACE_EXISTING);
+         oldLogging.delete();
+         File newLogging = new File(etc, Create.ETC_LOG4J2_PROPERTIES);
+
+
+         if (!newLogging.exists()) {
+            System.out.println("Creating " + newLogging);
+            InputStream inputStream = getClass().getResourceAsStream("etc/" + 
Create.ETC_LOG4J2_PROPERTIES);
+            OutputStream outputStream = new FileOutputStream(newLogging);
+            outputStream.write(inputStream.readAllBytes());
+            inputStream.close();
+         }
+      }
+   }
+
+
+
+   private void upgradeBootstrap(File bkpFolder, File etc, File instance) 
throws Exception {
+      File bootstrap = new File(etc, "bootstrap.xml");
+      if (bootstrap.exists()) {
+         File bootstrapCopy = new File(bkpFolder, "bootstrap.xml");
+         Files.copy(bootstrap.toPath(), bootstrapCopy.toPath(), 
StandardCopyOption.REPLACE_EXISTING);
+         System.out.println("Converting bootstrap.xml. Original file backed up 
at " + bkpFolder.getAbsolutePath());
+
+         upgrade(bootstrapCopy, bootstrap, (input, iterator, out) -> {
+            if (input.trim().startsWith("<server configuration=")) {
+               return "   <server configuration=\"" + etc.toURI() + 
"/broker.xml" + "\"/>";
+            }
+
+            return input;
+         });
+      } else {
+         System.out.println("Could not find bootstrap.xml");
+      }
+   }
+
+
+   private void upgradeArtemisProfile(File bkpFolder, File etc, File instance) 
throws Exception {
+      File artemisProfile = new File(etc, "artemis.profile");
+      if (artemisProfile.exists()) {
+         File artemisProfileCopy = new File(bkpFolder, "artemis.profile");
+         Files.copy(artemisProfile.toPath(), artemisProfileCopy.toPath(), 
StandardCopyOption.REPLACE_EXISTING);
+         System.out.println("Converting artemis profile. Original file backed 
up at " + bkpFolder.getAbsolutePath());
+
+         upgrade(artemisProfileCopy, artemisProfile, (input, iterator, out) -> 
{
+
+            if (input.startsWith("ARTEMIS_HOME=")) {
+               return "ARTEMIS_HOME='" + getHome().getAbsolutePath() + "'";
+            }
+
+            if (input.startsWith("ARTEMIS_INSTANCE=")) {
+               return "ARTEMIS_INSTANCE='" + instance.getAbsolutePath() + "'";
+            }
+
+            if (input.startsWith("ARTEMIS_DATA_DIR=")) {
+               // TODO: this variable is not really used, we should get rid of 
it
+               return "ARTEMIS_DATA_DIR='" + instance.getAbsolutePath() + 
"/data'";
+            }
+
+            if (input.startsWith("ARTEMIS_ETC_DIR=")) {
+               return "ARTEMIS_ETC_DIR='" + etc.getAbsolutePath() + "'";
+            }
+
+            if (input.startsWith("ARTEMIS_OOME_DUMP=")) {
+               return "ARTEMIS_OOME_DUMP='" + instance.getAbsolutePath() + 
"/log/oom_dump.hprof'";
+            }
+
+            if (input.startsWith("ARTEMIS_INSTANCE_URI=")) {
+               return "ARTEMIS_INSTANCE_URI='" + instance.toURI() + "'";
+            }
+
+            if (input.startsWith("ARTEMIS_INSTANCE_ETC_URI=")) {
+               return "ARTEMIS_INSTANCE_ETC_URI='" + etc.toURI() + "'";
+            }
+
+            return input;
+         });
+      }
+   }
+
+   private void upgradeArtemis(File bkpFolder, File bin, File etc) throws 
Exception {
+      File artemis = new File(bin, "artemis");
+      if (artemis.exists()) {
+         File artemisCopy = new File(bkpFolder, "artemis");
+         Files.copy(artemis.toPath(), artemisCopy.toPath(), 
StandardCopyOption.REPLACE_EXISTING);
+         System.out.println("Converting artemis script. Original file backed 
up at " + bkpFolder.getAbsolutePath());
+
+         upgrade(artemisCopy, artemis, (input, iterator, out) -> {
+
+            if (input.startsWith("ARTEMIS_INSTANCE_ETC=")) {
+               return "ARTEMIS_INSTANCE_ETC='" + etc.getAbsolutePath() + "'";
+            }
+
+            if (input.trim().startsWith("-Xbootclasspath/a:\"$LOG_MANAGER:")) {
+               return null;
+            }
+
+            if (input.trim().startsWith("-Djava.util.logging.manager")) {
+               return null;
+            }
+
+            if (input.trim().startsWith("-Dlogging.configuration=")) {
+               return null;
+            }
+
+            switch (input.trim()) {
+               case "if [ -z \"$WILDFLY_COMMON\" ] ; then": {
+                  String nextLine = iterator.next().trim();
+                  if (!nextLine.startsWith("# this is the one")) {
+                     throw new RuntimeException("Script artemis was manually 
updated. Can't proceed with upgrade");
+                  }
+                  nextLine = iterator.next().trim();
+                  if (!nextLine.startsWith("WILDFLY_COMMON=")) {
+                     throw new RuntimeException("Script artemis was manually 
updated. Can't proceed with upgrade");
+                  }
+
+                  nextLine = iterator.next().trim();
+                  if (!nextLine.startsWith("fi")) {
+                     throw new RuntimeException("Script artemis was manually 
updated. Can't proceed with upgrade");
+                  }
+                  return null;
+               }
+
+               case "if [ -z \"$LOG_MANAGER\" ] ; then":
+                  return null;
+               case "# this is the one found when the server was created": {
+                  // looking for the following snippet:
+                  // 
https://github.com/apache/activemq-artemis/blob/fb1b362b473cad51ae5d05a897be02b1fa8461d4/artemis-cli/src/main/resources/org/apache/activemq/artemis/cli/commands/bin/artemis#L103-L109

Review Comment:
   A release tag like 2.26.0 is nicer and more succinct than the sha of an 
unrelated commit



##########
artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/Upgrade.java:
##########
@@ -0,0 +1,299 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.activemq.artemis.cli.commands;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.io.PrintStream;
+import java.nio.file.Files;
+import java.nio.file.StandardCopyOption;
+import java.util.Iterator;
+import java.util.stream.Stream;
+
+import io.airlift.airline.Command;
+
+@Command(name = "upgrade", description = "Update an artemis instance to the 
current artemis.home, keeping all the data and broker.xml. Warning: backup your 
instance before using this command and compare the files.")
+public class Upgrade extends InstallAbstract {
+
+   /**
+    * Checks that the directory provided either exists and is writable or 
doesn't exist but can be created.
+    */
+   protected void checkDirectory() {
+      if (!directory.exists()) {
+         throw new RuntimeException(String.format("Could not find path '%s' to 
upgrade.", directory));
+      } else if (!directory.canWrite()) {
+         throw new RuntimeException(String.format("The path '%s' is not 
writable.", directory));
+      }
+   }
+
+
+   @Override
+   public Object execute(ActionContext context) throws Exception {
+      this.checkDirectory();
+      super.execute(context);
+
+      return run(context);
+   }
+
+
+   public Object run(ActionContext context) throws Exception {
+      File bkpFolder = findBackup();
+      File bkpBin = new File(bkpFolder, "bin");
+      File etcBkp = new File(bkpFolder, "etc");
+      bkpBin.mkdirs();
+      etcBkp.mkdirs();
+
+      File bin = new File(directory, "bin");
+      File etcFolder = new File(directory, etc);
+
+      if (!bin.exists()) {
+         throw new IOException(bin.getAbsolutePath() + " does not exist");
+      }
+
+      
System.out.println("*******************************************************************************************************************************");
+      System.out.println("Upgrading broker instance " + directory + " to use 
artemis.home=" + getBrokerHome());
+
+      upgradeArtemis(bkpBin, bin, etcFolder);
+      upgradeArtemisCmd(bkpBin, bin, etcFolder);
+      upgradeArtemisProfile(etcBkp, etcFolder, directory);
+      upgradeBootstrap(etcBkp, etcFolder, directory);
+      upgradeLogging(etcBkp, etcFolder, directory);
+      System.out.println();
+      System.out.println("Warning: ./artemis upgrade does not bring new 
functionality on the script itself from newer artemis versions. Please check 
for any differences on artemis script in the current release!");
+      
System.out.println("*******************************************************************************************************************************");
+
+      return null;
+   }
+
+   private void upgradeLogging(File bkpFolder, File etc, File instance) throws 
Exception {
+      File oldLogging = new File(etc, "logging.properties");
+
+      if (oldLogging.exists()) {
+         System.out.println("Moving " + oldLogging + " under " + bkpFolder);
+         File oldLoggingCopy = new File(bkpFolder, "logging.properties");
+         Files.copy(oldLogging.toPath(), oldLoggingCopy.toPath(), 
StandardCopyOption.REPLACE_EXISTING);
+         oldLogging.delete();
+         File newLogging = new File(etc, Create.ETC_LOG4J2_PROPERTIES);
+
+
+         if (!newLogging.exists()) {
+            System.out.println("Creating " + newLogging);
+            InputStream inputStream = getClass().getResourceAsStream("etc/" + 
Create.ETC_LOG4J2_PROPERTIES);
+            OutputStream outputStream = new FileOutputStream(newLogging);
+            outputStream.write(inputStream.readAllBytes());
+            inputStream.close();
+         }
+      }
+   }
+
+
+
+   private void upgradeBootstrap(File bkpFolder, File etc, File instance) 
throws Exception {
+      File bootstrap = new File(etc, "bootstrap.xml");
+      if (bootstrap.exists()) {
+         File bootstrapCopy = new File(bkpFolder, "bootstrap.xml");
+         Files.copy(bootstrap.toPath(), bootstrapCopy.toPath(), 
StandardCopyOption.REPLACE_EXISTING);
+         System.out.println("Converting bootstrap.xml. Original file backed up 
at " + bkpFolder.getAbsolutePath());
+
+         upgrade(bootstrapCopy, bootstrap, (input, iterator, out) -> {
+            if (input.trim().startsWith("<server configuration=")) {
+               return "   <server configuration=\"" + etc.toURI() + 
"/broker.xml" + "\"/>";
+            }
+
+            return input;
+         });
+      } else {
+         System.out.println("Could not find bootstrap.xml");
+      }
+   }

Review Comment:
   Is this needed? The path to the broker.xml shouldnt be changing should it?



##########
artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/Upgrade.java:
##########
@@ -0,0 +1,299 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.activemq.artemis.cli.commands;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.io.PrintStream;
+import java.nio.file.Files;
+import java.nio.file.StandardCopyOption;
+import java.util.Iterator;
+import java.util.stream.Stream;
+
+import io.airlift.airline.Command;
+
+@Command(name = "upgrade", description = "Update an artemis instance to the 
current artemis.home, keeping all the data and broker.xml. Warning: backup your 
instance before using this command and compare the files.")
+public class Upgrade extends InstallAbstract {
+
+   /**
+    * Checks that the directory provided either exists and is writable or 
doesn't exist but can be created.
+    */
+   protected void checkDirectory() {
+      if (!directory.exists()) {
+         throw new RuntimeException(String.format("Could not find path '%s' to 
upgrade.", directory));
+      } else if (!directory.canWrite()) {
+         throw new RuntimeException(String.format("The path '%s' is not 
writable.", directory));
+      }
+   }
+
+
+   @Override
+   public Object execute(ActionContext context) throws Exception {
+      this.checkDirectory();
+      super.execute(context);
+
+      return run(context);
+   }
+
+
+   public Object run(ActionContext context) throws Exception {
+      File bkpFolder = findBackup();
+      File bkpBin = new File(bkpFolder, "bin");
+      File etcBkp = new File(bkpFolder, "etc");
+      bkpBin.mkdirs();
+      etcBkp.mkdirs();
+
+      File bin = new File(directory, "bin");
+      File etcFolder = new File(directory, etc);
+
+      if (!bin.exists()) {
+         throw new IOException(bin.getAbsolutePath() + " does not exist");
+      }
+
+      
System.out.println("*******************************************************************************************************************************");
+      System.out.println("Upgrading broker instance " + directory + " to use 
artemis.home=" + getBrokerHome());
+
+      upgradeArtemis(bkpBin, bin, etcFolder);
+      upgradeArtemisCmd(bkpBin, bin, etcFolder);
+      upgradeArtemisProfile(etcBkp, etcFolder, directory);
+      upgradeBootstrap(etcBkp, etcFolder, directory);
+      upgradeLogging(etcBkp, etcFolder, directory);
+      System.out.println();
+      System.out.println("Warning: ./artemis upgrade does not bring new 
functionality on the script itself from newer artemis versions. Please check 
for any differences on artemis script in the current release!");
+      
System.out.println("*******************************************************************************************************************************");
+
+      return null;
+   }
+
+   private void upgradeLogging(File bkpFolder, File etc, File instance) throws 
Exception {
+      File oldLogging = new File(etc, "logging.properties");
+
+      if (oldLogging.exists()) {
+         System.out.println("Moving " + oldLogging + " under " + bkpFolder);
+         File oldLoggingCopy = new File(bkpFolder, "logging.properties");
+         Files.copy(oldLogging.toPath(), oldLoggingCopy.toPath(), 
StandardCopyOption.REPLACE_EXISTING);
+         oldLogging.delete();
+         File newLogging = new File(etc, Create.ETC_LOG4J2_PROPERTIES);
+
+
+         if (!newLogging.exists()) {
+            System.out.println("Creating " + newLogging);
+            InputStream inputStream = getClass().getResourceAsStream("etc/" + 
Create.ETC_LOG4J2_PROPERTIES);
+            OutputStream outputStream = new FileOutputStream(newLogging);
+            outputStream.write(inputStream.readAllBytes());
+            inputStream.close();
+         }
+      }
+   }
+
+
+
+   private void upgradeBootstrap(File bkpFolder, File etc, File instance) 
throws Exception {
+      File bootstrap = new File(etc, "bootstrap.xml");
+      if (bootstrap.exists()) {
+         File bootstrapCopy = new File(bkpFolder, "bootstrap.xml");
+         Files.copy(bootstrap.toPath(), bootstrapCopy.toPath(), 
StandardCopyOption.REPLACE_EXISTING);
+         System.out.println("Converting bootstrap.xml. Original file backed up 
at " + bkpFolder.getAbsolutePath());
+
+         upgrade(bootstrapCopy, bootstrap, (input, iterator, out) -> {
+            if (input.trim().startsWith("<server configuration=")) {
+               return "   <server configuration=\"" + etc.toURI() + 
"/broker.xml" + "\"/>";
+            }
+
+            return input;
+         });
+      } else {
+         System.out.println("Could not find bootstrap.xml");
+      }
+   }
+
+
+   private void upgradeArtemisProfile(File bkpFolder, File etc, File instance) 
throws Exception {
+      File artemisProfile = new File(etc, "artemis.profile");
+      if (artemisProfile.exists()) {
+         File artemisProfileCopy = new File(bkpFolder, "artemis.profile");
+         Files.copy(artemisProfile.toPath(), artemisProfileCopy.toPath(), 
StandardCopyOption.REPLACE_EXISTING);
+         System.out.println("Converting artemis profile. Original file backed 
up at " + bkpFolder.getAbsolutePath());
+
+         upgrade(artemisProfileCopy, artemisProfile, (input, iterator, out) -> 
{
+
+            if (input.startsWith("ARTEMIS_HOME=")) {
+               return "ARTEMIS_HOME='" + getHome().getAbsolutePath() + "'";
+            }
+
+            if (input.startsWith("ARTEMIS_INSTANCE=")) {
+               return "ARTEMIS_INSTANCE='" + instance.getAbsolutePath() + "'";
+            }
+
+            if (input.startsWith("ARTEMIS_DATA_DIR=")) {
+               // TODO: this variable is not really used, we should get rid of 
it
+               return "ARTEMIS_DATA_DIR='" + instance.getAbsolutePath() + 
"/data'";
+            }
+
+            if (input.startsWith("ARTEMIS_ETC_DIR=")) {
+               return "ARTEMIS_ETC_DIR='" + etc.getAbsolutePath() + "'";
+            }
+
+            if (input.startsWith("ARTEMIS_OOME_DUMP=")) {
+               return "ARTEMIS_OOME_DUMP='" + instance.getAbsolutePath() + 
"/log/oom_dump.hprof'";
+            }
+
+            if (input.startsWith("ARTEMIS_INSTANCE_URI=")) {
+               return "ARTEMIS_INSTANCE_URI='" + instance.toURI() + "'";
+            }
+
+            if (input.startsWith("ARTEMIS_INSTANCE_ETC_URI=")) {
+               return "ARTEMIS_INSTANCE_ETC_URI='" + etc.toURI() + "'";
+            }
+
+            return input;
+         });
+      }
+   }
+
+   private void upgradeArtemis(File bkpFolder, File bin, File etc) throws 
Exception {
+      File artemis = new File(bin, "artemis");
+      if (artemis.exists()) {
+         File artemisCopy = new File(bkpFolder, "artemis");
+         Files.copy(artemis.toPath(), artemisCopy.toPath(), 
StandardCopyOption.REPLACE_EXISTING);
+         System.out.println("Converting artemis script. Original file backed 
up at " + bkpFolder.getAbsolutePath());
+
+         upgrade(artemisCopy, artemis, (input, iterator, out) -> {
+
+            if (input.startsWith("ARTEMIS_INSTANCE_ETC=")) {
+               return "ARTEMIS_INSTANCE_ETC='" + etc.getAbsolutePath() + "'";
+            }
+
+            if (input.trim().startsWith("-Xbootclasspath/a:\"$LOG_MANAGER:")) {
+               return null;
+            }
+
+            if (input.trim().startsWith("-Djava.util.logging.manager")) {
+               return null;
+            }
+
+            if (input.trim().startsWith("-Dlogging.configuration=")) {
+               return null;
+            }
+
+            switch (input.trim()) {
+               case "if [ -z \"$WILDFLY_COMMON\" ] ; then": {
+                  String nextLine = iterator.next().trim();
+                  if (!nextLine.startsWith("# this is the one")) {
+                     throw new RuntimeException("Script artemis was manually 
updated. Can't proceed with upgrade");
+                  }
+                  nextLine = iterator.next().trim();
+                  if (!nextLine.startsWith("WILDFLY_COMMON=")) {
+                     throw new RuntimeException("Script artemis was manually 
updated. Can't proceed with upgrade");
+                  }
+
+                  nextLine = iterator.next().trim();
+                  if (!nextLine.startsWith("fi")) {
+                     throw new RuntimeException("Script artemis was manually 
updated. Can't proceed with upgrade");
+                  }
+                  return null;
+               }
+
+               case "if [ -z \"$LOG_MANAGER\" ] ; then":
+                  return null;
+               case "# this is the one found when the server was created": {
+                  // looking for the following snippet:
+                  // 
https://github.com/apache/activemq-artemis/blob/fb1b362b473cad51ae5d05a897be02b1fa8461d4/artemis-cli/src/main/resources/org/apache/activemq/artemis/cli/commands/bin/artemis#L103-L109
+                  String nextLine = iterator.next().trim();
+                  if (!nextLine.startsWith("LOG_MANAGER=")) {
+                     throw new RuntimeException("Script artemis was manually 
updated. Can't proceed with upgrade");
+                  }
+                  nextLine = iterator.next().trim();
+                  if (!nextLine.startsWith("fi")) {
+                     throw new RuntimeException("Script artemis was manually 
updated. Can't proceed with upgrade");
+                  }
+                  return null;
+               }
+
+               case "# Set Defaults Properties":
+               case 
"ARTEMIS_LOGGING_CONF=\"$ARTEMIS_INSTANCE_ETC_URI/logging.properties\"":
+               case "ARTEMIS_LOG_MANAGER=org.jboss.logmanager.LogManager":
+               case "# finding the Log Manager":
+               case "LOG_MANAGER=`ls $ARTEMIS_HOME/lib/jboss-logmanager*jar 
2>/dev/null`":
+               case "WILDFLY_COMMON=`ls $ARTEMIS_HOME/lib/wildfly-common*jar 
2>/dev/null`":
+                  return null;
+            }
+            return input;
+         });
+      }
+   }
+
+   private void upgradeArtemisCmd(File bkpFolder, File bin, File etc) throws 
Exception {
+      File artemis = new File(bin, "artemis.cmd");
+      if (artemis.exists()) {
+         File artemisCopy = new File(bkpFolder, "artemis.cmd");
+         Files.copy(artemis.toPath(), artemisCopy.toPath(), 
StandardCopyOption.REPLACE_EXISTING);
+         System.out.println("Converting artemis script. Original file backed 
up at " + bkpFolder.getAbsolutePath());
+
+         upgrade(artemisCopy, artemis, (input, iterator, out) -> {
+            switch (input.trim()) {
+               case "rem \"Set Defaults.\"":
+               case "set 
ARTEMIS_LOGGING_CONF=%ARTEMIS_INSTANCE_ETC_URI%/logging.properties":
+               case "set ARTEMIS_LOG_MANAGER=org.jboss.logmanager.LogManager":
+               case "set JVM_ARGS=%JVM_ARGS% 
-Djava.util.logging.manager=%ARTEMIS_LOG_MANAGER%":
+               case "set JVM_ARGS=%JVM_ARGS% 
-Dlogging.configuration=%ARTEMIS_LOGGING_CONF%":
+                  return null;
+            }
+            return input;
+         });
+      }
+   }
+
+
+   private void upgrade(File sourceFile, File targetFile, IteratorFunction 
interceptorString) throws Exception {
+
+      PrintStream streamOutput = new PrintStream(new 
FileOutputStream(targetFile));

Review Comment:
   This seems like it will update the file as it goes, meaning it will leave 
the file in an incomplete state if the update fails. The exception messages 
indicate they "Can't proceed with upgrade" which makes it seem more like it did 
nothing to the file on failure. Also if you get a failure and then have an 
incomplete file like this and run the upgrade again, then it will start with 
the broken file and back that up and try to update it, and then likely 
'succeed' as it doesnt contain the problem bit, but still be incomplete.
   
   It could either run the process on the file twice, first as a verification 
(not updating the output at all the first time), or alternatively as the config 
files are expected to be small it could write the outpout only to mem and then 
flush the output to the file at the end if nothing barfed.



##########
docs/user-manual/en/upgrading.md:
##########
@@ -48,3 +48,23 @@ most cases_ the instance can be upgraded to a newer version 
simply by changing
 the value of this property to the location of the new broker home. Please refer
 to the aforementioned [versions](versions.md) document for additional upgrade
 steps (if required).
+
+It is also possible to do these steps automatically as it can be seen in the 
next section.
+
+## Upgrading tool
+
+An automatic approach can be used to upgrade the instance. You may simply call 
`./artemis upgrade <old-instance>`.
+
+```shell
+cd $NEW_ARTEMIS_DOWNLOAD/bin/
+./artemis upgrade PATH_TO_UPGRADING_INSTANCE
+```
+
+artemis, artemis.profile will be updated to the new version.
+
+The tool will also update log4j2.properties (if you are migrating from a 
version previous to 2.27.0).
+
+> **Note:**
+> 
+>to avoid removing eventual user's customizations, the upgrade process won't 
automatically bring new additions to the scripts itself. Please compare your 
artemis and artemis.profile to newer versions after the upgrade.

Review Comment:
   I think this is over-selling the 'automatation', given the note at the end. 
The description here isnt clear as to what it will do. I think a user will 
struggle to know what this means until trying it and finding it doenst 
necessarily do what they expected.
   
   To have a new version file to compare with, a user would still also need to 
'artemis create' a new separate broker instance to see its config, but now 
thats in addition to running the 'artemis upgrade' command on their existing 
one to take care of some of the updates, but not others. This isnt all that 
clear from the 'upgrade' name for the command, or this documentation.
   
   That was one good thing about the previous 'create new files' approach. 
Theyd already have the new file, and theyd have their backed up old file to 
compare it with and find/port port their own modifications across if needed.



##########
artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/Upgrade.java:
##########
@@ -0,0 +1,299 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.activemq.artemis.cli.commands;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.io.PrintStream;
+import java.nio.file.Files;
+import java.nio.file.StandardCopyOption;
+import java.util.Iterator;
+import java.util.stream.Stream;
+
+import io.airlift.airline.Command;
+
+@Command(name = "upgrade", description = "Update an artemis instance to the 
current artemis.home, keeping all the data and broker.xml. Warning: backup your 
instance before using this command and compare the files.")
+public class Upgrade extends InstallAbstract {
+
+   /**
+    * Checks that the directory provided either exists and is writable or 
doesn't exist but can be created.
+    */
+   protected void checkDirectory() {
+      if (!directory.exists()) {
+         throw new RuntimeException(String.format("Could not find path '%s' to 
upgrade.", directory));
+      } else if (!directory.canWrite()) {
+         throw new RuntimeException(String.format("The path '%s' is not 
writable.", directory));
+      }
+   }
+
+
+   @Override
+   public Object execute(ActionContext context) throws Exception {
+      this.checkDirectory();
+      super.execute(context);
+
+      return run(context);
+   }
+
+
+   public Object run(ActionContext context) throws Exception {
+      File bkpFolder = findBackup();
+      File bkpBin = new File(bkpFolder, "bin");
+      File etcBkp = new File(bkpFolder, "etc");
+      bkpBin.mkdirs();
+      etcBkp.mkdirs();
+
+      File bin = new File(directory, "bin");
+      File etcFolder = new File(directory, etc);
+
+      if (!bin.exists()) {
+         throw new IOException(bin.getAbsolutePath() + " does not exist");
+      }
+
+      
System.out.println("*******************************************************************************************************************************");
+      System.out.println("Upgrading broker instance " + directory + " to use 
artemis.home=" + getBrokerHome());
+
+      upgradeArtemis(bkpBin, bin, etcFolder);
+      upgradeArtemisCmd(bkpBin, bin, etcFolder);
+      upgradeArtemisProfile(etcBkp, etcFolder, directory);
+      upgradeBootstrap(etcBkp, etcFolder, directory);
+      upgradeLogging(etcBkp, etcFolder, directory);

Review Comment:
   The service.xml and artemis.profile.cmd files arent listed in the changes 
made. Intended?
   
   E.g they have related changes, see 
https://github.com/apache/activemq-artemis/blob/main/docs/user-manual/en/02-27-00-scripts-profiles-windows.diff
   
   Also, the boostrap _didnt_ have any change when I did the update previously 
that I saw (though this was diff from 2.26.0): 
https://github.com/apache/activemq-artemis/blob/main/docs/user-manual/en/02-27-00-scripts-profiles.diff



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to