chrisrec 0.1.2 → 0.1.3

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.
Files changed (48) hide show
  1. data/Manifest +44 -0
  2. data/Rakefile +2 -2
  3. data/chrisrec.gemspec +3 -3
  4. data/pkg/chrisrec-0.1.2/Manifest +88 -0
  5. data/pkg/chrisrec-0.1.2/README +1 -0
  6. data/pkg/chrisrec-0.1.2/Rakefile +21 -0
  7. data/pkg/chrisrec-0.1.2/chrisrec.gemspec +30 -0
  8. data/pkg/chrisrec-0.1.2/lib/backgroundrb/backgroundrb.rb +22 -0
  9. data/pkg/chrisrec-0.1.2/lib/chrisrec.rb +14 -0
  10. data/pkg/chrisrec-0.1.2/lib/console/console.rb +19 -0
  11. data/pkg/chrisrec-0.1.2/lib/daemon/daemon.rb +134 -0
  12. data/pkg/chrisrec-0.1.2/lib/gitosis/gitosis.rb +131 -0
  13. data/pkg/chrisrec-0.1.2/lib/jekyll/jekyll.rb +87 -0
  14. data/pkg/chrisrec-0.1.2/lib/memcached/memcached.rb +140 -0
  15. data/pkg/chrisrec-0.1.2/lib/munin/munin.rb +135 -0
  16. data/pkg/chrisrec-0.1.2/lib/mysql/mysql.rake +95 -0
  17. data/pkg/chrisrec-0.1.2/lib/mysql/mysql.rb +51 -0
  18. data/pkg/chrisrec-0.1.2/lib/rake/rake.rb +19 -0
  19. data/pkg/chrisrec-0.1.2/lib/rakecron/rakecron.rb +35 -0
  20. data/pkg/chrisrec-0.1.2/lib/starling/starling.rb +124 -0
  21. data/pkg/chrisrec-0.1.2/lib/static/static.rb +80 -0
  22. data/pkg/chrisrec-0.1.2/lib/tomcat/tomcat.rb +202 -0
  23. data/pkg/chrisrec-0.1.2/lib/workling/workling.rb +72 -0
  24. data/pkg/chrisrec-0.1.2/template/daemon/daemon-init-script.erb +59 -0
  25. data/pkg/chrisrec-0.1.2/template/daemon/monit.conf.erb +4 -0
  26. data/pkg/chrisrec-0.1.2/template/jekyll/httpd-vhost-jekyll.conf.erb +16 -0
  27. data/pkg/chrisrec-0.1.2/template/memcached/memcached-conf.erb +1 -0
  28. data/pkg/chrisrec-0.1.2/template/memcached/memcached.erb +59 -0
  29. data/pkg/chrisrec-0.1.2/template/memcached/monit.conf.erb +8 -0
  30. data/pkg/chrisrec-0.1.2/template/memcached/start-memcached.erb +118 -0
  31. data/pkg/chrisrec-0.1.2/template/munin/httpd-vhost-munin.conf.erb +20 -0
  32. data/pkg/chrisrec-0.1.2/template/munin/munin.conf.erb +70 -0
  33. data/pkg/chrisrec-0.1.2/template/munin/munin_nginx_vhost.conf.erb +24 -0
  34. data/pkg/chrisrec-0.1.2/template/rakecron/rakecron.erb +12 -0
  35. data/pkg/chrisrec-0.1.2/template/starling/monit.conf.erb +14 -0
  36. data/pkg/chrisrec-0.1.2/template/starling/starling-init-script.erb +69 -0
  37. data/pkg/chrisrec-0.1.2/template/static/httpd-vhost-static.conf.erb +16 -0
  38. data/pkg/chrisrec-0.1.2/template/tomcat/conf/server.xml.erb +33 -0
  39. data/pkg/chrisrec-0.1.2/template/tomcat/conf/web.xml +1194 -0
  40. data/pkg/chrisrec-0.1.2/template/tomcat/logs/empty.txt +1 -0
  41. data/pkg/chrisrec-0.1.2/template/tomcat/monit.conf.erb +8 -0
  42. data/pkg/chrisrec-0.1.2/template/tomcat/temp/empty.txt +1 -0
  43. data/pkg/chrisrec-0.1.2/template/tomcat/tomcat.erb +28 -0
  44. data/pkg/chrisrec-0.1.2/template/tomcat/webapps/empty.txt +1 -0
  45. data/pkg/chrisrec-0.1.2/template/tomcat/work/empty.txt +1 -0
  46. data/pkg/chrisrec-0.1.2/template/workling/monit.conf.erb +4 -0
  47. data/pkg/chrisrec-0.1.2/template/workling/workling-init-script.erb +56 -0
  48. metadata +48 -4
@@ -0,0 +1,140 @@
1
+ Capistrano::Configuration.instance(:must_exist).load do
2
+ namespace :chrisrec do
3
+ namespace :memcached do
4
+
5
+ # role :cache, 'ADDRESS TO CACHE'
6
+
7
+ set :memcached_port, 11211
8
+ set :memcached_address, '127.0.0.1'
9
+ set :memcached_memory, 256
10
+ set :memcached_user, "memcached"
11
+ set :memcached_group, "memcached"
12
+ set :memcached_run_dir, "/var/run"
13
+ set :memcached_log_dir, "/var/log"
14
+
15
+ set :local_template_dir, "#{File.dirname(__FILE__)}/../../template"
16
+
17
+ desc "Install memcached"
18
+ task :install, :roles => :cache do
19
+ version = 'memcached-1.4.0'
20
+ set :src_package, {
21
+ :file => version + '.tar.gz',
22
+ # :md5sum => 'a08851f7fa7b15e92ee6320b7a79c321 memcached-1.2.2.tar.gz',
23
+ :dir => version,
24
+ :url => "http://www.danga.com/memcached/dist/#{version}.tar.gz",
25
+ :unpack => "tar zxf #{version}.tar.gz;",
26
+ :configure => %w{
27
+ ./configure
28
+ --prefix=/usr/local
29
+ ;
30
+ }.reject{|arg| arg.match '#'}.join(' '),
31
+ :make => 'make;',
32
+ :install => 'make install;'
33
+ }
34
+ apt.install( {:base => %w(libevent-dev)}, :stable )
35
+ deprec2.download_src(src_package, src_dir)
36
+ deprec2.install_from_src(src_package, src_dir)
37
+
38
+ # deprec2.mkdir(memcached_run_dir, :via => :sudo)
39
+ # deprec2.mkdir(memcached_log_dir, :via => :sudo)
40
+
41
+ create_memcached_user_and_group
42
+ set_perms_for_memcached_dirs
43
+ end
44
+
45
+ # Configure
46
+ SYSTEM_CONFIG_FILES[:memcached] = [
47
+ {:template => 'memcached.erb',
48
+ :path => 'memcached/etc/init.d/memcached',
49
+ :mode => 0755,
50
+ :owner => 'root:root'},
51
+
52
+ {:template => 'memcached-conf.erb',
53
+ :path => 'memcached/etc/init.d/memcached.conf',
54
+ :mode => 0755,
55
+ :owner => 'root:root'},
56
+
57
+ {:template => 'start-memcached.erb',
58
+ :path => 'memcached/etc/init.d/start-memcached',
59
+ :mode => 0755,
60
+ :owner => 'root:root'},
61
+
62
+ {:template => 'monit.conf.erb',
63
+ :path => "memcached/etc/monit.d/monit_memcached.conf",
64
+ :mode => 0600,
65
+ :owner => 'root:root'}
66
+ ]
67
+
68
+ # Generating Configuration Files
69
+ desc "Generate configuration file(s) for memcached from template(s)"
70
+ task :config_gen do
71
+ SYSTEM_CONFIG_FILES[:memcached].each do |file|
72
+ deprec2.render_template(:memcached, file)
73
+ end
74
+ end
75
+
76
+ desc 'Deploy configuration files(s) for memcached'
77
+ task :config, :roles => :cache do
78
+
79
+ deprec2.push_configs(:memcached, SYSTEM_CONFIG_FILES[:memcached])
80
+ symlink_init_d
81
+ symlink_monit_d
82
+
83
+ activate
84
+ end
85
+
86
+ desc "Stop memcached"
87
+ task :stop , :roles => :cache do
88
+ sudo "/etc/init.d/memcached_#{memcached_port} stop"
89
+ end
90
+
91
+ desc "Start memcached"
92
+ task :start , :roles => :cache do
93
+ sudo "/etc/init.d/memcached_#{memcached_port} start"
94
+ end
95
+
96
+ desc "Start the memcached server"
97
+ task :restart, :roles => :cache do
98
+ stop
99
+ sleep(2)
100
+ start
101
+ end
102
+
103
+ task :activate, :roles => :cache do
104
+ send(run_method, "update-rc.d memcached_#{memcached_port} defaults")
105
+ end
106
+
107
+ task :deactivate, :roles => :cache do
108
+ send(run_method, "update-rc.d -f memcached_#{memcached_port} remove")
109
+ end
110
+
111
+ # User/Group creation & permission assignment
112
+ # These were based off the tasks used in the mongrel recipe -
113
+ # as this was probably the nicest way to ensure these tasks
114
+ # were doing the right thing.
115
+ desc "create user and group for memcached to run as"
116
+ task :create_memcached_user_and_group, :roles => :cache do
117
+ deprec2.groupadd(memcached_group)
118
+ deprec2.useradd(memcached_user, :group => memcached_group, :homedir => false)
119
+ # Set the primary group for the memcached user (in case user already existed
120
+ # when previous command was run)
121
+ sudo "usermod --gid #{memcached_group} #{memcached_user}"
122
+ end
123
+
124
+ desc "set group ownership and permissions on dirs memcached needs to write to"
125
+ task :set_perms_for_memcached_dirs, :roles => :cache do
126
+ # sudo "chgrp -R #{memcached_group} #{memcached_run_dir}"
127
+ # sudo "chmod -R g+w #{memcached_run_dir}"
128
+ end
129
+
130
+ task :symlink_init_d, :roles => :cache do
131
+ sudo "ln -fs #{deploy_to}/memcached/memcached/etc/init.d/memcached /etc/init.d/memcached_#{memcached_port}"
132
+ end
133
+
134
+ task :symlink_monit_d, :roles => :cache do
135
+ sudo "ln -fs #{deploy_to}/memcached/memcached/etc/monit.d/monit_memcached.conf /etc/monit.d/monit_memcached_#{memcached_port}.conf"
136
+ end
137
+
138
+ end
139
+ end
140
+ end
@@ -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
@@ -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
@@ -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,80 @@
1
+ Capistrano::Configuration.instance(:must_exist).load do
2
+ namespace :chrisrec do
3
+ namespace :static do
4
+
5
+ set :local_template_dir, "#{File.dirname(__FILE__)}/../../template"
6
+
7
+ desc "Install static site"
8
+ task :install, :roles => :app do
9
+ top.deprec.rails.setup_user_perms
10
+ top.deprec.rails.create_app_user_and_group
11
+ top.deprec.rails.setup_paths
12
+ top.deprec.rails.setup_shared_dirs
13
+
14
+ top.chrisrec.static.deploy.setup
15
+ end
16
+
17
+ PROJECT_CONFIG_FILES[:static] = [
18
+
19
+ {:template => "httpd-vhost-static.conf.erb",
20
+ :path => 'conf/httpd-vhost-static.conf',
21
+ :mode => 0755,
22
+ :owner => 'root:root'}
23
+ ]
24
+
25
+
26
+ desc "Generate configuration file(s) for static site from template(s)"
27
+ task :config_gen do
28
+ PROJECT_CONFIG_FILES[:static].each do |file|
29
+ deprec2.render_template(:static, file)
30
+ end
31
+ end
32
+
33
+ desc 'Deploy configuration files(s) for static site'
34
+ task :config, :roles => :web do
35
+ deprec2.push_configs(:static, PROJECT_CONFIG_FILES[:static])
36
+ symlink_apache_vhost
37
+
38
+ top.deprec.apache.restart
39
+ end
40
+
41
+ task :symlink_apache_vhost, :roles => :web do
42
+ sudo "ln -sf #{deploy_to}/static/conf/httpd-vhost-static.conf /etc/apache2/sites-available/#{application}"
43
+ sudo "ln -sf #{deploy_to}/static/conf/httpd-vhost-static.conf /etc/apache2/sites-enabled/#{application}"
44
+ end
45
+
46
+ namespace :deploy do
47
+ desc 'deploy'
48
+ task :default do
49
+ strategy.deploy!
50
+
51
+ run "rm -f #{current_path} && ln -s #{latest_release}/www #{current_path}"
52
+
53
+ top.deprec.apache.restart
54
+ end
55
+
56
+ desc 'setup'
57
+ task :setup do
58
+ dirs = [deploy_to, releases_path]
59
+ sudo "mkdir -p #{dirs.join(' ')}"
60
+ sudo "chgrp -R #{group} #{dirs.join(' ')}"
61
+ sudo "chmod g+w #{dirs.join(' ')}"
62
+ end
63
+
64
+ desc 'rollback'
65
+ task :rollback do
66
+ if previous_release
67
+ run "rm #{current_path}; ln -s #{previous_release} #{current_path}"
68
+ else
69
+ abort "could not rollback the code because there is no prior release"
70
+ end
71
+
72
+ run "if [ `readlink #{current_path}` != #{current_release} ]; then rm -rf #{current_release}; fi"
73
+
74
+ top.deprec.apache.restart
75
+ end
76
+ end
77
+
78
+ end
79
+ end
80
+ end