How to deploy a dropwizard application
Asked Answered
P

3

9

I read some comments about the build of dropwizard applications: [1] "Dropwizard is designed to run as a JAR, not as a WAR file." and [2]"You can't do this. Dropwizard embeds Jetty. You should look into just using Jersey as a standard web application.", so, my questions are:

1 - How to deploy a jar file in a production environment?

2 - How will I manage the service? for example, is there a way to monitor the healthy of the application? if the application falls down how can I restart it again automatically?

[1] How to create a war from dropwizard app? [2] Dropwizard in tomcat container

Purebred answered 2/10, 2014 at 16:25 Comment(0)
E
3

You can use tools like runit or systemd to manage your dropwizard app on Linux. They can do things like make sure it starts when the system starts up, and can help with detecting failures. There is a bit of scripting involved.

You can point a monitoring tool at the healthcheck URL of your app to send alerts when it's down.

For deployment, I prefer to package apps using the system packaging format, .deb (Debian-based systems, including Ubuntu), or .rpm (RedHat based systems). Use the fpm package builder to create it, and include your runit files (or whatever), and scripts to copy the jar file somewhere on the target system. If you have a private package repository, you can put builds of your app into it, and installation becomes a matter of "apt-get install myapp" or "yum install myapp". Otherwise, drop the package onto your target server and run "rpm -i myapp.rpm" or similar.

Electrometallurgy answered 3/10, 2014 at 12:34 Comment(1)
If you're on Ubuntu, Jamie Furness has written a great maven plugin dropwizard-debpkg-maven-plugin which can package your app and config for you as a .deb file, and create the appropriate init & upstart scripts for you.Excitable
P
2

After running mvn package of your source directory, the said jar file is created in the target directory by maven.

Just upload this jar file to a directory of your liking on the server, say /opt/myapplication/.

The jar file can be executed on the server with java -jar JARFILE, make sure you have java installed there. That's it, basically.

Now when you run this in production, you want to have the process supervised (and restarted if it fails) and started automatically on bootup. For this, look into your servers startup-system (systemd was mentioned before for those linux distributions that support it, but on current debian/ubuntu versions you have ATM still other boot mechanisms, you probably need to write a start script for /etc/init.d/myapplication).

Health checks are - as mentioned before - integrated in the dropwizard app, you simply request the health check url on a regular base. In professional environments, you should have a tool like nagios that you could point to the URL.

Proctor answered 4/10, 2014 at 4:14 Comment(0)
D
0

If your server is unix, you can build fpm packages to install your service on server. Just build fpm, copy to server and install it.

Or use fabric (http://www.fabfile.org/).

Decury answered 9/10, 2014 at 7:44 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.