Problems getting Vert.x to exit on Ubuntu Linux

478 views
Skip to first unread message

Jakob Jenkov

unread,
Sep 2, 2015, 4:17:04 AM9/2/15
to vert.x
What is the correct way to stop a Vert.x app that has been started with the Vert.x command line?

I am trying to create a stop script for a Vert.x app. It works on Windows, but not on Linux.

I have created a timer handler in my verticle that looks for a file, and when that file is found,
shuts down Vert.x (vertx.close()) after properly closing other resources. vertx.close() is called
from inside the deployed verticle (in the timer handler).

On windows this causes vertx to shutdown properly, but on Linux it does not. 

One big difference is that on Windows I have been running Vert.x embedded, whereas
on Linux I have been running Vert.x via the Vert.x command line tool. In fact, I just
double checked - when running Vert.x via the command line tool on Windows, it also
does not shut down. 

By not shutting down I mean it does call the verticle stop() handlers. But the Java process
doesn't exit.

So, what is the correct way to stop a Vert.x app that has been started with the Vert.x command line?

Assen Todorov

unread,
Sep 3, 2015, 3:48:56 AM9/3/15
to vert.x

Jakob Jenkov

unread,
Sep 3, 2015, 5:46:51 AM9/3/15
to vert.x
Hi, Thanks for the info.

I found a "solution" of some sorts. This piece of code seemed to shut down Vert.x - even when run from the command line:


vertx.setPeriodic(3000L, new Handler() {
@Override
public void handle(Object o) {
if(Files.exists(Paths.get("data/stop.txt"))){
System.out.println("Stopping Admin Server");
httpServer.close();
vertx.close();

try {
Logs.closeLogWriters();
} catch (IOException e) {
System.out.println("Error closing LogWriters");
e.printStackTrace();
}

try {
Files.delete(Paths.get("data/stop.txt")); //remove stop command file
} catch (IOException e) {
System.out.println("Error deleting stop command file");
e.printStackTrace();
}

try {
Thread.sleep(1800);
} catch (InterruptedException e) {
e.printStackTrace();
}

try(FileOutputStream stoppedOut = new FileOutputStream("data/stopped.txt")){
stoppedOut.write("stopped".getBytes("UTF-8"));
} catch(IOException e){
e.printStackTrace();
}
System.exit(0);
}
}
});

Asher Tarnopolski

unread,
Sep 3, 2015, 5:55:09 AM9/3/15
to vert.x
is there any special reason for your logic flow with file presence checking? 
you know, you could simply start/stop vertx as a linux service. works like a charm. there is also an example of script
in one of vertx.io blogs. 

Jakob Jenkov

unread,
Sep 3, 2015, 5:59:14 AM9/3/15
to ve...@googlegroups.com
Yes, I found that solution too somewhere - but I do all my development on Windows so I needed
a solution that works on both platforms. 

I experienced problems with close() handlers not being executed when I shutdown Vert.x, so
that is why my shutdown code (closing log files etc.) is embedded directly in the timer handler,
and not in the verticle close method.

Granted - my solution is a hack. I will use it only until I find a better / more correct solution.
The whole code base will anyways undergo many, many iterations of refactoring in the future.
But for now, it works. 

--
You received this message because you are subscribed to a topic in the Google Groups "vert.x" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/vertx/L2r1NUvJcXs/unsubscribe.
To unsubscribe from this group and all its topics, send an email to vertx+un...@googlegroups.com.
Visit this group at http://groups.google.com/group/vertx.
To view this discussion on the web, visit https://groups.google.com/d/msgid/vertx/75d089d0-ec64-4e44-b5e4-4567c4485e14%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Reply all
Reply to author
Forward
0 new messages