Skip to content

Commit

Permalink
DC21-308: creating capistrano tasks to deploy joai
Browse files Browse the repository at this point in the history
  • Loading branch information
diego-intersect committed Oct 15, 2012
1 parent a510f84 commit 10e0357
Show file tree
Hide file tree
Showing 7 changed files with 139 additions and 14 deletions.
1 change: 1 addition & 0 deletions config/deploy.rb
Expand Up @@ -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)
Expand Down
27 changes: 13 additions & 14 deletions 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


21 changes: 21 additions & 0 deletions 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
Binary file added joai/tomcat-joai.tar.gz
Binary file not shown.
8 changes: 8 additions & 0 deletions joai/tomcat_joai.conf
@@ -0,0 +1,8 @@
<Proxy *>
Order deny,allow
Allow from all
</Proxy>
ProxyRequests Off
ProxyPreserveHost On
ProxyPass /oai http://localhost:8080/oai
ProxyPassReverse /oai http://localhost:8080/oai
28 changes: 28 additions & 0 deletions joai/tomcat_users.xml
@@ -0,0 +1,28 @@
<?xml version='1.0' encoding='utf-8'?>
<!--
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<tomcat-users>
<!--
NOTE: By default, no user is included in the "manager-gui" role required
to operate the "/manager/html" web application. If you wish to use this app,
you must define such a user - the username and password are arbitrary.
-->
<role rolename="manager"/>
<role rolename="oai_admin"/>
<user username="oai_admin" password="---" roles="oai_admin"/>
<user username="tomcat" password="tomcat" roles="manager"/>
</tomcat-users>
68 changes: 68 additions & 0 deletions 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

0 comments on commit 10e0357

Please sign in to comment.