Archived
Compare commits
1
Commits
v0.1.2-rc1
...
v0.1.2-rc2
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7b45fce813 |
No files matched your search
@@ -113,16 +113,7 @@ public class ServiceRestartCommand extends BaseCommand {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private int startService(Path effectiveBarnDir) throws IOException {
|
private int startService(Path effectiveBarnDir) throws IOException {
|
||||||
String javaHome = System.getProperty("java.home");
|
ProcessBuilder pb = buildDaemonCommand(effectiveBarnDir);
|
||||||
String classPath = System.getProperty("java.class.path");
|
|
||||||
|
|
||||||
ProcessBuilder pb = new ProcessBuilder(
|
|
||||||
Path.of(javaHome, "bin", "java").toString(),
|
|
||||||
"-cp", classPath,
|
|
||||||
"com.samsonmedia.barn.Main",
|
|
||||||
"service", "start", "--foreground",
|
|
||||||
"--barn-dir", effectiveBarnDir.toString()
|
|
||||||
);
|
|
||||||
|
|
||||||
if (globalOptions != null && globalOptions.getConfigPath().isPresent()) {
|
if (globalOptions != null && globalOptions.getConfigPath().isPresent()) {
|
||||||
pb.command().add("--config");
|
pb.command().add("--config");
|
||||||
@@ -162,4 +153,33 @@ public class ServiceRestartCommand extends BaseCommand {
|
|||||||
}
|
}
|
||||||
return ConfigDefaults.getDefaultBaseDir();
|
return ConfigDefaults.getDefaultBaseDir();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private ProcessBuilder buildDaemonCommand(Path effectiveBarnDir) {
|
||||||
|
// Check if running as a native image
|
||||||
|
if (isNativeImage()) {
|
||||||
|
// In native image, re-exec the current executable
|
||||||
|
String executable = ProcessHandle.current().info().command().orElse("barn");
|
||||||
|
return new ProcessBuilder(
|
||||||
|
executable,
|
||||||
|
"service", "start", "--foreground",
|
||||||
|
"--barn-dir", effectiveBarnDir.toString()
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
// Running in JVM, use java command
|
||||||
|
String javaHome = System.getProperty("java.home");
|
||||||
|
String classPath = System.getProperty("java.class.path");
|
||||||
|
return new ProcessBuilder(
|
||||||
|
Path.of(javaHome, "bin", "java").toString(),
|
||||||
|
"-cp", classPath,
|
||||||
|
"com.samsonmedia.barn.Main",
|
||||||
|
"service", "start", "--foreground",
|
||||||
|
"--barn-dir", effectiveBarnDir.toString()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean isNativeImage() {
|
||||||
|
// GraalVM sets this property when running as native image
|
||||||
|
return System.getProperty("org.graalvm.nativeimage.imagecode") != null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -99,18 +99,9 @@ public class ServiceStartCommand extends BaseCommand {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private int startDaemon(Path effectiveBarnDir) throws IOException {
|
private int startDaemon(Path effectiveBarnDir) throws IOException {
|
||||||
// For daemonizing, we re-exec with --foreground and nohup
|
// For daemonizing, we re-exec with --foreground
|
||||||
// This is a simplified approach; production would use proper daemon techniques
|
// This is a simplified approach; production would use proper daemon techniques
|
||||||
String javaHome = System.getProperty("java.home");
|
ProcessBuilder pb = buildDaemonCommand(effectiveBarnDir);
|
||||||
String classPath = System.getProperty("java.class.path");
|
|
||||||
|
|
||||||
ProcessBuilder pb = new ProcessBuilder(
|
|
||||||
Path.of(javaHome, "bin", "java").toString(),
|
|
||||||
"-cp", classPath,
|
|
||||||
"com.samsonmedia.barn.Main",
|
|
||||||
"service", "start", "--foreground",
|
|
||||||
"--barn-dir", effectiveBarnDir.toString()
|
|
||||||
);
|
|
||||||
|
|
||||||
if (globalOptions != null && globalOptions.getConfigPath().isPresent()) {
|
if (globalOptions != null && globalOptions.getConfigPath().isPresent()) {
|
||||||
pb.command().add("--config");
|
pb.command().add("--config");
|
||||||
@@ -186,4 +177,33 @@ public class ServiceStartCommand extends BaseCommand {
|
|||||||
}
|
}
|
||||||
return ConfigDefaults.getDefaultBaseDir();
|
return ConfigDefaults.getDefaultBaseDir();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private ProcessBuilder buildDaemonCommand(Path effectiveBarnDir) {
|
||||||
|
// Check if running as a native image
|
||||||
|
if (isNativeImage()) {
|
||||||
|
// In native image, re-exec the current executable
|
||||||
|
String executable = ProcessHandle.current().info().command().orElse("barn");
|
||||||
|
return new ProcessBuilder(
|
||||||
|
executable,
|
||||||
|
"service", "start", "--foreground",
|
||||||
|
"--barn-dir", effectiveBarnDir.toString()
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
// Running in JVM, use java command
|
||||||
|
String javaHome = System.getProperty("java.home");
|
||||||
|
String classPath = System.getProperty("java.class.path");
|
||||||
|
return new ProcessBuilder(
|
||||||
|
Path.of(javaHome, "bin", "java").toString(),
|
||||||
|
"-cp", classPath,
|
||||||
|
"com.samsonmedia.barn.Main",
|
||||||
|
"service", "start", "--foreground",
|
||||||
|
"--barn-dir", effectiveBarnDir.toString()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean isNativeImage() {
|
||||||
|
// GraalVM sets this property when running as native image
|
||||||
|
return System.getProperty("org.graalvm.nativeimage.imagecode") != null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user