fix: 调整 pid ,延迟RtkrcvConfigService

This commit is contained in:
yarnom 2025-10-30 16:12:37 +08:00
parent 2cb32e8923
commit 1aec89c221
2 changed files with 17 additions and 5 deletions

View File

@ -28,7 +28,7 @@ public class GroupRtkScheduler {
private static class RuntimeInfo {
volatile String state = "stopped"; // starting|running|stopped|failed
volatile Integer pid;
volatile Long pid;
volatile Integer workPort; // reserved for future use
volatile String confPath;
volatile LocalDateTime startedAt;
@ -76,7 +76,7 @@ public class GroupRtkScheduler {
LOGGER.info("[scheduler] starting rtkrcv for group {} with {}", groupId, conf);
Process p = pb.start();
rt.process = p;
rt.pid = tryGetPidCompat(p);
rt.pid = safePid(p);
rt.state = "starting";
rt.startedAt = LocalDateTime.now();
startReader(groupId, rt);
@ -174,14 +174,20 @@ public class GroupRtkScheduler {
rt.readerThread.start();
}
private Integer tryGetPidCompat(Process p) {
private Long safePid(Process p) {
try {
// Try Java 9+ via reflection (keeps Java 8 compilation compatible)
java.lang.reflect.Method m = Process.class.getMethod("pid");
Object v = m.invoke(p);
if (v instanceof Number) return ((Number) v).longValue();
} catch (Exception ignore) {}
try {
// Fallback: reflect private 'pid' field (UNIXProcess on Java 8)
java.lang.reflect.Field f = p.getClass().getDeclaredField("pid");
f.setAccessible(true);
Object v = f.get(p);
if (v instanceof Integer) return (Integer) v;
if (v instanceof Number) return ((Number) v).longValue();
} catch (Exception ignore) {}
return null;
}
}

View File

@ -46,6 +46,8 @@ public class RtkClusterService implements ApplicationRunner {
private int startDelaySec;
@Value("${rtkrcv.bin:rtkrcv}")
private String rtkBinary;
@Value("${rtkcluster.autoStart:false}")
private boolean autoStart;
@Autowired
private RtkrcvProfileMapper profileMapper;
@ -68,6 +70,10 @@ public class RtkClusterService implements ApplicationRunner {
@Override
public void run(ApplicationArguments args) {
if (!autoStart) {
LOGGER.info("RtkClusterService autoStart disabled; skipping bootstrap.");
return;
}
if (startDelaySec > 0) {
try {
LOGGER.info("RtkClusterService delayed start {}s to wait for 9902/9903", startDelaySec);