teknobingo-recipes 0.1.39
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/.gitignore +3 -0
- data/Gemfile +4 -0
- data/LICENSE +1 -0
- data/README.rdoc +18 -0
- data/Rakefile +2 -0
- data/lib/teknobingo_recipes.rb +1 -0
- data/lib/teknobingo_recipes/helpers.rb +67 -0
- data/lib/teknobingo_recipes/recipes/apache.rb +62 -0
- data/lib/teknobingo_recipes/recipes/base.rb +16 -0
- data/lib/teknobingo_recipes/recipes/check.rb +13 -0
- data/lib/teknobingo_recipes/recipes/logrotate.rb +9 -0
- data/lib/teknobingo_recipes/recipes/memcached.rb +24 -0
- data/lib/teknobingo_recipes/recipes/mogilefs.rb +146 -0
- data/lib/teknobingo_recipes/recipes/nfs.rb +99 -0
- data/lib/teknobingo_recipes/recipes/nginx.rb +75 -0
- data/lib/teknobingo_recipes/recipes/nodejs.rb +15 -0
- data/lib/teknobingo_recipes/recipes/passenger.rb +68 -0
- data/lib/teknobingo_recipes/recipes/postgresql.rb +44 -0
- data/lib/teknobingo_recipes/recipes/profile.rb +43 -0
- data/lib/teknobingo_recipes/recipes/rainbows.rb +83 -0
- data/lib/teknobingo_recipes/recipes/rbenv.rb +40 -0
- data/lib/teknobingo_recipes/recipes/redis.rb +31 -0
- data/lib/teknobingo_recipes/version.rb +3 -0
- data/teknobingo-recipes.gemspec +27 -0
- data/templates/bash/lesslog.sh +1 -0
- data/templates/bash/profile +1 -0
- data/templates/bash/prompt.sh +13 -0
- data/templates/bash/railsc.sh +1 -0
- data/templates/bash/taillog.sh +1 -0
- data/templates/init.d/nginx +362 -0
- data/templates/logrotate.erb +14 -0
- data/templates/memcached.erb +16 -0
- data/templates/mogilefsd_conf.erb +7 -0
- data/templates/mogstored_conf.erb +3 -0
- data/templates/nginx.conf.erb +23 -0
- data/templates/passenger_mod.erb +3 -0
- data/templates/postgresql.yml.erb +8 -0
- data/templates/redis_conf.erb +419 -0
- data/templates/vhosts/http_site.erb +7 -0
- metadata +98 -0
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
ZTUwOGEwMTIxMDkxYTA4NmIwM2IwZWI1MWFjMmMxNzk0NmJlNWYxNA==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
Yjc4ZTk5NTIxZTYwOGMxNDViNDMwODU3N2FmM2QzNmI2Mjg4NWNmMg==
|
7
|
+
SHA512:
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
OGUxZjkxMzk5N2JlYjAwNzQyM2MxMTZhNTg2NTI2MDJkNWMxNDMxMWI2NDYy
|
10
|
+
NmRkMzZhNGIxMDc1NDY2MzljZmEzMWJhNDkwMDMyODlkZTkxNTc3Y2NiMWRk
|
11
|
+
MDYxNTljMGMzYzRkMjU2Yzk1ZjNjNzZmZmNmOTNmYTE5ZTkwYWI=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
ZmE5YjUwZWRmNDEwYThjM2YxOThlODA0NmI0MTU4ZDkzYzlhNmQ1OGI0N2Yx
|
14
|
+
OTFkNTI2NTQ1Mzk0MGFjM2FjODk0OWY2MWYyM2Y5ZDdjMjk5NjNmYWI2Y2Zi
|
15
|
+
YmNkZTk4YjcyZTI1MzczMjc4ZWI5ZGQ3OTg3OTIyYjA0NjliNzg=
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
Copyright (c) 20013 Teknobingo AS
|
data/README.rdoc
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
=Teknobingo Recipes
|
2
|
+
|
3
|
+
Useful Capistrano recipes
|
4
|
+
|
5
|
+
==Installation
|
6
|
+
|
7
|
+
Gemfile:
|
8
|
+
gem 'teknobingo-recipes', :git => 'git@github.com:teknobingo/teknobingo-recipes.git', :branch => 'master'
|
9
|
+
|
10
|
+
To setup the initial Capistrano deploy file, go to your Rails app folder via command line and enter:
|
11
|
+
|
12
|
+
capify .
|
13
|
+
|
14
|
+
==Configuration
|
15
|
+
|
16
|
+
In deploy.rb
|
17
|
+
require 'teknobingo_recipes'
|
18
|
+
include_recipes :nginx, :rbenv, :passenger
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'teknobingo_recipes/helpers'
|
@@ -0,0 +1,67 @@
|
|
1
|
+
def set_default(name, *args, &block)
|
2
|
+
set(name, *args, &block) unless exists?(name)
|
3
|
+
end
|
4
|
+
|
5
|
+
def copy_file(from,to,options={})
|
6
|
+
tmpname = '/tmp/knutervrang'
|
7
|
+
fname = ["../config/recipes/#{stage}/#{from}", "../config/recipes/#{from}", "#{Gem.loaded_specs['teknobingo-recipes'].full_gem_path}/lib/recipes/#{from}"].keep_if do |path|
|
8
|
+
fname = File.expand_path(path, ENV['BUNDLE_GEMFILE'])
|
9
|
+
fname if File.exists? fname
|
10
|
+
end.first
|
11
|
+
put File.read(File.expand_path(fname, ENV['BUNDLE_GEMFILE'])), tmpname, options
|
12
|
+
run "#{sudo} mv #{tmpname} #{to}"
|
13
|
+
end
|
14
|
+
|
15
|
+
def remote_file_exists?(full_path)
|
16
|
+
'true' == capture("if [ -e #{full_path} ]; then echo 'true'; fi").strip
|
17
|
+
end
|
18
|
+
|
19
|
+
def template(from, to)
|
20
|
+
fname = ["../config/recipes/templates/#{stage}/#{from}", "../config/recipes/templates/#{from}", "#{Gem.loaded_specs['teknobingo-recipes'].full_gem_path}/templates/#{from}"].keep_if do |path|
|
21
|
+
fname = File.expand_path(path, ENV['BUNDLE_GEMFILE'])
|
22
|
+
fname if File.exists? fname
|
23
|
+
end.first
|
24
|
+
fname = File.expand_path(fname, ENV['BUNDLE_GEMFILE'])
|
25
|
+
erb = File.read(fname)
|
26
|
+
put ERB.new(erb).result(binding), to
|
27
|
+
end
|
28
|
+
|
29
|
+
def has_servers?(options)
|
30
|
+
find_servers(options).size > 0
|
31
|
+
end
|
32
|
+
|
33
|
+
alias has_server? has_servers?
|
34
|
+
|
35
|
+
# Add text to fil unless it is already there
|
36
|
+
def sudo_enrich_file(filename, content, search_expr = nil)
|
37
|
+
content = content.gsub("'", "'\\\\''").gsub("\n", '\n')
|
38
|
+
search_expr ||= content
|
39
|
+
run "#{sudo} sh -c \"[ -e '#{filename}' ] || touch '#{filename}'\""
|
40
|
+
run "#{sudo} sh -c \"if grep -q '#{search_expr}' #{filename}; then echo ok; else echo '#{content}' >> #{filename}; fi\""
|
41
|
+
end
|
42
|
+
def enrich_file(filename, content, search_expr = nil)
|
43
|
+
content = content.gsub("'", "'\\\\''").gsub("\n", '\n')
|
44
|
+
search_expr ||= content
|
45
|
+
run "[ -e '#{filename}' ] || touch '#{filename}'"
|
46
|
+
run "if grep -q '#{search_expr}' #{filename}; then echo ok; else echo '#{content}' >> #{filename}; fi"
|
47
|
+
end
|
48
|
+
|
49
|
+
def replace_line_in_file(filename, search_expr, new_line)
|
50
|
+
search_expr = search_expr.gsub("'", "'\\\\''").gsub("\n", '\n')
|
51
|
+
new_line = new_line.gsub("'", "'\\\\''").gsub("\n", '\n')
|
52
|
+
run "#{sudo} cp '#{filename}' '#{filename}.bak'" # keep permissions
|
53
|
+
run "#{sudo} sh -c \"sed 's/^#{search_expr}$/#{new_line}/' < '#{filename}.bak' > '#{filename}'\""
|
54
|
+
run "#{sudo} rm '#{filename}.bak'"
|
55
|
+
end
|
56
|
+
|
57
|
+
module Capistrano
|
58
|
+
class Configuration
|
59
|
+
module Loading
|
60
|
+
def include_recipes *recipes
|
61
|
+
recipes.each do |recipe|
|
62
|
+
load "#{Gem.loaded_specs['teknobingo-recipes'].full_gem_path}/lib/teknobingo_recipes/recipes/#{recipe}.rb"
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
set_default :web_server, :apache
|
2
|
+
|
3
|
+
namespace :apache do
|
4
|
+
|
5
|
+
def passenger_root
|
6
|
+
@passenger_root ||= begin
|
7
|
+
state = nil
|
8
|
+
passenger_version = nil
|
9
|
+
passenger_root = nil
|
10
|
+
run "gem list",:pty => true do |ch, stream, data|
|
11
|
+
if /passenger \((?<version>.*)\)$/ =~ data
|
12
|
+
passenger_version = version
|
13
|
+
end
|
14
|
+
end
|
15
|
+
run "gem environment",:pty => true do |ch, stream, data|
|
16
|
+
state = nil if data[-1] == ':'
|
17
|
+
if data =~ /GEM PATHS:/
|
18
|
+
state = :gems
|
19
|
+
elsif !passenger_root && state == :gems
|
20
|
+
path = data.split(' - ').last.strip
|
21
|
+
if path && path != ""
|
22
|
+
puts path.inspect
|
23
|
+
if remote_file_exists?("#{path}/gems/passenger-#{passenger_version}/buildout/apache2/mod_passenger.so")
|
24
|
+
passenger_root = "#{path}/gems/passenger-#{passenger_version}"
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
passenger_root
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
desc "Install apache"
|
34
|
+
task :install, roles: :web do
|
35
|
+
run "#{sudo} apt-get install -y apache2 apache2.2-common apache2-mpm-prefork apache2-utils libexpat1 apache2-prefork-dev ssl-cert libapache2-mod-xsendfile"
|
36
|
+
run "#{sudo} a2enmod rewrite"
|
37
|
+
run "#{sudo} a2enmod ssl"
|
38
|
+
end
|
39
|
+
after "deploy:install", "apache:install"
|
40
|
+
|
41
|
+
desc "Setup apache"
|
42
|
+
task :setup, roles: :web do
|
43
|
+
|
44
|
+
set_default :passenger_root, passenger_root
|
45
|
+
|
46
|
+
template "passenger_mod.erb", "/tmp/passenger_mod"
|
47
|
+
run "#{sudo} mv /tmp/passenger_mod /etc/apache2/mods-available/passenger.load"
|
48
|
+
run "#{sudo} a2enmod passenger"
|
49
|
+
|
50
|
+
template "http_site.erb", "/tmp/http_site"
|
51
|
+
run "#{sudo} mv /tmp/http_site /etc/apache2/sites-available/#{application}"
|
52
|
+
run "#{sudo} a2ensite #{application}"
|
53
|
+
end
|
54
|
+
after "deploy:setup", "apache:setup"
|
55
|
+
|
56
|
+
%w[start stop reload restart].each do |command|
|
57
|
+
desc "#{command} Apache"
|
58
|
+
task command, roles: :web do
|
59
|
+
run "#{sudo} /etc/init.d/apache2 #{command}"
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
namespace :deploy do
|
2
|
+
desc "Install everything onto the server"
|
3
|
+
task :install, roles: [:app, :web] do
|
4
|
+
run "#{sudo} dpkg-reconfigure grub-pc -f noninteractive"
|
5
|
+
run "#{sudo} apt-get -y update"
|
6
|
+
run "#{sudo} apt-get -y upgrade"
|
7
|
+
run "#{sudo} apt-get -y install python-software-properties"
|
8
|
+
run "#{sudo} locale-gen en_US.UTF-8"
|
9
|
+
run "#{sudo} /usr/sbin/update-locale LANG=en_US.UTF-8 LC_ALL=en_US.UTF-8"
|
10
|
+
run "#{sudo} apt-get -y install locate"
|
11
|
+
run "#{sudo} dpkg-reconfigure locales"
|
12
|
+
run "mkdir -p ~/.ssh"
|
13
|
+
run "chmod 0700 ~/.ssh"
|
14
|
+
run "ssh-keyscan -H github.com >>~/.ssh/known_hosts"
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
namespace :check do
|
2
|
+
desc "Make sure local git is in sync with remote."
|
3
|
+
task :revision, roles: :web do
|
4
|
+
unless `git rev-parse HEAD` == `git rev-parse origin/#{branch}`
|
5
|
+
puts "WARNING: HEAD is not the same as origin/#{branch}"
|
6
|
+
puts "Run `git push` to sync changes."
|
7
|
+
exit
|
8
|
+
end
|
9
|
+
end
|
10
|
+
before "deploy", "check:revision"
|
11
|
+
before "deploy:migrations", "check:revision"
|
12
|
+
before "deploy:cold", "check:revision"
|
13
|
+
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
namespace :logrotate do
|
2
|
+
desc "Rotate logs in application."
|
3
|
+
task :setup, roles: [:app, :web] do
|
4
|
+
template "logrotate.erb", '/tmp/logrotate_tmp'
|
5
|
+
run "#{sudo} mv /tmp/logrotate_tmp /etc/logrotate.d/#{application}"
|
6
|
+
run "#{sudo} chown root:root /etc/logrotate.d/#{application}"
|
7
|
+
end
|
8
|
+
after "deploy:setup", "logrotate:setup"
|
9
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
set_default :memcached_memory_limit, 64
|
2
|
+
|
3
|
+
namespace :memcached do
|
4
|
+
desc "Install Memcached"
|
5
|
+
task :install, roles: [:app, :web] do
|
6
|
+
run "#{sudo} apt-get install memcached"
|
7
|
+
end
|
8
|
+
after "deploy:install", "memcached:install"
|
9
|
+
|
10
|
+
desc "Setup Memcached"
|
11
|
+
task :setup, roles: [:app, :web] do
|
12
|
+
template "memcached.erb", "/tmp/memcached.conf"
|
13
|
+
run "#{sudo} mv /tmp/memcached.conf /etc/memcached.conf"
|
14
|
+
restart
|
15
|
+
end
|
16
|
+
after "deploy:setup", "memcached:setup"
|
17
|
+
|
18
|
+
%w[start stop restart].each do |command|
|
19
|
+
desc "#{command} Memcached"
|
20
|
+
task command, roles: [:app, :web] do
|
21
|
+
run "#{sudo} service memcached #{command}"
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,146 @@
|
|
1
|
+
require 'yaml'
|
2
|
+
|
3
|
+
set_default(:mogilefs_database) { "#{postgresql_database}_mogilefs" }
|
4
|
+
set_default :mogilefs_classes, []
|
5
|
+
set_default :mogilefs_tracker_port, 6001
|
6
|
+
|
7
|
+
namespace :mogilefs do
|
8
|
+
|
9
|
+
def postgresql_password
|
10
|
+
fname = ["#{shared_path}/config/database.yml","#{current_path}/config/database.yml"].detect do |filename|
|
11
|
+
remote_file_exists?(filename)
|
12
|
+
end
|
13
|
+
if fname
|
14
|
+
capture("ruby -e \"require 'yaml'; config = YAML.load_file('#{fname}'); puts config['#{rails_env}']['password']\"").strip
|
15
|
+
else
|
16
|
+
config = YAML.load_file('config/database.yml')
|
17
|
+
config[rails_env]['password']
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def postgresql_host
|
22
|
+
fname = ["#{shared_path}/config/database.yml","#{current_path}/config/database.yml"].detect do |filename|
|
23
|
+
remote_file_exists?(filename)
|
24
|
+
end
|
25
|
+
if fname
|
26
|
+
capture("ruby -e \"require 'yaml'; config = YAML.load_file('#{fname}'); puts config['#{rails_env}']['host']\"").strip
|
27
|
+
else
|
28
|
+
config = YAML.load_file('config/database.yml')
|
29
|
+
config[rails_env]['host']
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
desc "Install mogilefs."
|
34
|
+
task :install, roles: :app do
|
35
|
+
# MOGSTORED_RUN_WITHOUT_AIO=1
|
36
|
+
run "#{sudo} apt-get -y install liblocal-lib-perl"
|
37
|
+
run "#{sudo} apt-get -y install libcommon-sense-perl"
|
38
|
+
%w(CPAN DBD:SQLite IO:AIO MogileFS:Server MogileFS:Utils MogileFS:Store::Postgres DBD::Pg).each do |pkg|
|
39
|
+
run "#{sudo} MOGTEST_DBTYPE=SQLite perl -MCPAN -e 'force install \"#{pkg}\"'",:pty => true do |ch, stream, data|
|
40
|
+
if data =~ /Would you like to configure as much as possible automatically\? \[yes\]/
|
41
|
+
ch.send_data("\n")
|
42
|
+
elsif ["[local::lib]","sites for you? (This means connecting to the Internet) [yes]", "Would you like me to append that to /home/capistrano/.bashrc now? [yes]"].include?(data.strip)
|
43
|
+
ch.send_data("\n")
|
44
|
+
else
|
45
|
+
Capistrano::Configuration.default_io_proc.call(ch,stream,data)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
task :setup_master, roles: :app, only: {primary: true} do
|
51
|
+
|
52
|
+
run "psql -h #{postgresql_host} -d template1 -U #{postgresql_user} -c \"create database #{mogilefs_database} with owner=#{postgresql_user} encoding='UNICODE';\"",:pty => true do |ch, stream, data|
|
53
|
+
if data.strip == 'Password for user clubhouse:'
|
54
|
+
ch.send_data(postgresql_password + "\n")
|
55
|
+
elsif data.strip == "ERROR: database \"clubhouse_#{rails_env}_mogilefs\" already exists"
|
56
|
+
break
|
57
|
+
else
|
58
|
+
Capistrano::Configuration.default_io_proc.call(ch,stream,data)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
run "mogdbsetup --yes --type=Postgres --dbhost=#{postgresql_host} --dbname=#{mogilefs_database} --dbuser=#{postgresql_user} --dbpass='#{postgresql_password}'"
|
63
|
+
start
|
64
|
+
sleep 10
|
65
|
+
|
66
|
+
roles[:app].servers.each do |server|
|
67
|
+
run "mogadm --trackers=localhost:#{mogilefs_tracker_port} host add #{server} --port 7500 --status=alive", :pty => true do |ch, stream, data|
|
68
|
+
if data.strip == "Host already exists."
|
69
|
+
break
|
70
|
+
else
|
71
|
+
Capistrano::Configuration.default_io_proc.call(ch,stream,data)
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
roles[:app].servers.each_with_index do |server,i|
|
76
|
+
run "mogadm --trackers=localhost:#{mogilefs_tracker_port} device add #{server} #{i+1}", :pty => true do |ch, stream, data|
|
77
|
+
if data.strip == "Error adding device: existing_devid existing_devid"
|
78
|
+
break
|
79
|
+
else
|
80
|
+
Capistrano::Configuration.default_io_proc.call(ch,stream,data)
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
run "mogadm --trackers=localhost:#{mogilefs_tracker_port} check"
|
85
|
+
run "mogadm --trackers=localhost:#{mogilefs_tracker_port} domain add #{application}", :pty => true do |ch, stream, data|
|
86
|
+
if data.strip == "Error creating domain: domain_exists That domain already exists"
|
87
|
+
break
|
88
|
+
else
|
89
|
+
Capistrano::Configuration.default_io_proc.call(ch,stream,data)
|
90
|
+
end
|
91
|
+
end
|
92
|
+
mogilefs_classes.each do |klass|
|
93
|
+
run "mogadm --trackers=localhost:#{mogilefs_tracker_port} class add #{application} #{klass}", :pty => true do |ch, stream, data|
|
94
|
+
if data.strip == "Error creating class: class_exists That class already exists in that domain"
|
95
|
+
break
|
96
|
+
else
|
97
|
+
Capistrano::Configuration.default_io_proc.call(ch,stream,data)
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
101
|
+
end
|
102
|
+
task :setup, roles: :app do
|
103
|
+
run "#{sudo} sh -c \"adduser --disabled-login --disabled-password mogile; exit 0\"",:pty => true do |ch, stream, data|
|
104
|
+
if data =~ /\[\]: $/
|
105
|
+
ch.send_data("\n")
|
106
|
+
elsif data.strip == "Is the information correct? [Y/n]"
|
107
|
+
ch.send_data("\n")
|
108
|
+
else
|
109
|
+
Capistrano::Configuration.default_io_proc.call(ch,stream,data)
|
110
|
+
end
|
111
|
+
end
|
112
|
+
run "#{sudo} mkdir -p /etc/mogilefs"
|
113
|
+
|
114
|
+
set :mogile_db_host, postgresql_host
|
115
|
+
set :mogilefs_master, roles[:app].servers.detect{ |server| server.options[:primary] == true }
|
116
|
+
|
117
|
+
template "mogilefsd_conf.erb", "/tmp/mogilefsd_conf"
|
118
|
+
run "#{sudo} mv /tmp/mogilefsd_conf /etc/mogilefs/mogilefsd.conf"
|
119
|
+
template "mogstored_conf.erb", "/tmp/mogstored_conf"
|
120
|
+
run "#{sudo} mv /tmp/mogstored_conf /etc/mogilefs/mogstored.conf"
|
121
|
+
|
122
|
+
copy_file '../rc-scripts/mogilefsd','/etc/init.d/mogilefsd', :mode => '755'
|
123
|
+
copy_file '../rc-scripts/mogstored','/etc/init.d/mogstored', :mode => '755'
|
124
|
+
run '#{sudo} chown root:root /etc/init.d/mogilefsd'
|
125
|
+
run '#{sudo} chown root:root /etc/init.d/mogstored'
|
126
|
+
|
127
|
+
run "#{sudo} mkdir -p /var/mogdata/dev1"
|
128
|
+
run "#{sudo} mkdir -p /var/mogdata/dev2"
|
129
|
+
run "#{sudo} chown mogile:mogile /var/mogdata"
|
130
|
+
run "#{sudo} chown mogile:mogile /var/mogdata/dev1"
|
131
|
+
run "#{sudo} chown mogile:mogile /var/mogdata/dev2"
|
132
|
+
run "#{sudo} update-rc.d mogilefsd defaults"
|
133
|
+
run "#{sudo} update-rc.d mogstored defaults"
|
134
|
+
run "#{sudo} apt-get -y install sysstat"
|
135
|
+
|
136
|
+
setup_master
|
137
|
+
end
|
138
|
+
after "deploy:install", "mogilefs:install"
|
139
|
+
after "deploy:setup", "mogilefs:setup"
|
140
|
+
|
141
|
+
task :start, roles: :app do
|
142
|
+
# nohup ensures start-stop-deamon completes its backround startup process before ssh exits
|
143
|
+
run "#{sudo} nohup service mogstored start"
|
144
|
+
run "#{sudo} nohup service mogilefsd start"
|
145
|
+
end
|
146
|
+
end
|
@@ -0,0 +1,99 @@
|
|
1
|
+
namespace :nfs do
|
2
|
+
# See https://help.ubuntu.com/community/SettingUpNFSHowTo
|
3
|
+
|
4
|
+
desc 'Install nfs, and if a primary is defined nfs server will be installed'
|
5
|
+
task :install do
|
6
|
+
if has_servers? roles: :nfs, only: {primary: true}
|
7
|
+
nfs.server.install
|
8
|
+
end
|
9
|
+
nfs.client.install
|
10
|
+
end
|
11
|
+
after "deploy:install", "nfs:install"
|
12
|
+
|
13
|
+
desc 'Setup nfs, primary will setup share, others will mount share'
|
14
|
+
task :setup do
|
15
|
+
if has_servers? roles: :nfs, only: {primary: true}
|
16
|
+
nfs.server.setup
|
17
|
+
end
|
18
|
+
nfs.client.setup
|
19
|
+
end
|
20
|
+
|
21
|
+
desc 'Restart nfs (applies to server only)'
|
22
|
+
task :restart do
|
23
|
+
if has_servers? roles: :nfs, only: {primary: true}
|
24
|
+
nfs.server.restart
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
namespace :client do
|
29
|
+
desc 'Install nfs client'
|
30
|
+
task :install, roles: :nfs, except: {primary: true} do
|
31
|
+
packages = %w(rpcbind nfs-common)
|
32
|
+
packages.each do |package|
|
33
|
+
run "#{sudo} apt-get install #{package}", pty: true do |ch, stream, data|
|
34
|
+
case data.strip
|
35
|
+
when 'Do you want to continue [Y/n]?'
|
36
|
+
ch.send_data("\n")
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
desc <<-DESC
|
42
|
+
Setup nfs mount points. Define nfs_shares that are to be setup. \
|
43
|
+
You define source and mount points as a hash. Example:
|
44
|
+
set :nfs_shares, { '/var/export' => '/var/shared'}
|
45
|
+
If not specifying server path, primary will be used.
|
46
|
+
If specifying server path, that server will be used. E.g.
|
47
|
+
set :nfs_shares, { 'myserver:/var/export' => '/var/shared'}
|
48
|
+
DESC
|
49
|
+
task :setup, roles: :nfs, except: {primary: true} do
|
50
|
+
# replace_line_in_file '/etc/default/nfs-common', 'NEED_IDMAPD=.*', 'NEED_IDMAPD=yes'
|
51
|
+
nfs_shares.each do |export,share|
|
52
|
+
run "#{sudo} mkdir -p --mode=777 #{share}"
|
53
|
+
source_path = export.include?(':') ? export : "#{find_servers(roles: :nfs, only: {primary: true}).first}:#{export}"
|
54
|
+
run "#{sudo} mount #{source_path} #{share}"
|
55
|
+
sudo_enrich_file '/etc/fstab', "#{source_path} #{share} nfs auto 0 0"
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
namespace :server do
|
61
|
+
desc 'Install nfs server'
|
62
|
+
task :install, roles: :nfs, only: {primary: true} do
|
63
|
+
packages = %w(rpcbind nfs-kernel-server)
|
64
|
+
packages.each do |package|
|
65
|
+
run "#{sudo} apt-get install #{package}", pty: true do |ch, stream, data|
|
66
|
+
case data.strip
|
67
|
+
when 'Do you want to continue [Y/n]?'
|
68
|
+
ch.send_data("\n")
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
desc <<-DESC
|
75
|
+
Setup servershares. Define nfs_shares that are to be setup. \
|
76
|
+
Directories will be created unless they exists. \
|
77
|
+
You define source and mount points as a hash. Example:
|
78
|
+
set :nfs_shares, { '/var/export' => '/var/shared'}
|
79
|
+
DESC
|
80
|
+
task :setup, roles: :nfs, only: {primary: true} do
|
81
|
+
nfs_shares.each do |export,share|
|
82
|
+
run "#{sudo} mkdir -p --mode=777 #{export}"
|
83
|
+
run "#{sudo} mkdir -p --mode=777 #{share}"
|
84
|
+
run "#{sudo} mount --bind #{share} #{export}"
|
85
|
+
sudo_enrich_file '/etc/fstab', "#{share} #{export} none bind 0 0"
|
86
|
+
#replace_line_in_file '/etc/default/nfs-common', 'NEED_IDMAPD=.*', 'NEED_IDMAPD=yes'
|
87
|
+
# may need export in /etc/exports
|
88
|
+
sudo_enrich_file '/etc/exports', "#{export} *(rw,nohide,insecure,no_subtree_check,async)"
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
desc 'Restart nfs server'
|
93
|
+
task :restart, roles: :nfs, only: {primary: true} do
|
94
|
+
run "#{sudo} service nfs-kernel-server restart"
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
|
99
|
+
end
|