diff --git a/config/deploy.rb b/config/deploy.rb
index e2ddfaf2..e0ee2ba5 100644
--- a/config/deploy.rb
+++ b/config/deploy.rb
@@ -6,6 +6,7 @@
# Extra capistrano tasks
load 'lib/intersect_capistrano_tasks'
+load 'lib/joai_capistrano_tasks'
set :application, 'dc21app'
set :stages, %w(qa staging production)
diff --git a/config/deploy/production.rb b/config/deploy/production.rb
index 77cdc96f..f3575c34 100644
--- a/config/deploy/production.rb
+++ b/config/deploy/production.rb
@@ -1,23 +1,22 @@
# Your HTTP server, Apache/etc
-set :web_server, 'hostname.com'
-# This may be the same as your Web server
-set :app_server, 'hostname.com'
-# This is where Rails migrations will run
-set :db_server, 'hostname.com'
-# The user configured to run the rails app
+set :web_server, '115.146.94.136'
+# # This may be the same as your Web server
+set :app_server, '115.146.94.136'
+# # This is where Rails migrations will run
+set :db_server, '115.146.94.136'
+# # The user configured to run the rails app
set :user, 'dc21'
-
-# If you are using RHEL/CentOS 6 or later, set this to true
+#
+# # If you are using RHEL/CentOS 6 or later, set this to true
set :el6, true
-
-# If you have a proxy server, enter the value here in "inverted commas", eg:
-#set :proxy, "http://user:pass@proxy.example.com:8080" # with a user/password
-#set :proxy, "http://proxy.example.com:8080" # without a user/pass
-set :proxy, nil
+#
+# # If you have a proxy server, enter the value here in "inverted commas", eg:
+# #set :proxy, "http://user:pass@proxy.example.com:8080" # with a user/password
+# #set :proxy, "http://proxy.example.com:8080" # without a user/pass
+set :proxy, nil
role :web, web_server
role :app, app_server
role :db, db_server, :primary => true
-
diff --git a/joai/tomcat b/joai/tomcat
new file mode 100644
index 00000000..40a0d2dc
--- /dev/null
+++ b/joai/tomcat
@@ -0,0 +1,21 @@
+#!/bin/bash
+# chkconfig: 234 20 80
+# description: Tomcat Server basic start/shutdown script
+# processname: tomcat
+JAVA_HOME=/usr/lib/jvm/jre-1.6.0-openjdk.x86_64/
+export JAVA_HOME
+TOMCAT_HOME=/usr/tomcat6/bin
+
+case $1 in
+start)
+/bin/su dc21 $TOMCAT_HOME/startup.sh
+;;
+stop)
+/bin/su dc21 $TOMCAT_HOME/shutdown.sh
+;;
+restart)
+/bin/su dc21 $TOMCAT_HOME/shutdown.sh
+/bin/su dc21 $TOMCAT_HOME/startup.sh
+;;
+esac
+exit 0
\ No newline at end of file
diff --git a/joai/tomcat-joai.tar.gz b/joai/tomcat-joai.tar.gz
new file mode 100644
index 00000000..1c0b5753
Binary files /dev/null and b/joai/tomcat-joai.tar.gz differ
diff --git a/joai/tomcat_joai.conf b/joai/tomcat_joai.conf
new file mode 100644
index 00000000..ee978e18
--- /dev/null
+++ b/joai/tomcat_joai.conf
@@ -0,0 +1,8 @@
+
+Order deny,allow
+Allow from all
+
+ProxyRequests Off
+ProxyPreserveHost On
+ProxyPass /oai http://localhost:8080/oai
+ProxyPassReverse /oai http://localhost:8080/oai
diff --git a/joai/tomcat_users.xml b/joai/tomcat_users.xml
new file mode 100644
index 00000000..723fdcda
--- /dev/null
+++ b/joai/tomcat_users.xml
@@ -0,0 +1,28 @@
+
+
+
+
+
+
+
+
+
diff --git a/lib/joai_capistrano_tasks.rb b/lib/joai_capistrano_tasks.rb
new file mode 100644
index 00000000..c0c91ca9
--- /dev/null
+++ b/lib/joai_capistrano_tasks.rb
@@ -0,0 +1,68 @@
+require 'tempfile'
+
+namespace :joai do
+ set :catalina_home, "/usr/tomcat6"
+ set :webapp_dir, "#{catalina_home}/webapps"
+ set :tomcat_conf, "#{catalina_home}/conf"
+
+ set :remote_directory, "/home/dc21/joai"
+ set :tomcat_bundle, "tomcat-joai.tar.gz"
+ set :tomcat_package, 'apache-tomcat-6.0.35'
+
+ set :tomcat_service, "tomcat"
+ set :apache_config, "tomcat_joai.conf"
+
+ set :tomcat_user_file, 'joai/tomcat_users.xml'
+
+ desc 'Copy joai bundle to remote server'
+ task :copy do
+ run "mkdir -p #{remote_directory}"
+ upload("joai/#{tomcat_bundle}", "#{remote_directory}", :via => :scp)
+ upload("joai/#{tomcat_service}", "#{remote_directory}", :via => :scp)
+ upload("joai/#{apache_config}", "#{remote_directory}", :via => :scp)
+ end
+
+ desc "Unpack tomcat and install in usr directory"
+ task :tomcat_install do
+ run "cd #{remote_directory} && tar xvfz #{tomcat_bundle}"
+ run "#{try_sudo} mv #{remote_directory}/#{tomcat_package} #{catalina_home}"
+ run "#{try_sudo} mv #{remote_directory}/#{tomcat_service} /etc/init.d"
+ run "#{try_sudo} mv #{remote_directory}/#{apache_config} /etc/httpd/conf.d/"
+ run "#{try_sudo} chmod 755 /etc/init.d/#{tomcat_service}"
+ run "#{try_sudo} chkconfig --add tomcat"
+ run "#{try_sudo} chkconfig --level 234 tomcat on"
+ end
+
+ desc "configure joai and tomcat password"
+ task "joai_user" do
+ password = nil
+ until password
+ first_password = Capistrano::CLI.password_prompt("New jOAI password (at least six alphanumeric characters): ".yellow)
+ second_password = Capistrano::CLI.password_prompt("Confirm password: ".yellow)
+
+ if first_password.eql? second_password
+ if first_password =~ /^[a-zA-Z0-9]{6,}$/
+ password = first_password
+ else
+ puts "Wrong password"
+ end
+ else
+ puts "Passwords don't match".red
+ end
+ end
+
+ tmp_oai_user_file = Tempfile.new('foo')
+ `cat #{tomcat_user_file} | sed 's/---/#{password}/' > #{tmp_oai_user_file.path}`
+ upload(tmp_oai_user_file.path, "#{tomcat_conf}/tomcat-users.xml", :via => :scp)
+
+ tmp_oai_user_file.close
+ tmp_oai_user_file.unlink
+ end
+
+ desc "Fully deploy joai"
+ task :deploy do
+ copy
+ tomcat_install
+ joai_user
+ end
+end