chrisrec 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Manifest +39 -0
- data/README +0 -0
- data/Rakefile +15 -0
- data/chrisrec.gemspec +30 -0
- data/lib/backgroundrb/backgroundrb.rb +22 -0
- data/lib/chrisrec.rb +12 -0
- data/lib/console/console.rb +19 -0
- data/lib/daemon/daemon.rb +134 -0
- data/lib/gitosis/gitosis.rb +131 -0
- data/lib/memcached/memcached.rb +140 -0
- data/lib/munin/munin.rb +135 -0
- data/lib/mysql/mysql.rake +95 -0
- data/lib/mysql/mysql.rb +51 -0
- data/lib/rake/rake.rb +19 -0
- data/lib/rakecron/rakecron.rb +35 -0
- data/lib/starling/starling.rb +124 -0
- data/lib/tomcat/tomcat.rb +200 -0
- data/lib/workling/workling.rb +72 -0
- data/template/daemon/daemon-init-script.erb +59 -0
- data/template/daemon/monit.conf.erb +4 -0
- data/template/memcached/memcached-conf.erb +1 -0
- data/template/memcached/memcached.erb +59 -0
- data/template/memcached/monit.conf.erb +8 -0
- data/template/memcached/start-memcached.erb +118 -0
- data/template/munin/httpd-vhost-munin.conf.erb +20 -0
- data/template/munin/munin.conf.erb +70 -0
- data/template/munin/munin_nginx_vhost.conf.erb +24 -0
- data/template/rakecron/rakecron.erb +12 -0
- data/template/starling/monit.conf.erb +14 -0
- data/template/starling/starling-init-script.erb +69 -0
- data/template/tomcat/conf/server.xml.erb +33 -0
- data/template/tomcat/conf/web.xml +1194 -0
- data/template/tomcat/logs/empty.txt +1 -0
- data/template/tomcat/monit.conf.erb +8 -0
- data/template/tomcat/temp/empty.txt +1 -0
- data/template/tomcat/tomcat.erb +28 -0
- data/template/tomcat/webapps/empty.txt +1 -0
- data/template/tomcat/work/empty.txt +1 -0
- data/template/workling/monit.conf.erb +4 -0
- data/template/workling/workling-init-script.erb +56 -0
- metadata +121 -0
data/lib/munin/munin.rb
ADDED
@@ -0,0 +1,135 @@
|
|
1
|
+
# Copyright 2006-2008 by Mike Bailey. All rights reserved.
|
2
|
+
Capistrano::Configuration.instance(:must_exist).load do
|
3
|
+
namespace :chrisrec do
|
4
|
+
namespace :munin do
|
5
|
+
|
6
|
+
set :use_nginx, false
|
7
|
+
set :use_apache, true
|
8
|
+
set :munin_user, 'munin'
|
9
|
+
set :munin_group, 'munin'
|
10
|
+
set :munin_webserver_auth_user, 'admin'
|
11
|
+
set :munin_webserver_auth_pass, 'XXXX'
|
12
|
+
|
13
|
+
set :local_template_dir, "#{File.dirname(__FILE__)}/../../template"
|
14
|
+
|
15
|
+
desc "Install munin"
|
16
|
+
task :install, :roles => :web do
|
17
|
+
install_deps
|
18
|
+
create_munin_user
|
19
|
+
deprec2.mkdir("#{deploy_to}/munin/html", :group => munin_group, :mode => 0775, :via => :sudo)
|
20
|
+
end
|
21
|
+
|
22
|
+
task :install_deps do
|
23
|
+
apt.install( {:base => %w(munin munin-node)}, :stable )
|
24
|
+
end
|
25
|
+
|
26
|
+
task :create_munin_user do
|
27
|
+
deprec2.groupadd(munin_group)
|
28
|
+
deprec2.useradd(munin_user, :group => munin_group, :homedir => false)
|
29
|
+
end
|
30
|
+
|
31
|
+
SYSTEM_CONFIG_FILES[:munin] = [
|
32
|
+
|
33
|
+
{:template => 'munin.conf.erb',
|
34
|
+
:path => '/etc/munin/munin.conf',
|
35
|
+
:mode => 0664,
|
36
|
+
:owner => 'root:root'}
|
37
|
+
]
|
38
|
+
|
39
|
+
PROJECT_CONFIG_FILES[:munin_nginx] = [
|
40
|
+
|
41
|
+
{:template => 'munin_nginx_vhost.conf.erb',
|
42
|
+
:path => "conf/munin_nginx_vhost.conf",
|
43
|
+
:mode => 0644,
|
44
|
+
:owner => 'root:root'}
|
45
|
+
]
|
46
|
+
|
47
|
+
PROJECT_CONFIG_FILES[:munin_apache] = [
|
48
|
+
|
49
|
+
{:template => "httpd-vhost-munin.conf.erb",
|
50
|
+
:path => 'conf/httpd-vhost-munin.conf',
|
51
|
+
:mode => 0755,
|
52
|
+
:owner => 'root:root'}
|
53
|
+
]
|
54
|
+
|
55
|
+
desc "Generate configuration file(s) for munin from template(s)"
|
56
|
+
task :config_gen do
|
57
|
+
SYSTEM_CONFIG_FILES[:munin].each do |file|
|
58
|
+
deprec2.render_template(:munin, file)
|
59
|
+
end
|
60
|
+
|
61
|
+
PROJECT_CONFIG_FILES[:munin_nginx].each do |file|
|
62
|
+
deprec2.render_template(:munin, file)
|
63
|
+
end if use_nginx
|
64
|
+
|
65
|
+
PROJECT_CONFIG_FILES[:munin_apache].each do |file|
|
66
|
+
deprec2.render_template(:munin, file)
|
67
|
+
end if use_apache
|
68
|
+
end
|
69
|
+
|
70
|
+
desc 'Deploy configuration files(s) for munin'
|
71
|
+
task :config, :roles => :web do
|
72
|
+
deprec2.push_configs(:munin, SYSTEM_CONFIG_FILES[:munin])
|
73
|
+
deprec2.push_configs(:munin, PROJECT_CONFIG_FILES[:munin_nginx]) if use_nginx
|
74
|
+
deprec2.push_configs(:munin, PROJECT_CONFIG_FILES[:munin_apache]) if use_apache
|
75
|
+
symlink_nginx_vhost if use_nginx
|
76
|
+
symlink_apache_vhost if use_apache
|
77
|
+
auth_user if use_apache
|
78
|
+
end
|
79
|
+
|
80
|
+
task :symlink_nginx_vhost, :roles => :web do
|
81
|
+
return unless use_nginx
|
82
|
+
sudo "ln -sf #{deploy_to}/munin/conf/munin_nginx_vhost.conf #{nginx_vhost_dir}/munin.conf"
|
83
|
+
end
|
84
|
+
|
85
|
+
task :symlink_apache_vhost, :roles => :web do
|
86
|
+
return unless use_apache
|
87
|
+
sudo "ln -sf #{deploy_to}/munin/conf/httpd-vhost-munin.conf /etc/apache2/sites-available/munin"
|
88
|
+
sudo "ln -sf #{deploy_to}/munin/conf/httpd-vhost-munin.conf /etc/apache2/sites-enabled/munin"
|
89
|
+
end
|
90
|
+
|
91
|
+
task :auth_user, :roles => :web do
|
92
|
+
set (:munin_webserver_auth_user) {
|
93
|
+
Capistrano::CLI.ui.ask "Enter munin web user" do |q|
|
94
|
+
q.default = 'admin'
|
95
|
+
end
|
96
|
+
}
|
97
|
+
|
98
|
+
set (:munin_webserver_auth_pass) {
|
99
|
+
Capistrano::CLI.ui.ask "Enter munin web user password"
|
100
|
+
}
|
101
|
+
|
102
|
+
|
103
|
+
sudo "/usr/bin/htpasswd -c -b #{deploy_to}/munin/htpasswd.users #{munin_webserver_auth_user} #{munin_webserver_auth_pass}"
|
104
|
+
end
|
105
|
+
|
106
|
+
desc "start munin"
|
107
|
+
task :start, :roles => :web do
|
108
|
+
send(run_method, "/etc/init.d/munin-node start")
|
109
|
+
end
|
110
|
+
|
111
|
+
desc "stop munin"
|
112
|
+
task :stop, :roles => :web do
|
113
|
+
send(run_method, "/etc/init.d/munin-node stop")
|
114
|
+
end
|
115
|
+
|
116
|
+
desc "restart munin"
|
117
|
+
task :restart, :roles => :web do
|
118
|
+
send(run_method, "/etc/init.d/munin-node restart")
|
119
|
+
end
|
120
|
+
|
121
|
+
task :activate, :roles => :web do
|
122
|
+
end
|
123
|
+
|
124
|
+
task :deactivate, :roles => :web do
|
125
|
+
end
|
126
|
+
|
127
|
+
task :backup, :roles => :web do
|
128
|
+
end
|
129
|
+
|
130
|
+
task :restore, :roles => :web do
|
131
|
+
end
|
132
|
+
|
133
|
+
end
|
134
|
+
end
|
135
|
+
end
|
@@ -0,0 +1,95 @@
|
|
1
|
+
# COPY TO YOUR lib/rake directory
|
2
|
+
require 'fileutils'
|
3
|
+
require 'active_record'
|
4
|
+
require 'erb'
|
5
|
+
|
6
|
+
namespace :mysql do
|
7
|
+
DUMP_FILENAME = [RAILS_ENV, Time.now.utc.strftime('%Y-%m-%d_%H-%M-%S')].join('_') + '.sql.bz2'
|
8
|
+
DUMP_LOCATION = File.join(RAILS_ROOT, 'db', 'dumps')
|
9
|
+
|
10
|
+
def populate_config
|
11
|
+
ActiveRecord::Base.configurations = Rails::Configuration.new.database_configuration
|
12
|
+
end
|
13
|
+
|
14
|
+
def conf
|
15
|
+
populate_config if ActiveRecord::Base.configurations.empty?
|
16
|
+
@conf ||= ActiveRecord::Base.configurations[RAILS_ENV]
|
17
|
+
end
|
18
|
+
|
19
|
+
def mysql_opts
|
20
|
+
user = conf['user'] || conf['username']
|
21
|
+
opts = []
|
22
|
+
opts << "--user=#{user}" if user
|
23
|
+
opts << "--password=#{conf['password']}" if conf['password']
|
24
|
+
opts << "--host=#{conf['host']}" if conf['host']
|
25
|
+
opts << "--port=#{conf['port']}" if conf['port']
|
26
|
+
opts << "--default-character-set=#{conf['encoding']}" if conf['encoding']
|
27
|
+
opts << "#{conf['database']}"
|
28
|
+
opts.join(' ')
|
29
|
+
end
|
30
|
+
|
31
|
+
def dump_cmd
|
32
|
+
"mysqldump --skip-lock-tables #{mysql_opts} | bzip2"
|
33
|
+
end
|
34
|
+
|
35
|
+
def load_cmd
|
36
|
+
"bunzip2 | mysql #{mysql_opts}"
|
37
|
+
end
|
38
|
+
|
39
|
+
def overwrite_db_with(file_or_io)
|
40
|
+
IO.popen(load_cmd, 'w') { |mysql| mysql << file_or_io.read }
|
41
|
+
end
|
42
|
+
|
43
|
+
task :ensure_mysql do
|
44
|
+
abort "Sorry, you have to be using MySQL locally" unless conf['adapter'] == 'mysql'
|
45
|
+
ActiveRecord::Base.establish_connection
|
46
|
+
end
|
47
|
+
|
48
|
+
desc <<-DESC
|
49
|
+
Prints out information about the charsets and collations used by the MySQL
|
50
|
+
connection of the current environment
|
51
|
+
DESC
|
52
|
+
task :charset_info => :ensure_mysql do
|
53
|
+
charset_vars = ActiveRecord::Base.connection.execute("show variables like 'character\_set\_%'")
|
54
|
+
collation_vars = ActiveRecord::Base.connection.execute("show variables like 'colla%'")
|
55
|
+
puts "ActiveRecord::Base.connection.charset: #{ActiveRecord::Base.connection.charset}"
|
56
|
+
puts "ActiveRecord::Base.connection.collation: #{ActiveRecord::Base.connection.collation}"
|
57
|
+
[charset_vars, collation_vars].each do |resultset|
|
58
|
+
resultset.each do |variable, value|
|
59
|
+
puts "#{variable}: #{value}"
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
desc 'Dumps the a mysql db of the current environment to standard out'
|
65
|
+
task :stream_dump => :ensure_mysql do
|
66
|
+
exec dump_cmd
|
67
|
+
end
|
68
|
+
|
69
|
+
desc <<-DESC
|
70
|
+
Pipes STDIN into the local MySQL DB.\
|
71
|
+
Warning! May replace current DB entirely, use with care.\
|
72
|
+
Reverse of mysql:stream_dump
|
73
|
+
DESC
|
74
|
+
task :load_dump => :dump do
|
75
|
+
overwrite_db_with $stdin
|
76
|
+
puts "loaded other database into #{conf['database']}"
|
77
|
+
end
|
78
|
+
|
79
|
+
desc 'Dump the database for the current environment into /db/dumps'
|
80
|
+
task :dump => :ensure_mysql do
|
81
|
+
FileUtils.mkdir_p DUMP_LOCATION
|
82
|
+
dumpfile = File.join(DUMP_LOCATION, DUMP_FILENAME)
|
83
|
+
puts "created #{dumpfile.gsub(RAILS_ROOT,'')}" if system "#{dump_cmd} > #{dumpfile}"
|
84
|
+
end
|
85
|
+
|
86
|
+
desc 'Loads the last dump into the DB'
|
87
|
+
task :restore => :ensure_mysql do
|
88
|
+
Dir.chdir DUMP_LOCATION do
|
89
|
+
last_filename = Dir.glob("#{RAILS_ENV}_*.sql.bz2").sort.last
|
90
|
+
abort 'Sorry, no restorable dump found' unless last_filename
|
91
|
+
File.open(last_filename, 'r') { |dumpfile| overwrite_db_with dumpfile }
|
92
|
+
puts "Restored backup #{last_filename}"
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
data/lib/mysql/mysql.rb
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
require 'fileutils'
|
2
|
+
|
3
|
+
Capistrano::Configuration.instance(:must_exist).load do
|
4
|
+
namespace :chrisrec do
|
5
|
+
|
6
|
+
set :db_dump_filename do
|
7
|
+
[rails_env, release_name].join('_') + '.sql.bz2'
|
8
|
+
end
|
9
|
+
|
10
|
+
namespace :mysql do
|
11
|
+
|
12
|
+
desc 'Dump the remote database'
|
13
|
+
task :dump, :roles => :db, :only => { :primary => true } do
|
14
|
+
top.chrisrec.remote_rake 'mysql:dump'
|
15
|
+
end
|
16
|
+
|
17
|
+
desc 'Restore the latest database dump'
|
18
|
+
task :restore, :roles => :db, :only => { :primary => true } do
|
19
|
+
top.chrisrec.remote_rake 'mysql:restore'
|
20
|
+
end
|
21
|
+
|
22
|
+
desc 'Dumps the remote database and copies the dump to the shared directory'
|
23
|
+
task :backup_dump, :roles => :db, :only => { :primary => true } do
|
24
|
+
destination = fetch(:db_backup_location, File.join(deploy_to, shared_dir, 'db_dumps'))
|
25
|
+
run "mkdir -p #{destination}"
|
26
|
+
top.chrisrec.remote_rake "mysql:stream_dump > #{File.join(destination, db_dump_filename)}"
|
27
|
+
end
|
28
|
+
|
29
|
+
desc 'Creates a dump of the remote database and copies it to the local working dir'
|
30
|
+
task :fetch_dump, :roles => :db, :only => { :primary => true } do
|
31
|
+
host = roles[:db].servers.first.host
|
32
|
+
destination = fetch(:db_dump_location, File.join('db', 'dumps', host))
|
33
|
+
tempfile = File.join('tmp', db_dump_filename)
|
34
|
+
FileUtils.mkdir_p destination unless File.directory?(destination) || File.symlink?(destination)
|
35
|
+
top.chrisrec.remote_rake "mysql:stream_dump > #{tempfile}"
|
36
|
+
get File.join(deploy_to, 'current', tempfile), File.join(destination, db_dump_filename)
|
37
|
+
run "rm -f #{tempfile}" # delete tempfile # doesnt work!?!
|
38
|
+
end
|
39
|
+
|
40
|
+
desc 'Clones the remote db, replacing the local development one'
|
41
|
+
task :duplicate, :roles => :db, :only => { :primary => true } do
|
42
|
+
IO.popen('rake mysql:load_dump', 'w') do |local_mysql|
|
43
|
+
top.chrisrec.remote_rake('mysql:stream_dump', :pty => false) do |channel, stream, data|
|
44
|
+
next if stream == :err
|
45
|
+
local_mysql << data
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
data/lib/rake/rake.rb
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
Capistrano::Configuration.instance(:must_exist).load do
|
2
|
+
namespace :chrisrec do
|
3
|
+
def remote_rake(task, options={}, &block)
|
4
|
+
rake = fetch(:rake, 'rake')
|
5
|
+
run("cd #{deploy_to}/current && RAILS_ENV=#{rails_env} #{rake} #{task}", options, &block)
|
6
|
+
end
|
7
|
+
|
8
|
+
desc %Q{\
|
9
|
+
Invokes rake task in currently deployed app\
|
10
|
+
specify task(s) to be in ENV variable TASK\
|
11
|
+
Example: cap rake TASK=db:migrate
|
12
|
+
}
|
13
|
+
task :rake do
|
14
|
+
task = ENV['TASK'] || ENV['TASKS']
|
15
|
+
abort 'please specify a TASK env variable' unless task
|
16
|
+
remote_rake task
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
Capistrano::Configuration.instance(:must_exist).load do
|
2
|
+
namespace :chrisrec do
|
3
|
+
namespace :rakecron do
|
4
|
+
|
5
|
+
# role :cron, "TODO"
|
6
|
+
set :rakecron_log_dir, "/var/log"
|
7
|
+
set :local_template_dir, "#{File.dirname(__FILE__)}/../../template"
|
8
|
+
|
9
|
+
PROJECT_CONFIG_FILES[:rakecron] = [
|
10
|
+
{:template => 'rakecron.erb',
|
11
|
+
:path => 'crontab',
|
12
|
+
:mode => 0664,
|
13
|
+
:owner => 'root:root'}
|
14
|
+
]
|
15
|
+
|
16
|
+
desc "Generate configuration file(s) for from template(s)"
|
17
|
+
task :config_gen do
|
18
|
+
PROJECT_CONFIG_FILES[:rakecron].each do |file|
|
19
|
+
deprec2.render_template(:rakecron, file)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
desc 'Deploy configuration files(s) for rakecron'
|
24
|
+
task :config, :roles => :cron do
|
25
|
+
deprec2.push_configs(:rakecron, PROJECT_CONFIG_FILES[:rakecron])
|
26
|
+
symlink_cron_job
|
27
|
+
end
|
28
|
+
|
29
|
+
task :symlink_cron_job, :roles => :cron do
|
30
|
+
sudo "ln -sf #{deploy_to}/rakecron/crontab /etc/cron.d/rakecron_#{application}"
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,124 @@
|
|
1
|
+
Capistrano::Configuration.instance(:must_exist).load do
|
2
|
+
namespace :chrisrec do
|
3
|
+
namespace :starling do
|
4
|
+
|
5
|
+
set :starling_port, 15151
|
6
|
+
set :starling_address, "127.0.0.1"
|
7
|
+
set :starling_user, "starling"
|
8
|
+
set :starling_group, "starling"
|
9
|
+
set :starling_spool_dir, "/var/spool/starling"
|
10
|
+
set :starling_run_dir, "/var/run"
|
11
|
+
set :starling_log_dir, "/var/log"
|
12
|
+
|
13
|
+
set :local_template_dir, "#{File.dirname(__FILE__)}/../../template"
|
14
|
+
|
15
|
+
# Installation
|
16
|
+
desc "Installs the Starling gem"
|
17
|
+
task :install, :roles => :cache do
|
18
|
+
sudo("gem install eventmachine --no-rdoc --no-ri")
|
19
|
+
sudo("gem install starling-starling --source http://gems.github.com -v 0.9.9 --no-rdoc --no-ri")
|
20
|
+
|
21
|
+
deprec2.mkdir(starling_spool_dir, :via => :sudo)
|
22
|
+
# deprec2.mkdir(starling_run_dir, :via => :sudo)
|
23
|
+
# deprec2.mkdir(starling_log_dir, :via => :sudo)
|
24
|
+
|
25
|
+
create_starling_user_and_group
|
26
|
+
set_perms_for_starling_dirs
|
27
|
+
symlink_starling_for_rubyee if ruby_vm_type == :ree
|
28
|
+
end
|
29
|
+
|
30
|
+
# Configure
|
31
|
+
|
32
|
+
SYSTEM_CONFIG_FILES[:starling] = [
|
33
|
+
{:template => 'starling-init-script.erb',
|
34
|
+
:path => 'starling/etc/init.d/starling',
|
35
|
+
:mode => 0755,
|
36
|
+
:owner => 'root:root'},
|
37
|
+
|
38
|
+
{:template => 'monit.conf.erb',
|
39
|
+
:path => "starling/etc/monit.d/monit_starling.conf",
|
40
|
+
:mode => 0600,
|
41
|
+
:owner => 'root:root'}
|
42
|
+
]
|
43
|
+
|
44
|
+
# Generating Configuration Files
|
45
|
+
desc "Generate configuration file(s) for Starling from template(s)"
|
46
|
+
task :config_gen do
|
47
|
+
SYSTEM_CONFIG_FILES[:starling].each do |file|
|
48
|
+
deprec2.render_template(:starling, file)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
desc 'Deploy configuration files(s) for Starling'
|
53
|
+
task :config, :roles => :cache do
|
54
|
+
deprec2.push_configs(:starling, SYSTEM_CONFIG_FILES[:starling])
|
55
|
+
symlink_init_d
|
56
|
+
symlink_monit_d
|
57
|
+
|
58
|
+
activate
|
59
|
+
end
|
60
|
+
|
61
|
+
desc "Stop starling"
|
62
|
+
task :stop , :roles => :cache do
|
63
|
+
sudo "/etc/init.d/starling_#{starling_port} stop"
|
64
|
+
end
|
65
|
+
|
66
|
+
desc "Start starling"
|
67
|
+
task :start , :roles => :cache do
|
68
|
+
sudo "/etc/init.d/starling_#{starling_port} start"
|
69
|
+
end
|
70
|
+
|
71
|
+
desc "Start the starling server"
|
72
|
+
task :restart, :roles => :cache do
|
73
|
+
stop
|
74
|
+
sleep(2)
|
75
|
+
start
|
76
|
+
end
|
77
|
+
|
78
|
+
task :activate, :roles => :cache do
|
79
|
+
send(run_method, "update-rc.d starling_#{starling_port} defaults")
|
80
|
+
end
|
81
|
+
|
82
|
+
task :deactivate, :roles => :cache do
|
83
|
+
send(run_method, "update-rc.d -f starling_#{starling_port} remove")
|
84
|
+
end
|
85
|
+
|
86
|
+
# User/Group creation & permission assignment
|
87
|
+
# These were based off the tasks used in the mongrel recipe -
|
88
|
+
# as this was probably the nicest way to ensure these tasks
|
89
|
+
# were doing the right thing.
|
90
|
+
desc "create user and group for starling to run as"
|
91
|
+
task :create_starling_user_and_group, :roles => :cache do
|
92
|
+
deprec2.groupadd(starling_group)
|
93
|
+
deprec2.useradd(starling_user, :group => starling_group, :homedir => false)
|
94
|
+
# Set the primary group for the starling user (in case user already existed
|
95
|
+
# when previous command was run)
|
96
|
+
sudo "usermod --gid #{starling_group} #{starling_user}"
|
97
|
+
end
|
98
|
+
|
99
|
+
desc "set group ownership and permissions on dirs starling needs to write to"
|
100
|
+
task :set_perms_for_starling_dirs, :roles => :cache do
|
101
|
+
sudo "chgrp -R #{starling_group} #{starling_spool_dir}"
|
102
|
+
sudo "chmod -R g+w #{starling_spool_dir}"
|
103
|
+
# sudo "chgrp -R #{starling_group} #{starling_run_dir} #{starling_log_dir}"
|
104
|
+
# sudo "chmod -R g+w #{starling_run_dir} #{starling_log_dir}"
|
105
|
+
end
|
106
|
+
|
107
|
+
task :symlink_starling_for_rubyee, :roles => :cache do
|
108
|
+
# This ensures we symlink from the REE common directory, NOT the
|
109
|
+
# actual REE install directory (so when we change the REE version,
|
110
|
+
# we don't have to fuddle around again).
|
111
|
+
sudo "ln -fs #{ree_short_path}/bin/starling /usr/local/bin/starling"
|
112
|
+
end
|
113
|
+
|
114
|
+
task :symlink_init_d, :roles => :cache do
|
115
|
+
sudo "ln -fs #{deploy_to}/starling/starling/etc/init.d/starling /etc/init.d/starling_#{starling_port}"
|
116
|
+
end
|
117
|
+
|
118
|
+
task :symlink_monit_d, :roles => :cache do
|
119
|
+
sudo "ln -fs #{deploy_to}/starling/starling/etc/monit.d/monit_starling.conf /etc/monit.d/monit_starling_#{starling_port}.conf"
|
120
|
+
end
|
121
|
+
|
122
|
+
end
|
123
|
+
end
|
124
|
+
end
|
@@ -0,0 +1,200 @@
|
|
1
|
+
Capistrano::Configuration.instance(:must_exist).load do
|
2
|
+
namespace :chrisrec do
|
3
|
+
namespace :tomcat do
|
4
|
+
|
5
|
+
set :maven_env, "production"
|
6
|
+
set :tomcat_war, "MyAppName"
|
7
|
+
|
8
|
+
set :tomcat_address, '127.0.0.1'
|
9
|
+
set :tomcat_port, 8080
|
10
|
+
set :tomcat_shutdown_port, 8009
|
11
|
+
set :tomcat_ssl_port, 8443
|
12
|
+
|
13
|
+
set :local_template_dir, "#{File.dirname(__FILE__)}/../../template"
|
14
|
+
|
15
|
+
desc "Install tomcat"
|
16
|
+
task :install, :roles => :app do
|
17
|
+
version = 'apache-tomcat-6.0.20'
|
18
|
+
set :src_package, {
|
19
|
+
:file => version + '.tar.gz',
|
20
|
+
# :md5sum => 'a08851f7fa7b15e92ee6320b7a79c321 tomcat-1.2.2.tar.gz',
|
21
|
+
:dir => version,
|
22
|
+
:url => "http://apache.16degrees.com.au/tomcat/tomcat-6/v6.0.20/bin/apache-tomcat-6.0.20.tar.gz",
|
23
|
+
:unpack => "tar zxf #{version}.tar.gz;"
|
24
|
+
}
|
25
|
+
|
26
|
+
deprec2.download_src(src_package, src_dir)
|
27
|
+
deprec2.unpack_src(src_package, src_dir)
|
28
|
+
|
29
|
+
sudo "sudo mv #{src_dir}/#{version} /usr/local/tomcat"
|
30
|
+
|
31
|
+
install_java
|
32
|
+
end
|
33
|
+
|
34
|
+
task :install_java do
|
35
|
+
# puts "sudo vi /etc/apt/sources.list"
|
36
|
+
sudo "chmod 666 /etc/apt/sources.list"
|
37
|
+
sudo "grep 'multiverse$' /etc/apt/sources.list || sudo echo \"\"\n\"deb http://archive.ubuntu.com/ubuntu/ intrepid multiverse\" >> /etc/apt/sources.list"
|
38
|
+
sudo "chmod 644 /etc/apt/sources.list"
|
39
|
+
|
40
|
+
apt.update
|
41
|
+
apt.install( {:base => %w(maven2)}, :stable )
|
42
|
+
|
43
|
+
puts "*******************"
|
44
|
+
puts "*******************"
|
45
|
+
puts "******************* cannot automate the sun java install"
|
46
|
+
puts "******************* run : sudo apt-get install sun-java6-bin sun-java6-jre sun-java6-jdk"
|
47
|
+
puts "*******************"
|
48
|
+
puts "*******************"
|
49
|
+
|
50
|
+
end
|
51
|
+
|
52
|
+
# Configure
|
53
|
+
SYSTEM_CONFIG_FILES[:tomcat] = [
|
54
|
+
{:template => 'tomcat.erb',
|
55
|
+
:path => 'tomcat/etc/init.d/tomcat',
|
56
|
+
:mode => 0755,
|
57
|
+
:owner => 'root:root'},
|
58
|
+
|
59
|
+
{:template => 'monit.conf.erb',
|
60
|
+
:path => "tomcat/etc/monit.d/monit_tomcat.conf",
|
61
|
+
:mode => 0600,
|
62
|
+
:owner => 'root:root'},
|
63
|
+
|
64
|
+
{:template => 'conf/server.xml.erb',
|
65
|
+
:path => "conf/server.xml",
|
66
|
+
:mode => 0644,
|
67
|
+
:owner => 'root:root'},
|
68
|
+
|
69
|
+
{:template => 'conf/web.xml',
|
70
|
+
:path => "conf/web.xml",
|
71
|
+
:mode => 0644,
|
72
|
+
:owner => 'root:root'},
|
73
|
+
|
74
|
+
{:template => 'temp/empty.txt',
|
75
|
+
:path => "temp/empty.txt",
|
76
|
+
:mode => 0644,
|
77
|
+
:owner => 'root:root'},
|
78
|
+
|
79
|
+
{:template => 'logs/empty.txt',
|
80
|
+
:path => "logs/empty.txt",
|
81
|
+
:mode => 0644,
|
82
|
+
:owner => 'root:root'},
|
83
|
+
|
84
|
+
{:template => 'webapps/empty.txt',
|
85
|
+
:path => "webapps/empty.txt",
|
86
|
+
:mode => 0644,
|
87
|
+
:owner => 'root:root'},
|
88
|
+
|
89
|
+
{:template => 'work/empty.txt',
|
90
|
+
:path => "work/empty.txt",
|
91
|
+
:mode => 0644,
|
92
|
+
:owner => 'root:root'}
|
93
|
+
]
|
94
|
+
|
95
|
+
# Generating Configuration Files
|
96
|
+
desc "Generate configuration file(s) for tomcat from template(s)"
|
97
|
+
task :config_gen do
|
98
|
+
SYSTEM_CONFIG_FILES[:tomcat].each do |file|
|
99
|
+
deprec2.render_template(:tomcat, file)
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
desc 'Deploy configuration files(s) for tomcat'
|
104
|
+
task :config, :roles => :app do
|
105
|
+
|
106
|
+
deprec2.push_configs(:tomcat, SYSTEM_CONFIG_FILES[:tomcat])
|
107
|
+
symlink_init_d
|
108
|
+
symlink_monit_d
|
109
|
+
|
110
|
+
activate
|
111
|
+
end
|
112
|
+
|
113
|
+
desc "Stop tomcat"
|
114
|
+
task :stop , :roles => :app do
|
115
|
+
sudo "/etc/init.d/tomcat_#{tomcat_port} stop"
|
116
|
+
end
|
117
|
+
|
118
|
+
desc "Start tomcat"
|
119
|
+
task :start , :roles => :app do
|
120
|
+
sudo "/etc/init.d/tomcat_#{tomcat_port} start"
|
121
|
+
end
|
122
|
+
|
123
|
+
desc "Start the tomcat server"
|
124
|
+
task :restart, :roles => :app do
|
125
|
+
stop
|
126
|
+
sleep(2)
|
127
|
+
start
|
128
|
+
end
|
129
|
+
|
130
|
+
task :activate, :roles => :app do
|
131
|
+
send(run_method, "update-rc.d tomcat_#{tomcat_port} defaults")
|
132
|
+
end
|
133
|
+
|
134
|
+
task :deactivate, :roles => :app do
|
135
|
+
send(run_method, "update-rc.d -f tomcat_#{tomcat_port} remove")
|
136
|
+
end
|
137
|
+
|
138
|
+
task :symlink_init_d, :roles => :app do
|
139
|
+
sudo "ln -fs #{deploy_to}/tomcat/tomcat/etc/init.d/tomcat /etc/init.d/tomcat_#{tomcat_port}"
|
140
|
+
end
|
141
|
+
|
142
|
+
task :symlink_monit_d, :roles => :app do
|
143
|
+
sudo "ln -fs #{deploy_to}/tomcat/tomcat/etc/monit.d/monit_tomcat.conf /etc/monit.d/monit_tomcat_#{tomcat_port}.conf"
|
144
|
+
end
|
145
|
+
|
146
|
+
namespace :deploy do
|
147
|
+
desc 'deploy'
|
148
|
+
task :default do
|
149
|
+
strategy.deploy!
|
150
|
+
|
151
|
+
top.chrisrec.tomcat.stop
|
152
|
+
|
153
|
+
run "rm -f #{current_path} && ln -s #{latest_release} #{current_path}"
|
154
|
+
if dependent_projects
|
155
|
+
dependent_projects.each do | project |
|
156
|
+
name = project.scan(/:(.*)/).flatten.to_s
|
157
|
+
run "git clone #{project} #{current_path}/#{name}"
|
158
|
+
run "cd #{current_path}/#{name} && mvn clean -P #{maven_env}"
|
159
|
+
run "cd #{current_path}/#{name} && mvn compile -P #{maven_env}"
|
160
|
+
run "cd #{current_path}/#{name} && mvn install -P #{maven_env}"
|
161
|
+
end
|
162
|
+
end
|
163
|
+
|
164
|
+
run "cd #{current_path} && mvn clean -P #{maven_env}"
|
165
|
+
run "cd #{current_path} && mvn compile -P #{maven_env}"
|
166
|
+
run "cd #{current_path} && mvn package -P #{maven_env}"
|
167
|
+
|
168
|
+
sudo "rm -f #{deploy_to}/tomcat/webapps/#{tomcat_war}.war"
|
169
|
+
sudo "rm -rf #{deploy_to}/tomcat/webapps/#{tomcat_war}"
|
170
|
+
|
171
|
+
sudo "cp #{current_path}/target/#{tomcat_war}.war #{deploy_to}/tomcat/webapps"
|
172
|
+
|
173
|
+
top.chrisrec.tomcat.start
|
174
|
+
end
|
175
|
+
|
176
|
+
desc 'setup'
|
177
|
+
task :setup do
|
178
|
+
dirs = [deploy_to, releases_path]
|
179
|
+
sudo "mkdir -p #{dirs.join(' ')}"
|
180
|
+
sudo "chgrp -R #{group} #{dirs.join(' ')}"
|
181
|
+
sudo "chmod g+w #{dirs.join(' ')}"
|
182
|
+
end
|
183
|
+
|
184
|
+
desc 'rollback'
|
185
|
+
task :rollback do
|
186
|
+
if previous_release
|
187
|
+
run "rm #{current_path}; ln -s #{previous_release} #{current_path}"
|
188
|
+
else
|
189
|
+
abort "could not rollback the code because there is no prior release"
|
190
|
+
end
|
191
|
+
|
192
|
+
run "if [ `readlink #{current_path}` != #{current_release} ]; then rm -rf #{current_release}; fi"
|
193
|
+
|
194
|
+
top.chrisrec.daemon.restart
|
195
|
+
end
|
196
|
+
end
|
197
|
+
|
198
|
+
end
|
199
|
+
end
|
200
|
+
end
|