| skipped 178 lines |
179 | 179 | | if (oldAppVersion == null || !oldAppVersion.equals(AppLoader.getProduct().getVersion())) { |
180 | 180 | | logger.info("Upgrading {}...", upgradeDir.getAbsolutePath()); |
181 | 181 | | |
182 | | - | if (Bootstrap.isServerRunning(upgradeDir)) { |
183 | | - | logger.error("Please stop server running at \"{}\" before upgrading", upgradeDir.getAbsolutePath()); |
184 | | - | System.exit(1); |
185 | | - | } |
186 | | - | if (Bootstrap.isServerRunning(Bootstrap.installDir)) { |
187 | | - | logger.error("Please stop server running at \"{}\" before upgrading", Bootstrap.installDir.getAbsolutePath()); |
| 182 | + | if (isServerRunning(upgradeDir) || isServerRunning(Bootstrap.installDir)) { |
| 183 | + | logger.error("Please stop server before upgrading"); |
188 | 184 | | System.exit(1); |
189 | 185 | | } |
190 | 186 | | |
| skipped 12 lines |
203 | 199 | | } |
204 | 200 | | } |
205 | 201 | | |
| 202 | + | File statusDir = new File(upgradeDir, "status"); |
| 203 | + | if (statusDir.exists()) |
| 204 | + | FileUtils.cleanDir(statusDir); |
| 205 | + | |
206 | 206 | | AtomicInteger oldDataVersion = new AtomicInteger(0); |
207 | 207 | | |
208 | 208 | | int ret = buildCommandline(upgradeDir, "check-data-version").execute(new LineConsumer() { |
| skipped 77 lines |
286 | 286 | | FileUtils.deleteDir(new File(upgradeDir, "sampledb"), 3); |
287 | 287 | | } else { |
288 | 288 | | logger.info("Cleaning database with old program..."); |
| 289 | + | |
289 | 290 | | ret = buildCommandline(upgradeDir, "clean-db").execute(new LineConsumer() { |
290 | 291 | | |
291 | 292 | | @Override |
| skipped 103 lines |
395 | 396 | | } else { |
396 | 397 | | logger.info("Populating {}...", upgradeDir.getAbsolutePath()); |
397 | 398 | | |
398 | | - | if (Bootstrap.isServerRunning(Bootstrap.installDir)) { |
399 | | - | logger.error("Please stop server running at \"{}\" before populating", Bootstrap.installDir.getAbsolutePath()); |
| 399 | + | if (isServerRunning(Bootstrap.installDir)) { |
| 400 | + | logger.error("Please stop server before populating"); |
400 | 401 | | System.exit(1); |
401 | 402 | | } |
402 | 403 | | |
403 | 404 | | try { |
404 | 405 | | FileUtils.copyDirectory(Bootstrap.installDir, upgradeDir); |
| 406 | + | FileUtils.cleanDir(new File(upgradeDir, "logs")); |
405 | 407 | | restoreExecutables(upgradeDir); |
406 | 408 | | logger.info("Successfully populated {}", upgradeDir.getAbsolutePath()); |
407 | 409 | | System.exit(0); |
| skipped 10 lines |
418 | 420 | | |
419 | 421 | | File siteServerScriptFile = new File(upgradeDir, "bin/server.sh"); |
420 | 422 | | for (File file: Bootstrap.getBinDir().listFiles()) { |
421 | | - | try { |
422 | | - | String serverScript = null; |
423 | | - | if (file.getName().equals("server.sh")) { |
424 | | - | String siteRunAsUserLine = null; |
425 | | - | for (String line: (List<String>)FileUtils.readLines(siteServerScriptFile, Charset.defaultCharset())) { |
426 | | - | if (line.contains("RUN_AS_USER")) { |
427 | | - | siteRunAsUserLine = line; |
428 | | - | break; |
429 | | - | } |
430 | | - | } |
431 | | - | if (siteRunAsUserLine != null) { |
432 | | - | String newRunAsUserLine = null; |
433 | | - | for (String line: (List<String>)FileUtils.readLines(file, Charset.defaultCharset())) { |
| 423 | + | if (!file.getName().endsWith(".pid") && !file.getName().endsWith(".status")) { |
| 424 | + | try { |
| 425 | + | String serverScript = null; |
| 426 | + | if (file.getName().equals("server.sh")) { |
| 427 | + | String siteRunAsUserLine = null; |
| 428 | + | for (String line: (List<String>)FileUtils.readLines(siteServerScriptFile, Charset.defaultCharset())) { |
434 | 429 | | if (line.contains("RUN_AS_USER")) { |
435 | | - | newRunAsUserLine = line; |
| 430 | + | siteRunAsUserLine = line; |
436 | 431 | | break; |
437 | 432 | | } |
438 | 433 | | } |
439 | | - | if (newRunAsUserLine != null) { |
440 | | - | serverScript = FileUtils.readFileToString(file, Charset.defaultCharset()); |
441 | | - | serverScript = StringUtils.replace(serverScript, newRunAsUserLine, siteRunAsUserLine); |
| 434 | + | if (siteRunAsUserLine != null) { |
| 435 | + | String newRunAsUserLine = null; |
| 436 | + | for (String line: (List<String>)FileUtils.readLines(file, Charset.defaultCharset())) { |
| 437 | + | if (line.contains("RUN_AS_USER")) { |
| 438 | + | newRunAsUserLine = line; |
| 439 | + | break; |
| 440 | + | } |
| 441 | + | } |
| 442 | + | if (newRunAsUserLine != null) { |
| 443 | + | serverScript = FileUtils.readFileToString(file, Charset.defaultCharset()); |
| 444 | + | serverScript = StringUtils.replace(serverScript, newRunAsUserLine, siteRunAsUserLine); |
| 445 | + | } |
442 | 446 | | } |
443 | 447 | | } |
| 448 | + | if (serverScript != null) |
| 449 | + | FileUtils.writeStringToFile(siteServerScriptFile, serverScript, Charset.defaultCharset()); |
| 450 | + | else |
| 451 | + | FileUtils.copyFile(file, new File(upgradeDir, "bin/" + file.getName())); |
| 452 | + | } catch (IOException e) { |
| 453 | + | throw new RuntimeException(e); |
444 | 454 | | } |
445 | | - | if (serverScript != null) |
446 | | - | FileUtils.writeStringToFile(siteServerScriptFile, serverScript, Charset.defaultCharset()); |
447 | | - | else |
448 | | - | FileUtils.copyFile(file, new File(upgradeDir, "bin/" + file.getName())); |
449 | | - | } catch (IOException e) { |
450 | | - | throw new RuntimeException(e); |
451 | 455 | | } |
452 | 456 | | } |
453 | 457 | | |
| skipped 14 lines |
468 | 472 | | if (new File(upgradeDir, "bin/reset_admin_password.sh").exists()) |
469 | 473 | | FileUtils.deleteFile(new File(upgradeDir, "bin/reset_admin_password.sh")); |
470 | 474 | | |
| 475 | + | FileUtils.deleteDir(new File(upgradeDir, "status")); |
| 476 | + | |
471 | 477 | | cleanAndCopy(Bootstrap.getBootDir(), new File(upgradeDir, "boot")); |
| 478 | + | cleanAndCopy(new File(Bootstrap.installDir, "agent"), new File(upgradeDir, "agent")); |
472 | 479 | | if (new File(upgradeDir, "boot/system.classpath").exists()) |
473 | 480 | | FileUtils.deleteFile(new File(upgradeDir, "boot/system.classpath")); |
474 | 481 | | |
475 | 482 | | cleanAndCopy(Bootstrap.getLibDir(), new File(upgradeDir, "lib")); |
476 | 483 | | for (File file: new File(Bootstrap.getSiteDir(), "avatars").listFiles()) { |
477 | | - | try { |
478 | | - | FileUtils.copyFileToDirectory(file, new File(upgradeDir, "site/avatars")); |
479 | | - | } catch (IOException e) { |
480 | | - | throw new RuntimeException(e); |
| 484 | + | if (file.isFile()) { |
| 485 | + | try { |
| 486 | + | FileUtils.copyFileToDirectory(file, new File(upgradeDir, "site/avatars")); |
| 487 | + | } catch (IOException e) { |
| 488 | + | throw new RuntimeException(e); |
| 489 | + | } |
481 | 490 | | } |
482 | 491 | | } |
483 | 492 | | File uploadedDir = new File(upgradeDir, "site/avatars/uploaded"); |
| skipped 23 lines |
507 | 516 | | "io.onedev.commons.launcher.bootstrap.Bootstrap"); |
508 | 517 | | wrapperConf = StringUtils.replace(wrapperConf, "io.onedev.commons.launcher.bootstrap.Bootstrap", |
509 | 518 | | "io.onedev.commons.bootstrap.Bootstrap"); |
| 519 | + | wrapperConf = StringUtils.replace(wrapperConf, "wrapper.pidfile=../status/onedev.pid", ""); |
| 520 | + | |
510 | 521 | | FileUtils.writeStringToFile(wrapperConfFile, wrapperConf, StandardCharsets.UTF_8); |
511 | 522 | | |
512 | 523 | | File hibernatePropsFile = new File(upgradeDir, "conf/hibernate.properties"); |
| skipped 91 lines |