fix: 调整 pid ,延迟RtkrcvConfigService
This commit is contained in:
parent
2cb32e8923
commit
1aec89c221
@ -28,7 +28,7 @@ public class GroupRtkScheduler {
|
|||||||
|
|
||||||
private static class RuntimeInfo {
|
private static class RuntimeInfo {
|
||||||
volatile String state = "stopped"; // starting|running|stopped|failed
|
volatile String state = "stopped"; // starting|running|stopped|failed
|
||||||
volatile Integer pid;
|
volatile Long pid;
|
||||||
volatile Integer workPort; // reserved for future use
|
volatile Integer workPort; // reserved for future use
|
||||||
volatile String confPath;
|
volatile String confPath;
|
||||||
volatile LocalDateTime startedAt;
|
volatile LocalDateTime startedAt;
|
||||||
@ -76,7 +76,7 @@ public class GroupRtkScheduler {
|
|||||||
LOGGER.info("[scheduler] starting rtkrcv for group {} with {}", groupId, conf);
|
LOGGER.info("[scheduler] starting rtkrcv for group {} with {}", groupId, conf);
|
||||||
Process p = pb.start();
|
Process p = pb.start();
|
||||||
rt.process = p;
|
rt.process = p;
|
||||||
rt.pid = tryGetPidCompat(p);
|
rt.pid = safePid(p);
|
||||||
rt.state = "starting";
|
rt.state = "starting";
|
||||||
rt.startedAt = LocalDateTime.now();
|
rt.startedAt = LocalDateTime.now();
|
||||||
startReader(groupId, rt);
|
startReader(groupId, rt);
|
||||||
@ -174,14 +174,20 @@ public class GroupRtkScheduler {
|
|||||||
rt.readerThread.start();
|
rt.readerThread.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
private Integer tryGetPidCompat(Process p) {
|
private Long safePid(Process p) {
|
||||||
try {
|
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");
|
java.lang.reflect.Field f = p.getClass().getDeclaredField("pid");
|
||||||
f.setAccessible(true);
|
f.setAccessible(true);
|
||||||
Object v = f.get(p);
|
Object v = f.get(p);
|
||||||
if (v instanceof Integer) return (Integer) v;
|
if (v instanceof Number) return ((Number) v).longValue();
|
||||||
} catch (Exception ignore) {}
|
} catch (Exception ignore) {}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -46,6 +46,8 @@ public class RtkClusterService implements ApplicationRunner {
|
|||||||
private int startDelaySec;
|
private int startDelaySec;
|
||||||
@Value("${rtkrcv.bin:rtkrcv}")
|
@Value("${rtkrcv.bin:rtkrcv}")
|
||||||
private String rtkBinary;
|
private String rtkBinary;
|
||||||
|
@Value("${rtkcluster.autoStart:false}")
|
||||||
|
private boolean autoStart;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private RtkrcvProfileMapper profileMapper;
|
private RtkrcvProfileMapper profileMapper;
|
||||||
@ -68,6 +70,10 @@ public class RtkClusterService implements ApplicationRunner {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run(ApplicationArguments args) {
|
public void run(ApplicationArguments args) {
|
||||||
|
if (!autoStart) {
|
||||||
|
LOGGER.info("RtkClusterService autoStart disabled; skipping bootstrap.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (startDelaySec > 0) {
|
if (startDelaySec > 0) {
|
||||||
try {
|
try {
|
||||||
LOGGER.info("RtkClusterService delayed start {}s to wait for 9902/9903", startDelaySec);
|
LOGGER.info("RtkClusterService delayed start {}s to wait for 9902/9903", startDelaySec);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user