xsbt-web-plugin Running the web servelet container outside of sbt?

166 views Asked by At

I'm using the xsbt-web-plugin to host my servelet. It works fine, using container:start.

I now need it to run in the background, like a daemon, even if I hang up, and ideally, even if the machine reboots. I'd rather not have to invoke sbt.

I know that the plugin can package a WAR file, but I'm not running tomcat or anything like that. I just want to do what container:start does, but in a more robust (read: noninteractive) way.

(My goal is for a demo of dev: I'd hate for my ssh session to drop sbt, or something similar like that, while people are using the demo. But we're not ready for production yet and have no servelet infrastructure.)

1

There are 1 answers

0
earldouglas On

xsbt-web-plugin is really not meant to act as a production server (with features like automatic restarting, fault recovery, running on boot, etc.), however I understand the utility of using it this way for small-scale development purposes.

You have a couple of options:

First approach

Run sbt in a screen session, which you can (dis)connect at will without interrupting sbt.

Second approach

Override the shutdown function that triggers on sbt's exit hook, so that the container keeps running after sbt stops.

For this approach, add the following setting to your sbt configuration:

build.sbt:

onLoad in Global := { state => state }

Note that this will override the onLoad setting entirely, so in the (unlikely) case that you have it configured to do other important things, they won't happen.

Now you can launch your container either by running container:start from sbt and then exiting sbt, or simply by running sbt container:start from the command line, which will return after forking the container JVM. Give it a few seconds, then you should be able to request to localhost:8080.