The Unified and Autonomous Development Platform
fix: Preserve legacy launchd labels during wrapper migration
Robin Shen65a8f36adec7
diff --git a/server-core/src/main/java/io/onedev/server/commandhandler/Upgrade.java b/server-core/src/main/java/io/onedev/server/commandhandler/Upgrade.javaindex 5f0e5c24d1..b040ff575c 100644--- a/server-core/src/main/java/io/onedev/server/commandhandler/Upgrade.java+++ b/server-core/src/main/java/io/onedev/server/commandhandler/Upgrade.java@@ -21,6 +21,7 @@ import java.util.List;import java.util.Properties;import java.util.concurrent.Callable;import java.util.regex.Matcher;+import java.util.regex.Pattern;import jakarta.inject.Singleton;@@ -985,9 +986,7 @@ public class Upgrade extends AbstractPlugin {try {File wrapperConfFile = new File(upgradeDir, "conf/wrapper.conf");String wrapperConf = FileUtils.readFileToString(wrapperConfFile, UTF_8);- wrapperConf = wrapperConf.replaceAll(- "(?m)^(\\h*wrapper\\.java\\.mainclass\\h*=\\h*)[\\w.]+\\.WrapperSimpleApp\\h*$",- "$1io.onedev.wrapper.WrapperSimpleApp");+ wrapperConf = migrateWrapperConf(wrapperConf);wrapperConf = Strings.CS.replace(wrapperConf, "com.gitplex.commons.bootstrap.Bootstrap","io.onedev.commons.launcher.bootstrap.Bootstrap");wrapperConf = Strings.CS.replace(wrapperConf, "com.gitplex.launcher.bootstrap.Bootstrap",@@ -1199,6 +1198,27 @@ public class Upgrade extends AbstractPlugin {restoreExecutables(upgradeDir);}+ static String migrateWrapperConf(String wrapperConf) {+ var mainClassPattern = Pattern.compile(+ "(?m)^(\\h*wrapper\\.java\\.mainclass\\h*=\\h*)([\\w.]+\\.WrapperSimpleApp)(\\h*(?:#.*)?)$");+ var mainClassMatcher = mainClassPattern.matcher(wrapperConf);+ String mainClass = null;+ while (mainClassMatcher.find())+ mainClass = mainClassMatcher.group(2);+ if (mainClass != null && !mainClass.equals("io.onedev.wrapper.WrapperSimpleApp")+ && !Pattern.compile("(?m)^\\h*wrapper\\.launchd\\.label\\h*=").matcher(wrapperConf).find()) {+ // JSW installations (16.8.8 and earlier) keep their existing launchd plist.+ // Detect the old bridge before replacing it so subsequent upgrades are idempotent.+ var nameMatcher = Pattern.compile("(?m)^\\h*wrapper\\.name\\h*=([^\\r\\n#]*)").matcher(wrapperConf);+ String name = null;+ while (nameMatcher.find())+ name = nameMatcher.group(1).trim();+ if (name != null && !name.isEmpty())+ wrapperConf += lineSeparator() + "wrapper.launchd.label=org.tanukisoftware.wrapper." + name;+ }+ return mainClassPattern.matcher(wrapperConf).replaceAll("$1io.onedev.wrapper.WrapperSimpleApp$3");+ }+protected void cleanAndCopy(File srcDir, File destDir) {try {FileUtils.cleanDir(destDir);diff --git a/server-core/src/test/java/io/onedev/server/commandhandler/UpgradeWrapperConfTest.java b/server-core/src/test/java/io/onedev/server/commandhandler/UpgradeWrapperConfTest.javanew file mode 100644index 0000000000..db733c8e9c--- /dev/null+++ b/server-core/src/test/java/io/onedev/server/commandhandler/UpgradeWrapperConfTest.java@@ -0,0 +1,43 @@+package io.onedev.server.commandhandler;++import static org.junit.jupiter.api.Assertions.assertEquals;+import static org.junit.jupiter.api.Assertions.assertFalse;+import static org.junit.jupiter.api.Assertions.assertTrue;++import org.junit.jupiter.api.Test;++class UpgradeWrapperConfTest {++ @Test+ void preservesLegacyLaunchdIdentityAcrossUpgrades() {+ var config = "wrapper.java.mainclass=org.tanukisoftware.wrapper.WrapperSimpleApp\r\n"+ + "wrapper.name=onedev\r\n";+ var migrated = Upgrade.migrateWrapperConf(config);+ assertTrue(migrated.contains("wrapper.java.mainclass=io.onedev.wrapper.WrapperSimpleApp"));+ assertTrue(migrated.contains("wrapper.launchd.label=org.tanukisoftware.wrapper.onedev"));+ assertTrue(migrated.contains("wrapper.name=onedev\r\n"));+ assertEquals(migrated, Upgrade.migrateWrapperConf(migrated));+ }++ @Test+ void handlesCustomNamesWhitespaceAndComments() {+ var config = " wrapper.java.mainclass = org.tanukisoftware.wrapper.WrapperSimpleApp # bridge\n"+ + "#wrapper.launchd.label=example\nwrapper.name=old-name\n wrapper.name = custom.server # service\n";+ var migrated = Upgrade.migrateWrapperConf(config);+ assertTrue(migrated.contains("io.onedev.wrapper.WrapperSimpleApp # bridge"));+ assertTrue(migrated.contains("wrapper.launchd.label=org.tanukisoftware.wrapper.custom.server"));+ assertFalse(migrated.contains("org.tanukisoftware.wrapper.old-name"));+ }++ @Test+ void keepsExplicitLabelAndNativeConfigurations() {+ var config = "wrapper.java.mainclass=org.tanukisoftware.wrapper.WrapperSimpleApp\n"+ + "wrapper.name=onedev\n wrapper.launchd.label = custom.label\n";+ assertEquals(config.replace("org.tanukisoftware.wrapper.WrapperSimpleApp", "io.onedev.wrapper.WrapperSimpleApp"),+ Upgrade.migrateWrapperConf(config));+ var nativeConfig = "wrapper.java.mainclass=io.onedev.wrapper.WrapperSimpleApp\nwrapper.name=onedev.server\n";+ assertEquals(nativeConfig, Upgrade.migrateWrapperConf(nativeConfig));+ assertEquals(nativeConfig + "wrapper.launchd.label=io.onedev.server\n",+ Upgrade.migrateWrapperConf(nativeConfig + "wrapper.launchd.label=io.onedev.server\n"));+ }+}diff --git a/server-product/system/incompatibilities/incompatibilities.md b/server-product/system/incompatibilities/incompatibilities.mdindex a6aa0c6cab..fa7b43517c 100644--- a/server-product/system/incompatibilities/incompatibilities.md+++ b/server-product/system/incompatibilities/incompatibilities.md@@ -1,9 +1,3 @@-# 16.8.9--### macOS Services--OneDev now uses its own service wrapper instead of Java Service Wrapper (JSW). When upgrading from 16.8.8 or earlier, existing macOS services must be reinstalled because the launchd labels have changed. **Before upgrading**, stop and remove the service using the old installation: `sudo bin/server.sh stop`, then `sudo bin/server.sh remove`. After upgrading, run `sudo bin/server.sh install`, then `sudo bin/server.sh start`. When migrating an agent to the new wrapper, follow the same sequence using `bin/agent.sh`.-# 16.8.4### CI/CDdiff --git a/server-product/wrapper/README.md b/server-product/wrapper/README.mdindex 42b8f1d033..eeb1beb82d 100644--- a/server-product/wrapper/README.md+++ b/server-product/wrapper/README.md@@ -152,19 +152,26 @@ The Java lifecycle API is `io.onedev.wrapper.WrapperManager`, with`io.onedev.wrapper.WrapperSimpleApp`. Update the wrapper and application jarstogether when migrating from an earlier Java API package.Server upgrades replace boot files and scripts while retaining `wrapper.conf`-and updating its lifecycle bridge class. When upgrading from JSW (16.8.8 or-earlier) on macOS, stop and remove the service using the old launcher before-upgrading, then install and start it using the new launcher. The old JSW launchd-label is not migrated automatically. Existing Linux and Windows service names-are retained. Fresh installations use the new names and labels documented above.-Intel Macs are not supported by the new wrapper.--Existing agents update only application jars: migrating their wrapper requires-stopping them and replacing `boot` and `bin` from a new agent distribution while-retaining configuration. Set `wrapper.java.mainclass=io.onedev.wrapper.WrapperSimpleApp`-and, on macOS, remove the service with the old launcher before replacing these-files, then install and start it with the new launcher. Newly downloaded agents-use Wrapper.+and updating its lifecycle bridge class. When migrating a JSW configuration+(16.8.8 or earlier), the upgrader sets a missing `wrapper.launchd.label` to+`org.tanukisoftware.wrapper.<existing wrapper.name>`. Explicit labels are preserved.+This retains the standard old macOS registration and its `launchdinternal`+launcher argument, so an Apple Silicon service can be stopped before the upgrade+and started afterward without uninstalling/reinstalling it. Existing Linux and+Windows service names are also retained. Fresh installations use the new names+and labels documented above. Intel Macs are not supported by the new wrapper.++Existing agents update only application jars and continue using their installed+wrapper. The agent supports both the new WrapperManager and JSW's WrapperManager+for restart and stop requests, so automatic application updates do not require+migrating the native wrapper or reinstalling the service.++To migrate an existing agent's native wrapper, stop it and replace `boot` and+`bin` from a new agent distribution while retaining configuration. Set+`wrapper.java.mainclass=io.onedev.wrapper.WrapperSimpleApp` and, on macOS, set+`wrapper.launchd.label` to the installed JSW label (normally+`org.tanukisoftware.wrapper.onedevagent`). Keep the old `wrapper.name` and launcher+path to retain the existing service registration. Newly downloaded agents use Wrapper.Review the standalone project's configuration compatibility list before migratingcustom JSW features. Native SCM, launchd, and systemd acceptance testing is still