Question

I’m using a Ubuntu VPS to host a couple of Ring web apps. I have a separate GNU Screen window for each one, and I start and stop them using lein run and ^C, respectively. This works, but it feels amateurish and if anything goes wrong these services won’t be restarted automatically.

I’d like to set something up so that I can start and stop my apps using Ubuntu’s service command (which I already use to start and stop nginx). Is there some kind of shortcut I can use to get these apps working with the service command? For example, is there some Leiningen- or Ring-friendly template into which I can just insert my application’s path? Failing that, what would be the best practices for writing my own service script to integrate with Jetty?

Was it helpful?

Solution

It depends on whether you want your service to run straight from your project directory, or whether you want to go through the intermediate step of creating and installing a build artifact.

Certainly during development it's more convenient to use lein run from your project directory. For the sake of repeatability, I'd recommend using the second approach for production systems.

The general approach would be to use the lein uberjar task to create a stand-alone JAR file. From there, it's pretty straightforward (though somewhat tedious) to create a script you can stick in /etc/init.d to run the JAR file, either directly via java or using jsvc.

It looks like there's a Leiningen plugin (lein-init-script) to automate the process of generating the service script, though I don't have any experience with it. You'll probably want to check that out.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top