Deploy clojure web app with Immutant
Just want to put it simply, below are the steps necessary that i have done it a while back.
If your server doesn't have jdk yet, go install it. Below steps assumed you have download the jdk in your home directory and will install it on /usr/local/java:
mkdir /usr/local/java cd /usr/local/java tar zxvf ~/jdk-7u21-linux-x64.tar.gz
Setup JAVA_HOME, below are for my ubuntu server one:
cd /usr/local/java/jdk1.7.0_21/ d=`pwd` echo JAVA_HOME=$d >> ~/.bashrc echo export JAVA_HOME >> ~/.bashrc . ~/.bashrc
Install Leiningen, below i copy lein in /usr/local/bin
sudo su - cd /usr/local/bin wget https://raw.github.com/technomancy/leiningen/stable/bin/lein chmod a+x lein exit
Firstime you invoke lein, it will download the necessary things, just make sure you have internet connection. If you're behind proxy, below are how to set proxy env variable so that lein will use proxy, here my proxy server is 1.2.3.4 on port 8080:
export http_proxy=1.2.3.4:8080 export https_proxy=$http_proxy
Then run lein with the user you choose, as below:
su -l reedho lein
If all going well, then you see the list of available lein task, this means from now on, you can rely much on lein for doing many of clojure things.
For Immutant, the easiest path for installing and working with it is via immutant lein plugin, below are steps to install. This assume you have empty lein profiles file, if not, you have to suit it accordingly:
echo "{:user {:plugins [[lein-immutant \"0.18.1\"]]}}" >> ~/.lein/profiles.clj
As everything with lein, all the necessary packages will be fetched and installed the first time you invoke the task with lein, so, to have the immutant plugin, after setup profiles file above, the only next step is to invoke the lein immutant task:
lein immutant
If everything goes well, you will be shown the immutant subtasks.
After the immutant plugin installed succesfully, next step is install the Immutant itself via the plugin, as below:
lein immutant install
When finish, now you have Immutant ready for work. Its installed in ~/.lein/immutant directory.
For me, in the development machine i install immutant as above, and in production machine i install immutant with lein immutant install --full.
Now is the time to prepare deploying your clojure web app.
Below are steps of how i prepare the app archive in my development machine, and deploy manually in production machine.
In devel machine, on clojure app directory, invoke the archive subtask as follow, where i set the context-path as app/myapp.
cd ~/Workspace/Clojure/myapp lein immutant archive --include-dependencies --context-path app/myapp
Then copy the myapp.ima to production server, put it in Immutant deployments directory.
cd ~/.lein/immutant/current/jboss/standalone/deployments cp ~/myapp.ima ./ touch myapp.ima.dodeploy cd ~
Then, if you haven't yet start the immutant, start it as below steps:
cd ~ lein immutant run -b 0.0.0.0
So, if all goes well, your will see the bunch of message that the myapp.ima already serving in /app/myapp path, so it will be available with the following url: http://serverhostname:8080/app/myapp.
Thats it!
Resources:
http://leiningen.org
http://immutant.org










