| 16 | import java.io.IOException; |
| 17 | |
| 18 | @Slf4j |
| 19 | public class DaemonService { |
| 20 | |
| 21 | private static final String OPEN_FROM_JAR_SIGNAL = "tmp/openFromJar"; |
| 22 | |
| 23 | @EventRegister(registerClass = StopDaemonEvent.class) |
| 24 | private static void stopDaemon(Event event) { |
| 25 | DaemonUtil.stopDaemon(); |
| 26 | try { |
| 27 | ProcessUtil.waitForProcess(Constants.LAUNCH_WRAPPER_NAME, 10); |
| 28 | } catch (IOException | InterruptedException e) { |
| 29 | throw new RuntimeException(e); |
| 30 | } |
| 31 | } |
| 32 | |
| 33 | @EventRegister(registerClass = StartDaemonEvent.class) |
| 34 | private static void startDaemon(Event event) { |
| 35 | File launcher = new File("..", Constants.LAUNCH_WRAPPER_NAME); |
| 36 | if (IsDebug.isDebug()) { |
| 37 | log.info("启动守护进程" + Constants.LAUNCH_WRAPPER_NAME); |
| 38 | return; |
| 39 | } |
| 40 | File openFromJar = new File(OPEN_FROM_JAR_SIGNAL); |
| 41 | if (!openFromJar.exists()) { |
| 42 | try { |
| 43 | if (!openFromJar.createNewFile()) { |
| 44 | log.error("error create open from jar file signal. File: " + OPEN_FROM_JAR_SIGNAL); |
| 45 | } |
| 46 | } catch (IOException ex) { |
| 47 | log.error("error: {}", ex.getMessage(), ex); |
| 48 | } |
| 49 | } |
| 50 | EventManagement.getInstance().putEvent(new OpenFileEvent(OpenFileEvent.OpenStatus.WITH_ADMIN, launcher.getAbsolutePath())); |
| 51 | } |
| 52 | } |
nothing calls this directly
no outgoing calls
no test coverage detected