capistrano-cluster 0.0.10
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +21 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +38 -0
- data/Rakefile +1 -0
- data/capistrano-cluster.gemspec +29 -0
- data/files/Procfile.erb +2 -0
- data/files/apt.conf.d/10periodic +4 -0
- data/files/apt.conf.d/50unattended-upgrades +4 -0
- data/files/database.yml.erb +11 -0
- data/files/etc/hosts.erb +9 -0
- data/files/firewall.erb +8 -0
- data/files/issue.net +11 -0
- data/files/lb-sysctl.conf +24 -0
- data/files/nginx/application.conf.erb +67 -0
- data/files/nginx/lb-application.conf.erb +91 -0
- data/files/nginx/lb-nginx.conf.erb +84 -0
- data/files/nginx/nginx.conf.erb +80 -0
- data/files/pg_hba.conf.erb +10 -0
- data/files/postgresql.conf +19 -0
- data/files/redis/redis.conf +597 -0
- data/files/service.erb +67 -0
- data/files/solr/conf/lang/contractions_ca.txt +8 -0
- data/files/solr/conf/lang/contractions_fr.txt +9 -0
- data/files/solr/conf/lang/contractions_ga.txt +5 -0
- data/files/solr/conf/lang/contractions_it.txt +23 -0
- data/files/solr/conf/lang/hyphenations_ga.txt +5 -0
- data/files/solr/conf/lang/stemdict_nl.txt +6 -0
- data/files/solr/conf/lang/stoptags_ja.txt +420 -0
- data/files/solr/conf/lang/stopwords_ar.txt +125 -0
- data/files/solr/conf/lang/stopwords_bg.txt +193 -0
- data/files/solr/conf/lang/stopwords_ca.txt +220 -0
- data/files/solr/conf/lang/stopwords_cz.txt +172 -0
- data/files/solr/conf/lang/stopwords_da.txt +108 -0
- data/files/solr/conf/lang/stopwords_de.txt +292 -0
- data/files/solr/conf/lang/stopwords_el.txt +78 -0
- data/files/solr/conf/lang/stopwords_en.txt +54 -0
- data/files/solr/conf/lang/stopwords_es.txt +354 -0
- data/files/solr/conf/lang/stopwords_eu.txt +99 -0
- data/files/solr/conf/lang/stopwords_fa.txt +313 -0
- data/files/solr/conf/lang/stopwords_fi.txt +95 -0
- data/files/solr/conf/lang/stopwords_fr.txt +183 -0
- data/files/solr/conf/lang/stopwords_ga.txt +110 -0
- data/files/solr/conf/lang/stopwords_gl.txt +161 -0
- data/files/solr/conf/lang/stopwords_hi.txt +235 -0
- data/files/solr/conf/lang/stopwords_hu.txt +209 -0
- data/files/solr/conf/lang/stopwords_hy.txt +46 -0
- data/files/solr/conf/lang/stopwords_id.txt +359 -0
- data/files/solr/conf/lang/stopwords_it.txt +301 -0
- data/files/solr/conf/lang/stopwords_ja.txt +127 -0
- data/files/solr/conf/lang/stopwords_lv.txt +172 -0
- data/files/solr/conf/lang/stopwords_nl.txt +117 -0
- data/files/solr/conf/lang/stopwords_no.txt +192 -0
- data/files/solr/conf/lang/stopwords_pt.txt +251 -0
- data/files/solr/conf/lang/stopwords_ro.txt +233 -0
- data/files/solr/conf/lang/stopwords_ru.txt +241 -0
- data/files/solr/conf/lang/stopwords_sv.txt +131 -0
- data/files/solr/conf/lang/stopwords_th.txt +119 -0
- data/files/solr/conf/lang/stopwords_tr.txt +212 -0
- data/files/solr/conf/lang/userdict_ja.txt +29 -0
- data/files/solr/conf/mapping-FoldToASCII.txt +3813 -0
- data/files/solr/conf/schema.xml +111 -0
- data/files/solr/conf/solrconfig.xml +59 -0
- data/files/solr/conf/stopwords.txt +14 -0
- data/files/solr/solr.xml +45 -0
- data/files/ssh/authorized_keys.erb +4 -0
- data/files/ssh/config +3 -0
- data/files/sshd_config +40 -0
- data/files/tmux.conf +136 -0
- data/files/ufw +44 -0
- data/files/unicorn.rb.erb +63 -0
- data/lib/capistrano/cluster/application.rb +75 -0
- data/lib/capistrano/cluster/core_ext/object.rb +17 -0
- data/lib/capistrano/cluster/files.rb +57 -0
- data/lib/capistrano/cluster/packages.rb +62 -0
- data/lib/capistrano/cluster/paths.rb +18 -0
- data/lib/capistrano/cluster/service.rb +70 -0
- data/lib/capistrano/cluster/version.rb +5 -0
- data/lib/capistrano/cluster.rb +35 -0
- data/tasks/deploy/application.rake +48 -0
- data/tasks/deploy.rake +71 -0
- data/tasks/roles/app.rake +71 -0
- data/tasks/roles/cache.rake +16 -0
- data/tasks/roles/db.rake +66 -0
- data/tasks/roles/indexer.rake +132 -0
- data/tasks/roles/proxy.rake +59 -0
- data/tasks/roles/rabbit.rake +52 -0
- data/tasks/roles/resque.rake +96 -0
- data/tasks/roles/sidekiq.rake +42 -0
- data/tasks/roles/web.rake +64 -0
- data/tasks/setup/firewall.rake +53 -0
- data/tasks/setup.rake +96 -0
- metadata +221 -0
@@ -0,0 +1,57 @@
|
|
1
|
+
require 'nokogiri'
|
2
|
+
module Capistrano
|
3
|
+
module Cluster
|
4
|
+
module Files
|
5
|
+
module DSL
|
6
|
+
|
7
|
+
def remote_file(url, file, checksum: nil)
|
8
|
+
file = File.expand_path(file)
|
9
|
+
|
10
|
+
if test "[ -f '#{file}' ]"
|
11
|
+
if checksum
|
12
|
+
return if checksum == capture("sha256sum '#{file}' | awk '{ print $1}'")
|
13
|
+
execute :rm, "-f", file
|
14
|
+
else
|
15
|
+
return
|
16
|
+
end
|
17
|
+
end
|
18
|
+
execute :mkdir, "-p", File.dirname(file)
|
19
|
+
execute :wget, "-q", "-o", "/dev/null" , "-O", file, url
|
20
|
+
end
|
21
|
+
|
22
|
+
def upload_as(user, file, remote_file, options={})
|
23
|
+
group = options.fetch(:group, user)
|
24
|
+
|
25
|
+
tmp_name = "/tmp/#{SecureRandom.uuid}"
|
26
|
+
upload! file, tmp_name
|
27
|
+
|
28
|
+
sudo :mv, tmp_name, remote_file
|
29
|
+
|
30
|
+
unless test "[[ -d #{File.dirname(remote_file)} ]]"
|
31
|
+
sudo :mkdir, "-p", File.dirname(remote_file)
|
32
|
+
sudo :chown, "-R", "#{user}:#{group}", File.dirname(remote_file)
|
33
|
+
|
34
|
+
end
|
35
|
+
|
36
|
+
sudo :chown, "#{user}:#{group}", remote_file
|
37
|
+
sudo :chmod, options.fetch(:mode, 644), remote_file
|
38
|
+
|
39
|
+
end
|
40
|
+
|
41
|
+
def item(identifier)
|
42
|
+
consume = false
|
43
|
+
xml = File.read(caller.first.split(":").first).lines.select { |l| consume ||= l =~/^__END__$/ || consume}[1..-1].join()
|
44
|
+
doc = Nokogiri::HTML(xml)
|
45
|
+
doc.css("##{identifier}").inner_html
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
|
54
|
+
|
55
|
+
include Capistrano::Cluster::Files::DSL
|
56
|
+
|
57
|
+
|
@@ -0,0 +1,62 @@
|
|
1
|
+
require 'erb'
|
2
|
+
require 'ostruct'
|
3
|
+
require 'delegate'
|
4
|
+
|
5
|
+
module Capistrano
|
6
|
+
module Cluster
|
7
|
+
module Packages
|
8
|
+
module DSL
|
9
|
+
|
10
|
+
def install(*packages)
|
11
|
+
update_apt_source_list
|
12
|
+
sudo "apt-get", "-q", "-y", "--force-yes","install", *packages.flatten
|
13
|
+
end
|
14
|
+
|
15
|
+
class TemplateContext < SimpleDelegator
|
16
|
+
def initialize(obj, variables={})
|
17
|
+
__setobj__(obj)
|
18
|
+
@vars = variables
|
19
|
+
variables.each_pair do |name, value|
|
20
|
+
class <<self; self;end.send(:define_method,name, &->(){ value })
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
|
26
|
+
def file(source, locals={})
|
27
|
+
|
28
|
+
if file = file_path(source)
|
29
|
+
content = if file =~ /\.erb$/
|
30
|
+
ERB.new(File.read(file)).result(TemplateContext.new(self, locals).instance_eval { binding })
|
31
|
+
else
|
32
|
+
File.read(file)
|
33
|
+
end
|
34
|
+
StringIO.new(content)
|
35
|
+
else
|
36
|
+
raise "File #{source} not found"
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
40
|
+
|
41
|
+
def file_path(source)
|
42
|
+
lookup_paths = [fetch(:files_path), fetch(:default_templates_path)].compact
|
43
|
+
lookup_paths.map do |path|
|
44
|
+
[File.join(path, "#{source}"), File.join(path, "#{source}.erb")]
|
45
|
+
end.flatten.select do |file|
|
46
|
+
File.exists? file
|
47
|
+
end.first
|
48
|
+
end
|
49
|
+
|
50
|
+
def update_apt_source_list(forced: false)
|
51
|
+
sudo "apt-get", "-q", "-y", "update" if forced or test "[ ! -z $(find /var/lib/apt/periodic/update-success-stamp -mmin +120) ]"
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
|
60
|
+
include Capistrano::Cluster::Packages::DSL
|
61
|
+
|
62
|
+
set :files_path, fetch(:files_path, Pathname(fetch(:deploy_config_path)).dirname.join("files"))
|
@@ -0,0 +1,70 @@
|
|
1
|
+
module Capistrano
|
2
|
+
module Cluster
|
3
|
+
class Service
|
4
|
+
attr :name, :cmd
|
5
|
+
def initialize(name, &block)
|
6
|
+
@name = name
|
7
|
+
instance_eval(&block)
|
8
|
+
end
|
9
|
+
|
10
|
+
def start(*args)
|
11
|
+
@start = args.first if args.length > 0
|
12
|
+
@start || fail("no start command defined for #{@name}")
|
13
|
+
end
|
14
|
+
|
15
|
+
def working_dir(*args)
|
16
|
+
@working_dir = args.first if args.length > 0
|
17
|
+
@working_dir || "/tmp"
|
18
|
+
end
|
19
|
+
|
20
|
+
def pid_file(*args)
|
21
|
+
@pid_file = args.first if args.length > 0
|
22
|
+
@pid_file || "/var/run/#{@name}.pid"
|
23
|
+
end
|
24
|
+
|
25
|
+
def reload(*args)
|
26
|
+
@reload = args.first if args.length > 0
|
27
|
+
@reload || "stop;start"
|
28
|
+
end
|
29
|
+
|
30
|
+
def stop(*args)
|
31
|
+
@stop = args.first if args.length > 0
|
32
|
+
@stop || "kill -TERM $(< #{pid_file})"
|
33
|
+
end
|
34
|
+
|
35
|
+
def user(*args)
|
36
|
+
@user = args.first if args.length > 0
|
37
|
+
@user
|
38
|
+
end
|
39
|
+
|
40
|
+
def log_file(*args)
|
41
|
+
@log_file = args.first if args.length > 0
|
42
|
+
@log_file || "/var/log/service.#{@name}.log"
|
43
|
+
end
|
44
|
+
|
45
|
+
def script
|
46
|
+
file("service", name: name, start_cmd: start, pid_file: pid_file, working_dir: working_dir, reload_cmd: reload, stop_cmd: stop, user: user)
|
47
|
+
end
|
48
|
+
|
49
|
+
module DSL
|
50
|
+
|
51
|
+
def service(name, &block)
|
52
|
+
service = Capistrano::Cluster::Service.new(name, &block)
|
53
|
+
upload_as :root, service.script, "/etc/init.d/#{name}"
|
54
|
+
sudo :chmod, "0777", "/etc/init.d/#{name}"
|
55
|
+
sudo "update-rc.d", name, :defaults
|
56
|
+
end
|
57
|
+
|
58
|
+
end
|
59
|
+
|
60
|
+
end
|
61
|
+
|
62
|
+
end
|
63
|
+
|
64
|
+
end
|
65
|
+
|
66
|
+
|
67
|
+
|
68
|
+
include Capistrano::Cluster::Service::DSL
|
69
|
+
|
70
|
+
|
@@ -0,0 +1,35 @@
|
|
1
|
+
|
2
|
+
require 'capistrano/setup'
|
3
|
+
require 'capistrano/deploy'
|
4
|
+
require 'capistrano/bundler'
|
5
|
+
require 'capistrano/rails/assets'
|
6
|
+
require 'capistrano/rails/migrations'
|
7
|
+
require 'capistrano/rails'
|
8
|
+
|
9
|
+
require "capistrano/cluster/version"
|
10
|
+
require "capistrano/cluster/core_ext/object"
|
11
|
+
require "capistrano/cluster/application"
|
12
|
+
require "capistrano/cluster/packages"
|
13
|
+
require "capistrano/cluster/files"
|
14
|
+
require "capistrano/cluster/paths"
|
15
|
+
require "capistrano/cluster/service"
|
16
|
+
|
17
|
+
set :default_templates_path, File.expand_path('../../../files',__FILE__)
|
18
|
+
|
19
|
+
module Capistrano
|
20
|
+
module Cluster
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
tasks_path = Pathname(File.expand_path('../../../tasks/',__FILE__))
|
25
|
+
|
26
|
+
import tasks_path.join("setup.rake")
|
27
|
+
import tasks_path.join("setup/firewall.rake")
|
28
|
+
|
29
|
+
Dir.glob(tasks_path.join("*/*.rake")).each do |r|
|
30
|
+
import r
|
31
|
+
end
|
32
|
+
|
33
|
+
import tasks_path.join("deploy.rake")
|
34
|
+
import tasks_path.join("deploy/application.rake")
|
35
|
+
|
@@ -0,0 +1,48 @@
|
|
1
|
+
namespace :deploy do
|
2
|
+
|
3
|
+
namespace :check do
|
4
|
+
|
5
|
+
task :application do
|
6
|
+
|
7
|
+
on roles(:app) do
|
8
|
+
sudo :mkdir, "-p", deploy_to, shared_path.join("config")
|
9
|
+
sudo :chown, "-R", fetch(:user), deploy_to, shared_path.join("config")
|
10
|
+
end
|
11
|
+
|
12
|
+
invoke "deploy:application:secrets"
|
13
|
+
invoke "deploy:application:web"
|
14
|
+
invoke "deploy:application:indexer"
|
15
|
+
invoke "deploy:application:db"
|
16
|
+
invoke "deploy:application:proxy"
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
|
21
|
+
namespace :application do
|
22
|
+
|
23
|
+
task :secrets do
|
24
|
+
|
25
|
+
on roles(:app) do
|
26
|
+
env = StringIO.new
|
27
|
+
gc_settings = {
|
28
|
+
"RUBY_HEAP_MIN_SLOTS" => 800000,
|
29
|
+
"RUBY_FREE_MIN" => 100000,
|
30
|
+
"RUBY_GC_MALLOC_LIMIT" => 59000000
|
31
|
+
}
|
32
|
+
fetch(:secrets, {}).merge(gc_settings).each_pair do |key,value|
|
33
|
+
env.puts "export #{"#{key}".upcase}=#{value}"
|
34
|
+
end
|
35
|
+
env.rewind
|
36
|
+
upload! env, shared_path.join(".env")
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
40
|
+
|
41
|
+
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
45
|
+
|
46
|
+
before "deploy:symlink:linked_files", "check:application"
|
47
|
+
before "deploy:check:directories", "check:application"
|
48
|
+
|
data/tasks/deploy.rake
ADDED
@@ -0,0 +1,71 @@
|
|
1
|
+
require 'shellwords'
|
2
|
+
|
3
|
+
namespace :deploy do
|
4
|
+
|
5
|
+
task :restart do
|
6
|
+
|
7
|
+
on roles(:web) do
|
8
|
+
sudo "/etc/init.d/#{fetch(:application)}-web", :reload
|
9
|
+
end
|
10
|
+
|
11
|
+
end
|
12
|
+
|
13
|
+
end
|
14
|
+
|
15
|
+
|
16
|
+
class Rake::Task
|
17
|
+
def overwrite(&block)
|
18
|
+
@actions.clear
|
19
|
+
prerequisites.clear
|
20
|
+
enhance(&block)
|
21
|
+
end
|
22
|
+
def abandon
|
23
|
+
prerequisites.clear
|
24
|
+
@actions.clear
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
namespace :deploy do
|
29
|
+
after :publishing, :restart
|
30
|
+
end
|
31
|
+
|
32
|
+
Rake::Task["deploy:check:linked_files"].overwrite do
|
33
|
+
next unless any? :linked_files
|
34
|
+
on release_roles :app do |host|
|
35
|
+
linked_files(shared_path).each do |file|
|
36
|
+
unless test "[ -f #{file} ]"
|
37
|
+
error t(:linked_file_does_not_exist, file: file, host: host)
|
38
|
+
exit 1
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
|
45
|
+
Rake::Task["deploy"].clear
|
46
|
+
|
47
|
+
desc 'Deploy a new release.'
|
48
|
+
|
49
|
+
task :deploy, :app do |t,options|
|
50
|
+
|
51
|
+
applications options[:app] do
|
52
|
+
%w{ starting started
|
53
|
+
updating updated
|
54
|
+
publishing published
|
55
|
+
finishing finished }.each do |task|
|
56
|
+
|
57
|
+
invoke "deploy:#{task}"
|
58
|
+
end
|
59
|
+
|
60
|
+
end
|
61
|
+
|
62
|
+
end
|
63
|
+
|
64
|
+
|
65
|
+
|
66
|
+
desc "On app"
|
67
|
+
task :application, :app do |t,options|
|
68
|
+
if application = applications(options[:app]).first
|
69
|
+
configure_application application
|
70
|
+
end
|
71
|
+
end
|
@@ -0,0 +1,71 @@
|
|
1
|
+
namespace :setup do
|
2
|
+
|
3
|
+
namespace :app do
|
4
|
+
task :packages do
|
5
|
+
on roles(:app) do
|
6
|
+
install fetch(:app_packages)
|
7
|
+
if test "[ ! -f /etc/gemrc ]"
|
8
|
+
upload_as :root, StringIO.new("install: --no-rdoc --no-ri\nupdate: --no-rdoc --no-ri"), "/etc/gemrc"
|
9
|
+
sudo :chmod, '0644', "/etc/gemrc"
|
10
|
+
end
|
11
|
+
|
12
|
+
if test "[ -z $(which bundler) ]"
|
13
|
+
sudo :gem, 'install', 'bundler'
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
task :package_sources do
|
20
|
+
on roles(:app) do
|
21
|
+
sudo "apt-add-repository", "-y", "ppa:brightbox/ruby-ng"
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
before "setup:packages", "setup:app:package_sources"
|
29
|
+
after "setup:system", "setup:app:packages"
|
30
|
+
|
31
|
+
set :app_packages, %w[
|
32
|
+
autoconf
|
33
|
+
bind9-host
|
34
|
+
bison
|
35
|
+
build-essential
|
36
|
+
curl
|
37
|
+
daemontools
|
38
|
+
dnsutils
|
39
|
+
ed
|
40
|
+
git
|
41
|
+
imagemagick
|
42
|
+
iputils-tracepath
|
43
|
+
libcurl4-openssl-dev
|
44
|
+
libevent-dev
|
45
|
+
libglib2.0-dev
|
46
|
+
libjpeg-dev
|
47
|
+
libjpeg62
|
48
|
+
libpng12-0
|
49
|
+
libpng12-dev
|
50
|
+
libmagickcore-dev
|
51
|
+
libmagickwand-dev
|
52
|
+
libmcrypt-dev
|
53
|
+
libmysqlclient-dev
|
54
|
+
libpq-dev
|
55
|
+
libsqlite3-dev
|
56
|
+
libssl-dev
|
57
|
+
libssl0.9.8
|
58
|
+
libxml2-dev
|
59
|
+
libxslt-dev
|
60
|
+
mercurial
|
61
|
+
netcat-openbsd
|
62
|
+
ruby2.1-dev
|
63
|
+
ruby2.1
|
64
|
+
socat
|
65
|
+
sqlite3
|
66
|
+
telnet
|
67
|
+
zlib1g-dev
|
68
|
+
postgresql-client-9.3
|
69
|
+
jpegoptim
|
70
|
+
libv8-dev
|
71
|
+
]
|
@@ -0,0 +1,16 @@
|
|
1
|
+
namespace :setup do
|
2
|
+
|
3
|
+
task :cache do
|
4
|
+
on roles(:cache) do
|
5
|
+
unless test "[ -f /etc/redis/redis.conf ]"
|
6
|
+
install "redis-server"
|
7
|
+
upload_as :root, file("redis/redis.conf"), "/etc/redis/redis.conf"
|
8
|
+
sudo 'nohup /etc/init.d/redis-server restart'
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
end
|
14
|
+
|
15
|
+
|
16
|
+
after "setup:system", "setup:cache"
|
data/tasks/roles/db.rake
ADDED
@@ -0,0 +1,66 @@
|
|
1
|
+
#TODO (vvlad): tune using pgtune
|
2
|
+
namespace :setup do
|
3
|
+
|
4
|
+
task :db do
|
5
|
+
|
6
|
+
on roles(:db) do
|
7
|
+
|
8
|
+
install "postgresql-9.3", "postgresql-9.3-postgis-2.1"
|
9
|
+
allowed_hosts = roles(:app).map(&:to_s)
|
10
|
+
upload_as :postgres, file("pg_hba.conf", allowed_hosts: allowed_hosts), "/etc/postgresql/9.3/main/pg_hba.conf"
|
11
|
+
upload_as :postgres, file("postgresql.conf", allowed_hosts: allowed_hosts), "/etc/postgresql/9.3/main/postgresql.conf"
|
12
|
+
|
13
|
+
if test "[ ! -f /var/lib/postgresql/.first-time ]"
|
14
|
+
sudo :service, "postgresql", :restart
|
15
|
+
sudo :touch, '/var/lib/postgresql/.first-time'
|
16
|
+
else
|
17
|
+
sudo :service, "postgresql", :reload
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
|
25
|
+
after "setup:system", "setup:db"
|
26
|
+
|
27
|
+
namespace :deploy do
|
28
|
+
namespace :application do
|
29
|
+
|
30
|
+
task :db do
|
31
|
+
|
32
|
+
db_user = fetch(:database)[:username]
|
33
|
+
db_pass = fetch(:database)[:password]
|
34
|
+
db_name = fetch(:database).fetch(:name, fetch(:application))
|
35
|
+
enconding = fetch(:database)[:enconding] || "utf-8"
|
36
|
+
|
37
|
+
on roles(:db) do
|
38
|
+
|
39
|
+
if capture(:psql, "-U", "postgres", "template1", "-t", "-c", "SELECT 1 FROM pg_catalog.pg_user WHERE usename = '#{db_user}'".shellescape).empty?
|
40
|
+
execute :psql, "-U", "postgres", "-c", "CREATE ROLE #{db_user} LOGIN PASSWORD '#{db_pass}';".shellescape
|
41
|
+
end
|
42
|
+
|
43
|
+
if capture(:psql, "-U", "postgres", "template1", "-t", "-c", "SELECT 1 FROM pg_catalog.pg_database WHERE datname = '#{db_name}'".shellescape).empty?
|
44
|
+
execute :psql, "-U", "postgres", "-c", "CREATE DATABASE #{db_name} ENCODING '#{enconding}' OWNER #{db_user};".shellescape
|
45
|
+
execute :psql, "-U", "postgres", "#{db_name}", "-c", "CREATE EXTENSION postgis;".shellescape
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
49
|
+
|
50
|
+
on roles(:app) do
|
51
|
+
defaults = {
|
52
|
+
environment: fetch(:framework_env),
|
53
|
+
hostname: primary(:db),
|
54
|
+
name: db_name,
|
55
|
+
adapter: 'postgresql',
|
56
|
+
encoding: 'utf-8',
|
57
|
+
options:{}
|
58
|
+
}
|
59
|
+
settings = defaults.merge(fetch(:database))
|
60
|
+
upload! file("database.yml", settings), "#{shared_path}/config/database.yml"
|
61
|
+
end
|
62
|
+
|
63
|
+
end
|
64
|
+
|
65
|
+
end
|
66
|
+
end
|
@@ -0,0 +1,132 @@
|
|
1
|
+
solr_version = fetch(:solr_version, "4.9.0")
|
2
|
+
|
3
|
+
set :solr_version, solr_version
|
4
|
+
set :solr_url, fetch(:solr_url, "http://www.eu.apache.org/dist/lucene/solr/#{solr_version}/solr-#{solr_version}.tgz")
|
5
|
+
set :solr_checksum, 'ae47a89f35b5e2a6a4e55732cccc64fb10ed9779'
|
6
|
+
set :solr_data, "/var/lib/solr"
|
7
|
+
set :solr_dist, "/opt/solr"
|
8
|
+
set :solr_user, "solr"
|
9
|
+
|
10
|
+
|
11
|
+
namespace :setup do
|
12
|
+
|
13
|
+
desc "Boostraps solr nodes"
|
14
|
+
task :indexer do
|
15
|
+
|
16
|
+
on roles(:indexer) do
|
17
|
+
|
18
|
+
solr_dist = fetch(:solr_dist)
|
19
|
+
solr_data = fetch(:solr_data)
|
20
|
+
|
21
|
+
|
22
|
+
if test "[ ! -e '/etc/init.d/solr' ]"
|
23
|
+
|
24
|
+
|
25
|
+
install "openjdk-7-jre-headless"
|
26
|
+
|
27
|
+
sudo :mkdir, "-p", solr_dist
|
28
|
+
sudo :chown, "-R", "#{fetch(:user)}:#{fetch(:user)}", solr_dist
|
29
|
+
archive = "/tmp/solr-#{fetch(:solr_version)}.tgz"
|
30
|
+
remote_file fetch(:solr_url), archive, checksum: fetch(:solr_checksum)
|
31
|
+
|
32
|
+
execute :tar, "-xzC", solr_dist, "-f", archive, "--strip-components", "1"
|
33
|
+
|
34
|
+
sudo :mkdir, "-p", solr_data
|
35
|
+
sudo :chown, "-R", "#{fetch(:user)}:#{fetch(:user)}", solr_data
|
36
|
+
|
37
|
+
upload! file("solr/solr.xml"), "#{solr_data}/solr.xml"
|
38
|
+
service "solr" do
|
39
|
+
pid_file "/tmp/solr.pid"
|
40
|
+
user fetch(:user)
|
41
|
+
working_dir "#{solr_dist}/example"
|
42
|
+
start "/usr/bin/java -server -Dsolr.solr.home='#{solr_data}' -Djava.awt.headless=true -Djava.net.preferIPv4Stack=true -DSTOP.PORT=8079 -DSTOP.KEY=stopkey -Djetty.port=8983 -jar start.jar"
|
43
|
+
stop "pidof java && kill -TERM $(pidof java)"
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
47
|
+
|
48
|
+
sudo "nohup /etc/init.d/solr restart"
|
49
|
+
|
50
|
+
end
|
51
|
+
|
52
|
+
|
53
|
+
end
|
54
|
+
|
55
|
+
end
|
56
|
+
|
57
|
+
after "setup:system", "setup:indexer"
|
58
|
+
|
59
|
+
namespace :deploy do
|
60
|
+
namespace :application do
|
61
|
+
|
62
|
+
task :indexer do
|
63
|
+
|
64
|
+
config = { application: fetch(:application), name: fetch(:solr_core) }
|
65
|
+
|
66
|
+
on roles(:indexer) do
|
67
|
+
solr_data = fetch(:solr_data)
|
68
|
+
if test "[ ! -d '#{solr_data}/#{config[:name]}/data' ]"
|
69
|
+
execute :mkdir, "-p", "#{solr_data}/#{config[:name]}/data"
|
70
|
+
|
71
|
+
fetch(:solr_core_files).each do |core_file|
|
72
|
+
execute :mkdir, "-p", File.dirname("#{solr_data}/#{config[:name]}/#{core_file}")
|
73
|
+
upload! file("solr/#{core_file}"), "#{solr_data}/#{config[:name]}/#{core_file}"
|
74
|
+
end
|
75
|
+
execute :touch, "#{solr_data}/#{config[:name]}/core.properties"
|
76
|
+
end
|
77
|
+
|
78
|
+
end if config[:name]
|
79
|
+
|
80
|
+
end
|
81
|
+
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
|
86
|
+
set :solr_core_files , %w[
|
87
|
+
conf/mapping-FoldToASCII.txt
|
88
|
+
conf/schema.xml
|
89
|
+
conf/solrconfig.xml
|
90
|
+
conf/stopwords.txt
|
91
|
+
conf/lang/contractions_ca.txt
|
92
|
+
conf/lang/contractions_fr.txt
|
93
|
+
conf/lang/contractions_ga.txt
|
94
|
+
conf/lang/contractions_it.txt
|
95
|
+
conf/lang/hyphenations_ga.txt
|
96
|
+
conf/lang/stemdict_nl.txt
|
97
|
+
conf/lang/stoptags_ja.txt
|
98
|
+
conf/lang/stopwords_ar.txt
|
99
|
+
conf/lang/stopwords_bg.txt
|
100
|
+
conf/lang/stopwords_ca.txt
|
101
|
+
conf/lang/stopwords_cz.txt
|
102
|
+
conf/lang/stopwords_da.txt
|
103
|
+
conf/lang/stopwords_de.txt
|
104
|
+
conf/lang/stopwords_el.txt
|
105
|
+
conf/lang/stopwords_en.txt
|
106
|
+
conf/lang/stopwords_es.txt
|
107
|
+
conf/lang/stopwords_eu.txt
|
108
|
+
conf/lang/stopwords_fa.txt
|
109
|
+
conf/lang/stopwords_fi.txt
|
110
|
+
conf/lang/stopwords_fr.txt
|
111
|
+
conf/lang/stopwords_ga.txt
|
112
|
+
conf/lang/stopwords_gl.txt
|
113
|
+
conf/lang/stopwords_hi.txt
|
114
|
+
conf/lang/stopwords_hu.txt
|
115
|
+
conf/lang/stopwords_hy.txt
|
116
|
+
conf/lang/stopwords_id.txt
|
117
|
+
conf/lang/stopwords_it.txt
|
118
|
+
conf/lang/stopwords_ja.txt
|
119
|
+
conf/lang/stopwords_lv.txt
|
120
|
+
conf/lang/stopwords_nl.txt
|
121
|
+
conf/lang/stopwords_no.txt
|
122
|
+
conf/lang/stopwords_pt.txt
|
123
|
+
conf/lang/stopwords_ro.txt
|
124
|
+
conf/lang/stopwords_ru.txt
|
125
|
+
conf/lang/stopwords_sv.txt
|
126
|
+
conf/lang/stopwords_th.txt
|
127
|
+
conf/lang/stopwords_tr.txt
|
128
|
+
conf/lang/userdict_ja.txt
|
129
|
+
]
|
130
|
+
|
131
|
+
|
132
|
+
|