2424import java .io .InputStreamReader ;
2525
2626import lombok .SneakyThrows ;
27+ import lombok .extern .slf4j .Slf4j ;
2728import lombok .val ;
2829
30+ @ Slf4j
2931final class LocalEpmdHelper {
3032
3133 @ SneakyThrows
@@ -44,40 +46,47 @@ static boolean exists () {
4446 return process .exitValue () == 0 ;
4547 }
4648
47- @ SneakyThrows
4849 static void run () {
4950 if (isRunning ()) {
5051 kill ();
5152 }
5253
5354 val builder = new ProcessBuilder ("epmd" , "-daemon" , "-relaxed_command_check" );
54- val process = builder .start ();
55- if (!process .waitFor (1 , MINUTES )) {
56- process .destroy ();
57- throw new RuntimeException ("Local EPMD daemon doesn't respond" );
58- }
59- if (process .exitValue () != 0 ) {
60- process .destroy ();
61- throw new RuntimeException ("Local EPMD daemon doesn't run" );
55+ try {
56+ val process = builder .start ();
57+ if (!process .waitFor (1 , MINUTES )) {
58+ process .destroy ();
59+ throw new RuntimeException ("Local EPMD daemon doesn't respond" );
60+ }
61+ if (process .exitValue () != 0 ) {
62+ process .destroy ();
63+ throw new RuntimeException ("Local EPMD daemon doesn't run" );
64+ }
65+ SECONDS .sleep (1 );
66+ } catch (Exception ex ) {
67+ log .error ("starting EPMD error" , ex );
6268 }
63- SECONDS .sleep (1 );
6469 }
6570
66- @ SneakyThrows
6771 static void kill () {
6872 if (!isRunning ()) {
6973 return ;
7074 }
75+
7176 val pids = getEpmdPids ();
72- val builder = new ProcessBuilder ("kill" , "-9" , pids );
73- val process = builder .start ();
74- if (!process .waitFor (1 , MINUTES )) {
75- process .destroy ();
76- throw new RuntimeException ("Killing local EPMD is too long, pid: " + pids );
77- }
78- if (process .exitValue () != 0 ) {
79- process .destroy ();
80- throw new RuntimeException ("Couldn't kill local EPMD with PID " + pids );
77+ val builder = new ProcessBuilder ("kill" , "-s 9" , pids );
78+ try {
79+ val process = builder .start ();
80+ if (!process .waitFor (1 , MINUTES )) {
81+ process .destroy ();
82+ throw new RuntimeException ("Killing local EPMD is too long, pid: " + pids );
83+ }
84+ if (process .exitValue () != 0 ) {
85+ process .destroy ();
86+ throw new RuntimeException ("Couldn't kill local EPMD with PID " + pids );
87+ }
88+ } catch (Exception ex ) {
89+ log .error ("killing EPMD error" , ex );
8190 }
8291 }
8392
0 commit comments