capobvious 0.2.95 → 0.3.pre
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +92 -0
- data/lib/capistrano/ext/capobvious.rb +75 -460
- data/lib/capobvious/recipes/assets.rb +29 -0
- data/lib/capobvious/recipes/backup.rb +50 -0
- data/lib/capobvious/recipes/bundle.rb +11 -0
- data/lib/capobvious/recipes/db.rb +73 -0
- data/lib/capobvious/recipes/delayed_job.rb +17 -0
- data/lib/capobvious/recipes/import.rb +15 -0
- data/lib/capobvious/recipes/logrotate.rb +29 -0
- data/lib/capobvious/recipes/rake.rb +12 -0
- data/lib/capobvious/recipes/sitemap_generator.rb +9 -0
- data/lib/capobvious/recipes/unicorn.rb +67 -0
- data/lib/capobvious/recipes/whenever.rb +8 -0
- data/lib/capobvious/version.rb +1 -1
- metadata +17 -6
- data/README.markdown +0 -63
data/README.md
ADDED
@@ -0,0 +1,92 @@
|
|
1
|
+
# Capobvious
|
2
|
+
|
3
|
+
capobvious is a recipes, which i use every day
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'capobvious'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install capobvious
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
If project don't have capistrano yet, you can run
|
22
|
+
```sh
|
23
|
+
capobvious .
|
24
|
+
```
|
25
|
+
Inside of you'r project, it create Capfile and config/deploy.rb (you need to configure it)
|
26
|
+
|
27
|
+
Or if you have exsisting project with capistrano and you want to use all recipes - just add to the end of Capfile
|
28
|
+
```ruby
|
29
|
+
require 'capistrano/ext/capobvious'
|
30
|
+
```
|
31
|
+
|
32
|
+
## Recipes
|
33
|
+
|
34
|
+
### unicorn
|
35
|
+
```ruby
|
36
|
+
require 'capobvious/recipes/unicorn'
|
37
|
+
```
|
38
|
+
```sh
|
39
|
+
cap unicorn:start
|
40
|
+
cap unicorn:stop
|
41
|
+
cap unicorn:restart
|
42
|
+
```
|
43
|
+
### db
|
44
|
+
```ruby
|
45
|
+
require 'capobvious/recipes/db'
|
46
|
+
```
|
47
|
+
```sh
|
48
|
+
cap db:create # Will create user and production database, taken from database.yml
|
49
|
+
cap db:seed # rake db:seed
|
50
|
+
cap db:migrate # rake db:migrate
|
51
|
+
cap db:pg_import # import remote server postgresql database to your development postgresql database
|
52
|
+
# IT WILL DELETE YOUR DEV DATABASE
|
53
|
+
```
|
54
|
+
### rake
|
55
|
+
```ruby
|
56
|
+
require 'capobvious/recipes/rake'
|
57
|
+
```
|
58
|
+
```sh
|
59
|
+
cap rake TASK='your:custom:task'
|
60
|
+
```
|
61
|
+
### import
|
62
|
+
```ruby
|
63
|
+
require 'capobvious/recipes/import'
|
64
|
+
```
|
65
|
+
```sh
|
66
|
+
cap import:sys # Import shared/system folder from server to you development machine
|
67
|
+
# (with rsync works much faster)
|
68
|
+
```
|
69
|
+
### backup
|
70
|
+
```ruby
|
71
|
+
require 'capobvious/recipes/backup'
|
72
|
+
```
|
73
|
+
```sh
|
74
|
+
cap backup:db # Backup postgresql server database to local project/tmp/backup folder
|
75
|
+
cap backup:sys # Backup shared/system folder to local project/tmp/backup folder
|
76
|
+
cap backup:all # Run backup:db backup:sys
|
77
|
+
```
|
78
|
+
### bundle
|
79
|
+
```ruby
|
80
|
+
require 'capobvious/recipes/bundle'
|
81
|
+
```
|
82
|
+
```sh
|
83
|
+
cap bundle:install # run automatically on deploy
|
84
|
+
```
|
85
|
+
|
86
|
+
## Contributing
|
87
|
+
|
88
|
+
1. Fork it
|
89
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
90
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
91
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
92
|
+
5. Create new Pull Request
|
@@ -1,70 +1,77 @@
|
|
1
1
|
#$:.unshift(File.expand_path('./lib', ENV['rvm_path']))
|
2
2
|
require "rvm/capistrano"
|
3
|
+
require 'capobvious/recipes/unicorn'
|
4
|
+
require 'capobvious/recipes/delayed_job'
|
5
|
+
require 'capobvious/recipes/sitemap_generator'
|
6
|
+
require 'capobvious/recipes/assets'
|
7
|
+
require 'capobvious/recipes/bundle'
|
8
|
+
require 'capobvious/recipes/db'
|
9
|
+
require 'capobvious/recipes/backup'
|
10
|
+
require 'capobvious/recipes/logrotate'
|
11
|
+
require 'capobvious/recipes/whenever'
|
12
|
+
require 'capobvious/recipes/rake'
|
13
|
+
require 'capobvious/recipes/import'
|
14
|
+
|
15
|
+
Capistrano::Configuration.instance(:must_exist).load do
|
16
|
+
_cset(:ruby_version) { RUBY_VERSION }
|
17
|
+
_cset :rvm_type, :user
|
18
|
+
_cset :rails_env, 'production'
|
19
|
+
_cset :branch, 'master'
|
20
|
+
_cset :deploy_via, :remote_cache
|
21
|
+
_cset :keep_releases, 5
|
22
|
+
_cset :use_sudo, false
|
23
|
+
_cset :scm, :git
|
24
|
+
_cset :del_backup, true
|
25
|
+
|
26
|
+
set :rvmrc_string ,"rvm use #{fetch(:ruby_version)}"
|
27
|
+
after "deploy:update_code", "create:rvmrc"
|
28
|
+
after "deploy:update", "deploy:cleanup"
|
3
29
|
|
4
|
-
|
5
|
-
rvmrc = "rvm use #{rvm_ruby_string}" if exists?(:rvm_ruby_string)
|
6
|
-
set :rvm_type, :user
|
30
|
+
#set :deploy_to, (exists?(:deploy_folder)? fetch(:deploy_folder) : "/home/#{user}/www/#{application}")
|
7
31
|
|
8
32
|
default_run_options[:pty] = true
|
9
33
|
ssh_options[:forward_agent] = true
|
10
34
|
|
11
|
-
set :rails_env, "production" unless exists?(:rails_env)
|
12
|
-
set :branch, "master" unless exists?(:branch)
|
13
|
-
if exists?(:deploy_folder)
|
14
|
-
set :deploy_to, fetch(:deploy_folder)
|
15
|
-
else
|
16
|
-
set :deploy_to, "/home/#{user}/www/#{application}"
|
17
|
-
end
|
18
|
-
set :deploy_via, :remote_cache unless exists?(:deploy_via)
|
19
|
-
set :keep_releases, 5 unless exists?(:keep_releases)
|
20
|
-
set :use_sudo, false unless exists?(:use_sudo)
|
21
|
-
set :scm, :git unless exists?(:scm)
|
22
|
-
|
23
|
-
set :unicorn_init, "unicorn_#{application}"
|
24
|
-
set :unicorn_conf, "#{current_path}/config/unicorn.rb"
|
25
|
-
set :unicorn_pid, "#{shared_path}/pids/unicorn.pid"
|
26
|
-
|
27
|
-
psql = "psql -h localhost"
|
28
|
-
psql_postgres = "#{psql} -U postgres"
|
29
|
-
|
30
|
-
database_yml_path = "config/database.yml"
|
31
|
-
|
32
|
-
serv_path = "#{current_path}/#{database_yml_path}"
|
33
|
-
#if capture("if [ -f #{serv_path} ]; then echo '1'; fi") == '1'
|
34
|
-
# database_yml = capture("cat #{serv_path}")
|
35
|
-
#else
|
36
|
-
database_yml = File.open(database_yml_path) rescue nil
|
37
|
-
#end
|
38
|
-
if database_yml
|
39
|
-
config = YAML::load(database_yml)
|
40
|
-
adapter = config[rails_env]["adapter"]
|
41
|
-
database = config[rails_env]["database"]
|
42
|
-
db_username = config[rails_env]["username"]
|
43
|
-
db_password = config[rails_env]["password"]
|
44
|
-
|
45
|
-
local_rails_env = 'development'
|
46
|
-
local_adapter = config[local_rails_env]["adapter"]
|
47
|
-
local_database = config[local_rails_env]["database"]
|
48
|
-
local_db_username = config[local_rails_env]["username"]||`whoami`.chop
|
49
|
-
local_db_password = config[local_rails_env]["password"]
|
50
|
-
end
|
51
|
-
|
52
|
-
set :local_folder_path, "tmp/backup"
|
53
|
-
set :timestamp, Time.new.to_i.to_s
|
54
|
-
set :db_archive_ext, "tar.bz2"
|
55
|
-
set :arch_extract, "tar -xvjf"
|
56
|
-
set :arch_create, "tar -cvjf"
|
57
|
-
|
58
|
-
set :db_file_name, "#{database}-#{timestamp}.sql"
|
59
|
-
set :sys_file_name, "#{application}-system-#{timestamp}.#{db_archive_ext}"
|
60
|
-
set :del_backup, true
|
61
35
|
|
62
36
|
def gem_use?(name)
|
63
37
|
gemfile_lock = File.read("Gemfile.lock")
|
64
38
|
return (gemfile_lock =~ /^\s*#{name}\s+\(/)? true : false
|
65
39
|
end
|
66
40
|
|
67
|
-
|
41
|
+
def which(name)
|
42
|
+
str = capture("which #{name}").chop
|
43
|
+
return false if str == ''
|
44
|
+
str
|
45
|
+
rescue
|
46
|
+
false
|
47
|
+
end
|
48
|
+
def local_which(name)
|
49
|
+
str = `which #{name}`.chop
|
50
|
+
return false if str == ''
|
51
|
+
str
|
52
|
+
rescue
|
53
|
+
false
|
54
|
+
end
|
55
|
+
def ssh_port
|
56
|
+
exists?(:port) ? fetch(:port) : 22
|
57
|
+
end
|
58
|
+
def local_gem_available?(name)
|
59
|
+
Gem::Specification.find_by_name(name)
|
60
|
+
rescue Gem::LoadError
|
61
|
+
false
|
62
|
+
rescue
|
63
|
+
Gem.available?(name)
|
64
|
+
end
|
65
|
+
|
66
|
+
|
67
|
+
def file_size(file_path)
|
68
|
+
size = run("wc -c #{file_path} | cut -d' ' -f1")
|
69
|
+
return size
|
70
|
+
end
|
71
|
+
|
72
|
+
|
73
|
+
|
74
|
+
VarGems = {'delayed_job' => :delayed_job, 'activerecord-postgres-hstore' => :hstore, 'sitemap_generator' => :sitemap_generator, 'whenever' => 'whenever'}
|
68
75
|
|
69
76
|
VarGems.each do |gem,var|
|
70
77
|
gem = gem.to_s
|
@@ -78,95 +85,17 @@ Capistrano::Configuration.instance.load do
|
|
78
85
|
end
|
79
86
|
end
|
80
87
|
|
81
|
-
after 'deploy:update_code', 'bundle:install'
|
82
|
-
after "deploy:update", "deploy:cleanup"
|
83
|
-
|
84
|
-
if !exists?(:assets) || fetch(:assets) == true
|
85
|
-
after 'deploy:update_code', 'assets:precompile'
|
86
|
-
before 'deploy:finalize_update', 'assets:symlink'
|
87
|
-
end
|
88
|
-
after "deploy:update_code", "auto:run"
|
89
|
-
|
90
|
-
namespace :assets do
|
91
|
-
desc "Local Assets precompile"
|
92
|
-
task :local_precompile do
|
93
|
-
system("bundle exec rake assets:precompile && cd public && tar czf assets.tar.gz assets/")
|
94
|
-
upload("public/assets.tar.gz","#{latest_release}/public/assets.tar.gz")
|
95
|
-
system("rm public/assets.tar.gz && rm -rf tmp/assets && mv public/assets tmp/assets")
|
96
|
-
run("cd #{latest_release}/public && rm -rf assets/ && tar xzf assets.tar.gz && rm assets.tar.gz")
|
97
|
-
end
|
98
|
-
desc "Assets precompile"
|
99
|
-
task :precompile, :roles => :web, :except => { :no_release => true } do
|
100
|
-
run("cd #{latest_release} && bundle exec rake RAILS_ENV=#{rails_env} assets:precompile")
|
101
|
-
end
|
102
|
-
task :symlink, :roles => :web, :except => { :no_release => true } do
|
103
|
-
run <<-CMD
|
104
|
-
rm -rf #{latest_release}/public/assets &&
|
105
|
-
mkdir -p #{latest_release}/public &&
|
106
|
-
mkdir -p #{shared_path}/assets &&
|
107
|
-
ln -s #{shared_path}/assets #{latest_release}/public/assets
|
108
|
-
CMD
|
109
|
-
end
|
110
|
-
end
|
111
|
-
|
112
|
-
namespace :delayed_job do
|
113
|
-
desc 'Start the delayed_job process'
|
114
|
-
task :start, :roles => :app do
|
115
|
-
run "cd #{latest_release} && RAILS_ENV=#{rails_env} script/delayed_job start"
|
116
|
-
end
|
117
|
-
desc "Restart the delayed_job process"
|
118
|
-
task :restart, :roles => :app do
|
119
|
-
logger.important 'Restarting delayed_job process'
|
120
|
-
run "cd #{latest_release}; RAILS_ENV=#{rails_env} script/delayed_job restart"
|
121
|
-
end
|
122
|
-
desc 'Stop the delayed_job process'
|
123
|
-
task :stop, :roles => :app do
|
124
|
-
run "cd #{latest_release} && RAILS_ENV=#{rails_env} script/delayed_job stop"
|
125
|
-
end
|
126
|
-
end
|
127
|
-
|
128
|
-
namespace :sitemap_generator do
|
129
|
-
desc 'Start rack refresh sitemap project'
|
130
|
-
task :refresh do
|
131
|
-
run "cd #{latest_release} && bundle exec rake RAILS_ENV=#{rails_env} sitemap:refresh"
|
132
|
-
end
|
133
|
-
end
|
134
|
-
|
135
|
-
after "deploy:update_code", "create:dbconf"
|
136
88
|
namespace :create do
|
137
|
-
|
138
|
-
create.rvmrc if exists?(:rvmrc)
|
139
|
-
end
|
140
|
-
desc "Create .rvmrc & files"
|
89
|
+
desc "Create .rvmrc"
|
141
90
|
task :rvmrc do
|
142
|
-
put
|
143
|
-
end
|
144
|
-
task :dbconf do
|
145
|
-
serv_path = (exists?(:dbconf) && fetch(:dbconf)) || "#{database_yml_path}.server"
|
146
|
-
if File.exist?(serv_path)
|
147
|
-
run "cd #{latest_release} && cp -v #{serv_path} #{database_yml_path}"
|
148
|
-
end
|
149
|
-
end
|
150
|
-
end
|
151
|
-
namespace :bundle do
|
152
|
-
desc "Run bundle install"
|
153
|
-
task :install do
|
154
|
-
deployment = "--deployment --quiet"
|
155
|
-
without = ['development','test','production']-[rails_env]
|
156
|
-
run "cd #{latest_release} && bundle install --without #{without.join(" ")}"
|
91
|
+
put rvmrc_string, "#{latest_release}/.rvmrc"
|
157
92
|
end
|
158
93
|
end
|
159
94
|
|
95
|
+
|
96
|
+
after "deploy:update_code", "auto:run"
|
160
97
|
namespace :auto do
|
161
98
|
task :run do
|
162
|
-
# bundle.install
|
163
|
-
# if exists?(:assets) && fetch(:assets) == true
|
164
|
-
# assets.precompile
|
165
|
-
# end
|
166
|
-
create.files
|
167
|
-
if exists?(:sphinx) && fetch(:sphinx) == true
|
168
|
-
sphinx.symlink
|
169
|
-
end
|
170
99
|
if exists?(:auto_migrate) && fetch(:auto_migrate) == true
|
171
100
|
db.migrate
|
172
101
|
end
|
@@ -182,10 +111,8 @@ Capistrano::Configuration.instance.load do
|
|
182
111
|
task :prepare do
|
183
112
|
db.create
|
184
113
|
nginx.conf
|
185
|
-
install.p7zip
|
186
114
|
end
|
187
115
|
|
188
|
-
|
189
116
|
task :runtask do
|
190
117
|
path = "#{latest_release}/script/autorun.task"
|
191
118
|
if remote_file_exists?(path)
|
@@ -199,87 +126,12 @@ Capistrano::Configuration.instance.load do
|
|
199
126
|
end
|
200
127
|
|
201
128
|
|
202
|
-
namespace :db do
|
203
|
-
task :create do
|
204
|
-
if adapter == "postgresql"
|
205
|
-
run "echo \"create user #{db_username} with password '#{db_password}';\" | #{sudo} -u postgres psql"
|
206
|
-
run "echo \"create database #{database} owner #{db_username};\" | #{sudo} -u postgres psql"
|
207
|
-
run "echo \"CREATE EXTENSION IF NOT EXISTS hstore;\" | #{sudo} -u postgres psql #{database}" if exists?(:hstore) && fetch(:hstore) == true
|
208
|
-
else
|
209
|
-
puts "Cannot create, adapter #{adapter} is not implemented yet"
|
210
|
-
end
|
211
|
-
end
|
212
|
-
task :seed do
|
213
|
-
run "cd #{latest_release} && bundle exec rake RAILS_ENV=#{rails_env} db:seed"
|
214
|
-
end
|
215
|
-
task :reset do
|
216
|
-
run "cd #{latest_release} && bundle exec rake RAILS_ENV=#{rails_env} db:reset"
|
217
|
-
end
|
218
|
-
task :hard_reset do
|
219
|
-
run "cd #{latest_release} && bundle exec rake RAILS_ENV=#{rails_env} db:migrate VERSION=0 && bundle exec rake RAILS_ENV=#{rails_env} db:migrate && bundle exec rake RAILS_ENV=#{rails_env} db:seed"
|
220
|
-
end
|
221
129
|
|
222
|
-
task :migrate do
|
223
|
-
run "cd #{latest_release} && bundle exec rake RAILS_ENV=#{rails_env} db:migrate"
|
224
|
-
end
|
225
|
-
task :import do
|
226
|
-
file_name = "#{db_file_name}.#{db_archive_ext}"
|
227
|
-
file_path = "#{local_folder_path}/#{file_name}"
|
228
|
-
system "cd #{local_folder_path} && #{arch_extract} #{file_name}"
|
229
|
-
system "echo \"drop database IF EXISTS #{local_database}\" | #{psql_postgres}"
|
230
|
-
system "echo \"create database #{local_database} owner #{local_db_username};\" | #{psql_postgres}"
|
231
|
-
# system "#{psql_postgre} #{local_database} < #{local_folder_path}/#{db_file_name}"
|
232
|
-
puts "ENTER your development password: #{local_db_password}"
|
233
|
-
system "#{psql} -U#{local_db_username} #{local_database} < #{local_folder_path}/#{db_file_name}"
|
234
|
-
system "rm #{local_folder_path}/#{db_file_name}"
|
235
|
-
end
|
236
|
-
task :pg_import do
|
237
|
-
backup.db
|
238
|
-
db.import
|
239
|
-
end
|
240
|
-
end
|
241
|
-
|
242
|
-
def which(name)
|
243
|
-
str = capture("which #{name}").chop
|
244
|
-
return false if str == ''
|
245
|
-
str
|
246
|
-
rescue
|
247
|
-
false
|
248
|
-
end
|
249
|
-
def local_which(name)
|
250
|
-
str = `which #{name}`.chop
|
251
|
-
return false if str == ''
|
252
|
-
str
|
253
|
-
rescue
|
254
|
-
false
|
255
|
-
end
|
256
|
-
def ssh_port
|
257
|
-
exists?(:port) ? fetch(:port) : 22
|
258
|
-
end
|
259
130
|
|
260
131
|
|
261
|
-
namespace :import do
|
262
|
-
task :sys do
|
263
|
-
#system "rm -rfv public/system/"
|
264
|
-
if which('rsync') && local_which('rsync')
|
265
|
-
logger.important('Importing with rsync', 'import:sys')
|
266
|
-
system "rsync -avz --rsh='ssh -p#{ssh_port}' #{user}@#{serv}:#{shared_path}/system public/"
|
267
|
-
else
|
268
|
-
backup.sys
|
269
|
-
system "cd public && #{arch_extract} ../#{local_folder_path}/#{sys_file_name}"
|
270
|
-
end
|
271
|
-
end
|
272
|
-
end
|
273
132
|
namespace :export do
|
274
133
|
end
|
275
134
|
|
276
|
-
#def prompt_with_default(var, default)
|
277
|
-
# set(var) do
|
278
|
-
# Capistrano::CLI.ui.ask “#{var} [#{default}] : ”
|
279
|
-
# end
|
280
|
-
# set var, default if eval(“#{var.to_s}.empty?”)
|
281
|
-
#end
|
282
|
-
|
283
135
|
namespace :restore do
|
284
136
|
task :sys do
|
285
137
|
result = {}
|
@@ -306,65 +158,7 @@ Capistrano::Configuration.instance.load do
|
|
306
158
|
end
|
307
159
|
end
|
308
160
|
|
309
|
-
# PRIKHA-TASK
|
310
|
-
desc "Run custom task usage: cap rake TASK=patch:project_category"
|
311
|
-
task :rake do
|
312
|
-
if ENV.has_key?('TASK')
|
313
|
-
p "running rake task: #{ENV['TASK']}"
|
314
|
-
run "cd #{current_path} && bundle exec rake RAILS_ENV=#{rails_env} #{ENV['TASK']}"
|
315
|
-
else
|
316
|
-
puts 'Please specify correct task: cap rake TASK= some_task'
|
317
|
-
end
|
318
|
-
end
|
319
161
|
|
320
|
-
namespace :backup do
|
321
|
-
desc "Backup a database"
|
322
|
-
task :db do
|
323
|
-
file_name = fetch(:db_file_name)
|
324
|
-
archive_ext = fetch(:db_archive_ext)
|
325
|
-
dump_file_path = "#{shared_path}/backup/#{file_name}"
|
326
|
-
output_file = "#{file_name}.#{archive_ext}"
|
327
|
-
output_file_path = "#{dump_file_path}.#{archive_ext}"
|
328
|
-
require 'yaml'
|
329
|
-
run "mkdir -p #{shared_path}/backup"
|
330
|
-
if adapter == "postgresql"
|
331
|
-
logger.important("Backup database #{database}", "Backup:db")
|
332
|
-
run "export PGPASSWORD=\"#{db_password}\" && pg_dump -U #{db_username} #{database} > #{dump_file_path}"
|
333
|
-
run "cd #{shared_path}/backup && #{arch_create} #{output_file} #{file_name} && rm #{dump_file_path}"
|
334
|
-
else
|
335
|
-
puts "Cannot backup, adapter #{adapter} is not implemented for backup yet"
|
336
|
-
end
|
337
|
-
system "mkdir -p #{local_folder_path}"
|
338
|
-
download_path = "#{local_folder_path}/#{file_name}.#{archive_ext}"
|
339
|
-
logger.important("Downloading database to #{download_path}", "Backup:db")
|
340
|
-
download(output_file_path, download_path)
|
341
|
-
run "rm -v #{output_file_path}" if fetch(:del_backup)
|
342
|
-
end
|
343
|
-
desc "Backup public/system folder"
|
344
|
-
task :sys do
|
345
|
-
file_path = "#{shared_path}/backup/#{sys_file_name}"
|
346
|
-
logger.important("Backup shared/system folder", "Backup:sys")
|
347
|
-
run "#{arch_create} #{file_path} -C #{shared_path} system"
|
348
|
-
download_path = "#{local_folder_path}/#{sys_file_name}"
|
349
|
-
logger.important("Downloading system to #{download_path}", "Backup:db")
|
350
|
-
download(file_path, download_path)
|
351
|
-
run "rm -v #{file_path}" if fetch(:del_backup)
|
352
|
-
end
|
353
|
-
task :all do
|
354
|
-
backup.db
|
355
|
-
backup.sys
|
356
|
-
end
|
357
|
-
desc "Clean backup folder"
|
358
|
-
task :clean do
|
359
|
-
run "rm -rfv #{shared_path}/backup/*"
|
360
|
-
end
|
361
|
-
end
|
362
|
-
if exists?(:backup_db) && fetch(:backup_db) == true
|
363
|
-
before "deploy:update", "backup:db"
|
364
|
-
end
|
365
|
-
if exists?(:backup_sys) && fetch(:backup_sys) == true
|
366
|
-
before "deploy:update", "backup:sys"
|
367
|
-
end
|
368
162
|
|
369
163
|
|
370
164
|
namespace :nginx do
|
@@ -477,12 +271,16 @@ Capistrano::Configuration.instance.load do
|
|
477
271
|
end
|
478
272
|
end
|
479
273
|
|
480
|
-
|
274
|
+
after 'deploy:update_code', 'sphinx:symlink' if exists?(:sphinx) && fetch(:sphinx)
|
481
275
|
namespace :sphinx do
|
482
276
|
desc "Rebuild indexes"
|
483
277
|
task :rebuild, :roles => :app, :except => {:no_release => true} do
|
484
278
|
run "cd #{latest_release} && bundle exec rake RAILS_ENV=#{rails_env} ts:rebuild"
|
485
279
|
end
|
280
|
+
desc "Reindex"
|
281
|
+
task :reindex, :roles => :app, :except => {:no_release => true} do
|
282
|
+
run "cd #{latest_release} && bundle exec rake RAILS_ENV=#{rails_env} ts:reindex"
|
283
|
+
end
|
486
284
|
desc "Sphinx start"
|
487
285
|
task :start, :roles => :app, :except => {:no_release => true} do
|
488
286
|
run "cd #{latest_release} && bundle exec rake RAILS_ENV=#{rails_env} ts:start"
|
@@ -497,13 +295,9 @@ Capistrano::Configuration.instance.load do
|
|
497
295
|
end
|
498
296
|
desc "Re-establish symlinks"
|
499
297
|
task :symlink do
|
500
|
-
|
501
|
-
|
502
|
-
|
503
|
-
run "ln -sfv #{shared_path}/sphinx/#{rails_env}.sphinx.conf #{release_path}/config/#{rails_env}.sphinx.conf"
|
504
|
-
else
|
505
|
-
puts "sphinx is disabled in config/deploy.rb to enable add line set :sphinx, true"
|
506
|
-
end
|
298
|
+
run "mkdir -pv #{shared_path}/sphinx"
|
299
|
+
run "rm -rf #{release_path}/db/sphinx && ln -sfv #{shared_path}/sphinx #{release_path}/db/sphinx"
|
300
|
+
run "ln -sfv #{shared_path}/sphinx/#{rails_env}.sphinx.conf #{release_path}/config/#{rails_env}.sphinx.conf"
|
507
301
|
end
|
508
302
|
end
|
509
303
|
|
@@ -519,13 +313,13 @@ Capistrano::Configuration.instance.load do
|
|
519
313
|
|
520
314
|
desc "init"
|
521
315
|
task :init, :roles => :web do
|
522
|
-
join_ruby =
|
316
|
+
join_ruby = ruby_version[/\d.\d.\d/].delete('.')
|
523
317
|
local_runit_path = "#{shared_path}/runit_temp"
|
524
318
|
runit = "/etc/sv/#{application}"
|
525
319
|
runit_path = "/etc/service/#{application}"
|
526
320
|
wrapper = "#{join_ruby}_unicorn"
|
527
321
|
logger.important('Creating unicorn wrapper', 'runit')
|
528
|
-
run "rvm wrapper #{
|
322
|
+
run "rvm wrapper #{ruby_version} #{join_ruby} unicorn"
|
529
323
|
|
530
324
|
runit_run = <<EOF
|
531
325
|
#!/bin/sh
|
@@ -580,131 +374,6 @@ run "#{sudo} chown -R root:root #{runit}"
|
|
580
374
|
capture("ps -p $(cat #{pid_file}) ; true").strip.split("\n").size == 2
|
581
375
|
end
|
582
376
|
|
583
|
-
namespace :unicorn do
|
584
|
-
desc "init autostart unicorn"
|
585
|
-
task :autostart do
|
586
|
-
#cd /home/rails/www/three-elements/current && sudo -u rails -H /home/rails/.rvm/bin/193_bundle exec /home/rails/.rvm/bin/193_unicorn -c /home/rails/www/three-elements/current/config/unicorn.rb -E production -D
|
587
|
-
join_ruby = rvm_ruby_string[/\d.\d.\d/].delete('.')
|
588
|
-
ruby_wrapper = "#{join_ruby}_unicorn"
|
589
|
-
ruby_wrapper_path = "/home/#{user}/.rvm/bin/#{ruby_wrapper}"
|
590
|
-
bundle_wrapper = "#{join_ruby}_bundle"
|
591
|
-
bundle_wrapper_path = "/home/#{user}/.rvm/bin/#{bundle_wrapper}"
|
592
|
-
|
593
|
-
run "rvm wrapper #{rvm_ruby_string} #{join_ruby} unicorn"
|
594
|
-
run "rvm wrapper #{rvm_ruby_string} #{join_ruby} bundle"
|
595
|
-
#puts "sudo -u #{user} -H /home/#{user}/.rvm/bin/#{wrapper} -c #{unicorn_conf} -E production -D"
|
596
|
-
command = "cd #{current_path} && sudo -u #{user} -H #{bundle_wrapper_path} exec #{ruby_wrapper_path} -c #{unicorn_conf} -E production -D"
|
597
|
-
puts command
|
598
|
-
|
599
|
-
run "#{sudo} sed -i 's/exit 0//g' /etc/rc.local"
|
600
|
-
run "echo \"#{command}\" | #{sudo} tee -a /etc/rc.local"
|
601
|
-
run "echo \"exit 0\" | #{sudo} tee -a /etc/rc.local"
|
602
|
-
end
|
603
|
-
|
604
|
-
desc "start unicorn"
|
605
|
-
task :start do
|
606
|
-
if remote_file_exists?(unicorn_pid)
|
607
|
-
if remote_process_exists?(unicorn_pid)
|
608
|
-
logger.important("Unicorn is already running!", "Unicorn")
|
609
|
-
next
|
610
|
-
else
|
611
|
-
run "rm #{unicorn_pid}"
|
612
|
-
end
|
613
|
-
end
|
614
|
-
logger.important("Starting...", "Unicorn")
|
615
|
-
run "cd #{current_path} && bundle exec unicorn -c #{unicorn_conf} -E #{rails_env} -D"
|
616
|
-
end
|
617
|
-
desc "stop unicorn"
|
618
|
-
#task :stop, :roles => :app, :except => {:no_release => true} do
|
619
|
-
task :stop do
|
620
|
-
if remote_file_exists?(unicorn_pid)
|
621
|
-
if remote_process_exists?(unicorn_pid)
|
622
|
-
logger.important("Stopping...", "Unicorn")
|
623
|
-
run "if [ -f #{unicorn_pid} ] && [ -e /proc/$(cat #{unicorn_pid}) ]; then kill -QUIT `cat #{unicorn_pid}`; fi"
|
624
|
-
else
|
625
|
-
run "rm #{unicorn_pid}"
|
626
|
-
logger.important("Unicorn is not running.", "Unicorn")
|
627
|
-
end
|
628
|
-
else
|
629
|
-
logger.important("No PIDs found. Check if unicorn is running.", "Unicorn")
|
630
|
-
end
|
631
|
-
end
|
632
|
-
desc "restart unicorn"
|
633
|
-
task :restart do
|
634
|
-
if remote_file_exists?(unicorn_pid)
|
635
|
-
logger.important("Stopping...", "Unicorn")
|
636
|
-
run "kill -s USR2 `cat #{unicorn_pid}`"
|
637
|
-
else
|
638
|
-
logger.important("No PIDs found. Starting Unicorn server...", "Unicorn")
|
639
|
-
run "cd #{current_path} && bundle exec unicorn -c #{unicorn_conf} -E #{rails_env} -D"
|
640
|
-
end
|
641
|
-
end
|
642
|
-
|
643
|
-
task :init do
|
644
|
-
template = <<EOF
|
645
|
-
#! /bin/sh
|
646
|
-
# File: /etc/init.d/<%= unicorn_init %>
|
647
|
-
### BEGIN INIT INFO
|
648
|
-
# Provides: unicorn
|
649
|
-
# Required-Start: $local_fs $remote_fs $network $syslog
|
650
|
-
# Required-Stop: $local_fs $remote_fs $network $syslog
|
651
|
-
# Default-Start: 2 3 4 5
|
652
|
-
# Default-Stop: 0 1 6
|
653
|
-
# Short-Description: starts the unicorn web server
|
654
|
-
# Description: starts unicorn
|
655
|
-
### END INIT INFO
|
656
|
-
|
657
|
-
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
|
658
|
-
DAEMON=/home/nyaa/.rvm/bin/system_unicorn
|
659
|
-
DAEMON_OPTS="<%= unicorn_conf %>"
|
660
|
-
NAME=unicorn_<%= application %>
|
661
|
-
DESC="Unicorn app for <%= application %>"
|
662
|
-
PID=<% unicorn_pid %>
|
663
|
-
|
664
|
-
case "$1" in
|
665
|
-
start)
|
666
|
-
echo -n "Starting $DESC: "
|
667
|
-
$DAEMON $DAEMON_OPTS
|
668
|
-
echo "$NAME."
|
669
|
-
;;
|
670
|
-
stop)
|
671
|
-
echo -n "Stopping $DESC: "
|
672
|
-
kill -QUIT `cat $PID`
|
673
|
-
echo "$NAME."
|
674
|
-
;;
|
675
|
-
restart)
|
676
|
-
echo -n "Restarting $DESC: "
|
677
|
-
kill -QUIT `cat $PID`
|
678
|
-
sleep 1
|
679
|
-
$DAEMON $DAEMON_OPTS
|
680
|
-
echo "$NAME."
|
681
|
-
;;
|
682
|
-
reload)
|
683
|
-
echo -n "Reloading $DESC configuration: "
|
684
|
-
kill -HUP `cat $PID`
|
685
|
-
echo "$NAME."
|
686
|
-
;;
|
687
|
-
*)
|
688
|
-
echo "Usage: $NAME {start|stop|restart|reload}" >&2
|
689
|
-
exit 1
|
690
|
-
;;
|
691
|
-
esac
|
692
|
-
|
693
|
-
exit 0
|
694
|
-
EOF
|
695
|
-
erb = ERB.new(template)
|
696
|
-
init = erb.result(binding)
|
697
|
-
file_path = "/etc/init.d/#{unicorn_init}"
|
698
|
-
put init, "/tmp/#{unicorn_init}"
|
699
|
-
run "#{sudo} mv /tmp/#{unicorn_init} #{file_path} && #{sudo} chmod +x #{file_path}"
|
700
|
-
end
|
701
|
-
task :init_defaults do
|
702
|
-
"#{sudo} /usr/sbin/update-rc.d -f #{unicorn_init} defaults"
|
703
|
-
end
|
704
|
-
task :init_remove do
|
705
|
-
"sudo update-rc.d #{unicorn_init} remove"
|
706
|
-
end
|
707
|
-
end
|
708
377
|
|
709
378
|
namespace :deploy do
|
710
379
|
task :restart do
|
@@ -712,59 +381,5 @@ EOF
|
|
712
381
|
end
|
713
382
|
end
|
714
383
|
|
715
|
-
if gem_use?('whenever') && exists?(:whenever) && fetch(:whenever) == true
|
716
|
-
set :whenever_command, "bundle exec whenever"
|
717
|
-
require "whenever/capistrano/recipes"
|
718
|
-
after "bundle:install", "whenever:update_crontab"
|
719
|
-
after "deploy:rollback", "whenever:update_crontab"
|
720
|
-
end
|
721
|
-
|
722
|
-
#namespace :whenever do
|
723
|
-
# task :update_crontab do
|
724
|
-
# run "cd #{latest_release} && bundle exec rake RAILS_ENV=#{rails_env} whenever:update_crontab"
|
725
|
-
# end
|
726
|
-
#end
|
727
|
-
|
728
|
-
def local_gem_available?(name)
|
729
|
-
Gem::Specification.find_by_name(name)
|
730
|
-
rescue Gem::LoadError
|
731
|
-
false
|
732
|
-
rescue
|
733
|
-
Gem.available?(name)
|
734
|
-
end
|
735
|
-
|
736
|
-
|
737
|
-
def file_size(file_path)
|
738
|
-
size = run("wc -c #{file_path} | cut -d' ' -f1")
|
739
|
-
return size
|
740
|
-
end
|
741
|
-
|
742
|
-
after 'deploy:setup', 'logrotate:init'
|
743
|
-
|
744
|
-
set :logrotate_path, '/etc/logrotate.d'
|
745
|
-
set :logrotate_file_name, "cap_#{application}"
|
746
|
-
set :logrotate_file, "#{logrotate_path}/#{logrotate_file_name}"
|
747
|
-
namespace :logrotate do
|
748
|
-
#http://stackoverflow.com/questions/4883891/ruby-on-rails-production-log-rotation
|
749
|
-
task :init do
|
750
|
-
str = %|
|
751
|
-
#{shared_path}/log/*.log {
|
752
|
-
size=32M
|
753
|
-
rotate 10
|
754
|
-
missingok
|
755
|
-
compress
|
756
|
-
delaycompress
|
757
|
-
notifempty
|
758
|
-
copytruncate
|
759
|
-
}
|
760
|
-
|
|
761
|
-
temp_path = "/tmp/#{logrotate_file_name}"
|
762
|
-
put str, temp_path
|
763
|
-
run "#{sudo} mv -v #{temp_path} #{logrotate_file}"
|
764
|
-
end
|
765
|
-
task :stop do
|
766
|
-
run "#{sudo} rm #{logrotate_file}"
|
767
|
-
end
|
768
|
-
end
|
769
384
|
|
770
385
|
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
Capistrano::Configuration.instance(:must_exist).load do
|
2
|
+
|
3
|
+
if !exists?(:assets) || fetch(:assets) == true
|
4
|
+
after 'bundle:install', 'assets:precompile'
|
5
|
+
before 'deploy:finalize_update', 'assets:symlink'
|
6
|
+
end
|
7
|
+
|
8
|
+
namespace :assets do
|
9
|
+
desc "Local Assets precompile"
|
10
|
+
task :local_precompile do
|
11
|
+
system("bundle exec rake assets:precompile && cd public && tar czf assets.tar.gz assets/")
|
12
|
+
upload("public/assets.tar.gz","#{latest_release}/public/assets.tar.gz")
|
13
|
+
system("rm public/assets.tar.gz && rm -rf tmp/assets && mv public/assets tmp/assets")
|
14
|
+
run("cd #{latest_release}/public && rm -rf assets/ && tar xzf assets.tar.gz && rm assets.tar.gz")
|
15
|
+
end
|
16
|
+
desc "Assets precompile"
|
17
|
+
task :precompile, :roles => :web, :except => { :no_release => true } do
|
18
|
+
run("cd #{latest_release} && bundle exec rake RAILS_ENV=#{rails_env} assets:precompile")
|
19
|
+
end
|
20
|
+
task :symlink, :roles => :web, :except => { :no_release => true } do
|
21
|
+
run <<-CMD
|
22
|
+
rm -rf #{latest_release}/public/assets &&
|
23
|
+
mkdir -p #{latest_release}/public &&
|
24
|
+
mkdir -p #{shared_path}/assets &&
|
25
|
+
ln -s #{shared_path}/assets #{latest_release}/public/assets
|
26
|
+
CMD
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
Capistrano::Configuration.instance(:must_exist).load do
|
2
|
+
namespace :backup do
|
3
|
+
desc "Backup a database"
|
4
|
+
task :db do
|
5
|
+
file_name = fetch(:db_file_name)
|
6
|
+
archive_ext = fetch(:db_archive_ext)
|
7
|
+
dump_file_path = "#{shared_path}/backup/#{file_name}"
|
8
|
+
output_file = "#{file_name}.#{archive_ext}"
|
9
|
+
output_file_path = "#{dump_file_path}.#{archive_ext}"
|
10
|
+
require 'yaml'
|
11
|
+
run "mkdir -p #{shared_path}/backup"
|
12
|
+
if adapter == "postgresql"
|
13
|
+
logger.important("Backup database #{database}", "Backup:db")
|
14
|
+
run "export PGPASSWORD=\"#{db_password}\" && pg_dump -U #{db_username} #{database} > #{dump_file_path}"
|
15
|
+
run "cd #{shared_path}/backup && #{arch_create} #{output_file} #{file_name} && rm #{dump_file_path}"
|
16
|
+
else
|
17
|
+
puts "Cannot backup, adapter #{adapter} is not implemented for backup yet"
|
18
|
+
end
|
19
|
+
system "mkdir -p #{local_folder_path}"
|
20
|
+
download_path = "#{local_folder_path}/#{file_name}.#{archive_ext}"
|
21
|
+
logger.important("Downloading database to #{download_path}", "Backup:db")
|
22
|
+
download(output_file_path, download_path)
|
23
|
+
run "rm -v #{output_file_path}" if fetch(:del_backup)
|
24
|
+
end
|
25
|
+
desc "Backup public/system folder"
|
26
|
+
task :sys do
|
27
|
+
file_path = "#{shared_path}/backup/#{sys_file_name}"
|
28
|
+
logger.important("Backup shared/system folder", "Backup:sys")
|
29
|
+
run "#{arch_create} #{file_path} -C #{shared_path} system"
|
30
|
+
download_path = "#{local_folder_path}/#{sys_file_name}"
|
31
|
+
logger.important("Downloading system to #{download_path}", "Backup:db")
|
32
|
+
download(file_path, download_path)
|
33
|
+
run "rm -v #{file_path}" if fetch(:del_backup)
|
34
|
+
end
|
35
|
+
task :all do
|
36
|
+
backup.db
|
37
|
+
backup.sys
|
38
|
+
end
|
39
|
+
desc "Clean backup folder"
|
40
|
+
task :clean do
|
41
|
+
run "rm -rfv #{shared_path}/backup/*"
|
42
|
+
end
|
43
|
+
end
|
44
|
+
if exists?(:backup_db) && fetch(:backup_db) == true
|
45
|
+
before "deploy:update", "backup:db"
|
46
|
+
end
|
47
|
+
if exists?(:backup_sys) && fetch(:backup_sys) == true
|
48
|
+
before "deploy:update", "backup:sys"
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
Capistrano::Configuration.instance(:must_exist).load do
|
2
|
+
after 'deploy:update_code', 'bundle:install'
|
3
|
+
namespace :bundle do
|
4
|
+
desc "Run bundle install"
|
5
|
+
task :install do
|
6
|
+
deployment = "--deployment --quiet"
|
7
|
+
without = ['development','test','production']-[rails_env]
|
8
|
+
run "cd #{latest_release} && bundle install --without #{without.join(" ")}"
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,73 @@
|
|
1
|
+
Capistrano::Configuration.instance(:must_exist).load do
|
2
|
+
psql = "psql -h localhost"
|
3
|
+
psql_postgres = "#{psql} -U postgres"
|
4
|
+
|
5
|
+
database_yml_path = "config/database.yml"
|
6
|
+
|
7
|
+
serv_path = "#{current_path}/#{database_yml_path}"
|
8
|
+
#if capture("if [ -f #{serv_path} ]; then echo '1'; fi") == '1'
|
9
|
+
# database_yml = capture("cat #{serv_path}")
|
10
|
+
#else
|
11
|
+
database_yml = File.open(database_yml_path) rescue nil
|
12
|
+
#end
|
13
|
+
if database_yml
|
14
|
+
config = YAML::load(database_yml)
|
15
|
+
adapter = config[rails_env]["adapter"]
|
16
|
+
database = config[rails_env]["database"]
|
17
|
+
db_username = config[rails_env]["username"]
|
18
|
+
db_password = config[rails_env]["password"]
|
19
|
+
|
20
|
+
local_rails_env = 'development'
|
21
|
+
local_adapter = config[local_rails_env]["adapter"]
|
22
|
+
local_database = config[local_rails_env]["database"]
|
23
|
+
local_db_username = config[local_rails_env]["username"]||`whoami`.chop
|
24
|
+
local_db_password = config[local_rails_env]["password"]
|
25
|
+
end
|
26
|
+
|
27
|
+
set :local_folder_path, "tmp/backup"
|
28
|
+
set :timestamp, Time.new.to_i.to_s
|
29
|
+
set :db_archive_ext, "tar.bz2"
|
30
|
+
set :arch_extract, "tar -xvjf"
|
31
|
+
set :arch_create, "tar -cvjf"
|
32
|
+
|
33
|
+
set :db_file_name, "#{database}-#{timestamp}.sql"
|
34
|
+
set :sys_file_name, "#{application}-system-#{timestamp}.#{db_archive_ext}"
|
35
|
+
|
36
|
+
namespace :db do
|
37
|
+
task :create do
|
38
|
+
if adapter == "postgresql"
|
39
|
+
run "echo \"create user #{db_username} with password '#{db_password}';\" | #{sudo} -u postgres psql"
|
40
|
+
run "echo \"create database #{database} owner #{db_username};\" | #{sudo} -u postgres psql"
|
41
|
+
run "echo \"CREATE EXTENSION IF NOT EXISTS hstore;\" | #{sudo} -u postgres psql #{database}" if exists?(:hstore) && fetch(:hstore) == true
|
42
|
+
else
|
43
|
+
puts "Cannot create, adapter #{adapter} is not implemented yet"
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
[:seed, :migrate].each do |t|
|
48
|
+
task t do
|
49
|
+
run "cd #{latest_release} && bundle exec rake RAILS_ENV=#{rails_env} db:#{t}"
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
task :reset do
|
54
|
+
run "cd #{latest_release} && bundle exec rake RAILS_ENV=#{rails_env} db:reset"
|
55
|
+
end
|
56
|
+
|
57
|
+
task :import do
|
58
|
+
file_name = "#{db_file_name}.#{db_archive_ext}"
|
59
|
+
file_path = "#{local_folder_path}/#{file_name}"
|
60
|
+
system "cd #{local_folder_path} && #{arch_extract} #{file_name}"
|
61
|
+
system "echo \"drop database IF EXISTS #{local_database}\" | #{psql_postgres}"
|
62
|
+
system "echo \"create database #{local_database} owner #{local_db_username};\" | #{psql_postgres}"
|
63
|
+
# system "#{psql_postgre} #{local_database} < #{local_folder_path}/#{db_file_name}"
|
64
|
+
puts "ENTER your development password: #{local_db_password}"
|
65
|
+
system "#{psql} -U#{local_db_username} #{local_database} < #{local_folder_path}/#{db_file_name}"
|
66
|
+
system "rm #{local_folder_path}/#{db_file_name}"
|
67
|
+
end
|
68
|
+
task :pg_import do
|
69
|
+
backup.db
|
70
|
+
db.import
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
Capistrano::Configuration.instance(:must_exist).load do
|
2
|
+
namespace :delayed_job do
|
3
|
+
desc 'Start the delayed_job process'
|
4
|
+
task :start, :roles => :app do
|
5
|
+
run "cd #{latest_release} && RAILS_ENV=#{rails_env} script/delayed_job start"
|
6
|
+
end
|
7
|
+
desc "Restart the delayed_job process"
|
8
|
+
task :restart, :roles => :app do
|
9
|
+
logger.important 'Restarting delayed_job process'
|
10
|
+
run "cd #{latest_release}; RAILS_ENV=#{rails_env} script/delayed_job restart"
|
11
|
+
end
|
12
|
+
desc 'Stop the delayed_job process'
|
13
|
+
task :stop, :roles => :app do
|
14
|
+
run "cd #{latest_release} && RAILS_ENV=#{rails_env} script/delayed_job stop"
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
Capistrano::Configuration.instance(:must_exist).load do
|
2
|
+
|
3
|
+
namespace :import do
|
4
|
+
task :sys do
|
5
|
+
#system "rm -rfv public/system/"
|
6
|
+
if which('rsync') && local_which('rsync')
|
7
|
+
logger.important('Importing with rsync', 'import:sys')
|
8
|
+
system "rsync -avz --rsh='ssh -p#{ssh_port}' #{user}@#{serv}:#{shared_path}/system public/"
|
9
|
+
else
|
10
|
+
backup.sys
|
11
|
+
system "cd public && #{arch_extract} ../#{local_folder_path}/#{sys_file_name}"
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
Capistrano::Configuration.instance(:must_exist).load do
|
2
|
+
after 'deploy:setup', 'logrotate:init'
|
3
|
+
|
4
|
+
set :logrotate_path, '/etc/logrotate.d'
|
5
|
+
set :logrotate_file_name, "cap_#{application}"
|
6
|
+
set :logrotate_file, "#{logrotate_path}/#{logrotate_file_name}"
|
7
|
+
namespace :logrotate do
|
8
|
+
#http://stackoverflow.com/questions/4883891/ruby-on-rails-production-log-rotation
|
9
|
+
task :init do
|
10
|
+
str = %|
|
11
|
+
#{shared_path}/log/*.log {
|
12
|
+
size=32M
|
13
|
+
rotate 10
|
14
|
+
missingok
|
15
|
+
compress
|
16
|
+
delaycompress
|
17
|
+
notifempty
|
18
|
+
copytruncate
|
19
|
+
}
|
20
|
+
|
|
21
|
+
temp_path = "/tmp/#{logrotate_file_name}"
|
22
|
+
put str, temp_path
|
23
|
+
run "#{sudo} mv -v #{temp_path} #{logrotate_file}"
|
24
|
+
end
|
25
|
+
task :stop do
|
26
|
+
run "#{sudo} rm #{logrotate_file}"
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
Capistrano::Configuration.instance(:must_exist).load do
|
2
|
+
# PRIKHA-TASK
|
3
|
+
desc "Run custom task usage: cap rake TASK=patch:project_category"
|
4
|
+
task :rake do
|
5
|
+
if ENV.has_key?('TASK')
|
6
|
+
logger.important "running rake task: #{ENV['TASK']}"
|
7
|
+
run "cd #{current_path} && bundle exec rake RAILS_ENV=#{rails_env} #{ENV['TASK']}"
|
8
|
+
else
|
9
|
+
puts 'Please specify correct task: cap rake TASK= some_task'
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
Capistrano::Configuration.instance(:must_exist).load do
|
2
|
+
set :unicorn_init, "unicorn_#{fetch(:application)}"
|
3
|
+
set :unicorn_conf, "#{current_path}/config/unicorn.rb"
|
4
|
+
set :unicorn_pid, "#{shared_path}/pids/unicorn.pid"
|
5
|
+
|
6
|
+
namespace :unicorn do
|
7
|
+
desc "init autostart unicorn"
|
8
|
+
task :autostart do
|
9
|
+
#cd /home/rails/www/three-elements/current && sudo -u rails -H /home/rails/.rvm/bin/193_bundle exec /home/rails/.rvm/bin/193_unicorn -c /home/rails/www/three-elements/current/config/unicorn.rb -E production -D
|
10
|
+
join_ruby = ruby_version[/\d.\d.\d/].delete('.')
|
11
|
+
ruby_wrapper = "#{join_ruby}_unicorn"
|
12
|
+
ruby_wrapper_path = "/home/#{user}/.rvm/bin/#{ruby_wrapper}"
|
13
|
+
bundle_wrapper = "#{join_ruby}_bundle"
|
14
|
+
bundle_wrapper_path = "/home/#{user}/.rvm/bin/#{bundle_wrapper}"
|
15
|
+
|
16
|
+
run "rvm wrapper #{ruby_version} #{join_ruby} unicorn"
|
17
|
+
run "rvm wrapper #{ruby_version} #{join_ruby} bundle"
|
18
|
+
#puts "sudo -u #{user} -H /home/#{user}/.rvm/bin/#{wrapper} -c #{unicorn_conf} -E production -D"
|
19
|
+
command = "cd #{current_path} && sudo -u #{user} -H #{bundle_wrapper_path} exec #{ruby_wrapper_path} -c #{unicorn_conf} -E production -D"
|
20
|
+
puts command
|
21
|
+
|
22
|
+
run "#{sudo} sed -i 's/exit 0//g' /etc/rc.local"
|
23
|
+
run "echo \"#{command}\" | #{sudo} tee -a /etc/rc.local"
|
24
|
+
run "echo \"exit 0\" | #{sudo} tee -a /etc/rc.local"
|
25
|
+
end
|
26
|
+
|
27
|
+
desc "start unicorn"
|
28
|
+
task :start do
|
29
|
+
if remote_file_exists?(unicorn_pid)
|
30
|
+
if remote_process_exists?(unicorn_pid)
|
31
|
+
logger.important("Unicorn is already running!", "Unicorn")
|
32
|
+
next
|
33
|
+
else
|
34
|
+
run "rm #{unicorn_pid}"
|
35
|
+
end
|
36
|
+
end
|
37
|
+
logger.important("Starting...", "Unicorn")
|
38
|
+
run "cd #{current_path} && bundle exec unicorn -c #{unicorn_conf} -E #{rails_env} -D"
|
39
|
+
end
|
40
|
+
desc "stop unicorn"
|
41
|
+
#task :stop, :roles => :app, :except => {:no_release => true} do
|
42
|
+
task :stop do
|
43
|
+
if remote_file_exists?(unicorn_pid)
|
44
|
+
if remote_process_exists?(unicorn_pid)
|
45
|
+
logger.important("Stopping...", "Unicorn")
|
46
|
+
run "if [ -f #{unicorn_pid} ] && [ -e /proc/$(cat #{unicorn_pid}) ]; then kill -QUIT `cat #{unicorn_pid}`; fi"
|
47
|
+
else
|
48
|
+
run "rm #{unicorn_pid}"
|
49
|
+
logger.important("Unicorn is not running.", "Unicorn")
|
50
|
+
end
|
51
|
+
else
|
52
|
+
logger.important("No PIDs found. Check if unicorn is running.", "Unicorn")
|
53
|
+
end
|
54
|
+
end
|
55
|
+
desc "restart unicorn"
|
56
|
+
task :restart do
|
57
|
+
if remote_file_exists?(unicorn_pid)
|
58
|
+
logger.important("Stopping...", "Unicorn")
|
59
|
+
run "kill -s USR2 `cat #{unicorn_pid}`"
|
60
|
+
else
|
61
|
+
logger.important("No PIDs found. Starting Unicorn server...", "Unicorn")
|
62
|
+
run "cd #{current_path} && bundle exec unicorn -c #{unicorn_conf} -E #{rails_env} -D"
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
end
|
@@ -0,0 +1,8 @@
|
|
1
|
+
Capistrano::Configuration.instance(:must_exist).load do
|
2
|
+
if exists?(:whenever) && fetch(:whenever) == true
|
3
|
+
set :whenever_command, "bundle exec whenever"
|
4
|
+
require "whenever/capistrano/recipes"
|
5
|
+
after "bundle:install", "whenever:update_crontab"
|
6
|
+
after "deploy:rollback", "whenever:update_crontab"
|
7
|
+
end
|
8
|
+
end
|
data/lib/capobvious/version.rb
CHANGED
metadata
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: capobvious
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
5
|
-
prerelease:
|
4
|
+
version: 0.3.pre
|
5
|
+
prerelease: 4
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Dmitry Gruzd
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-11-
|
12
|
+
date: 2012-11-30 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: capistrano
|
@@ -53,11 +53,22 @@ extra_rdoc_files: []
|
|
53
53
|
files:
|
54
54
|
- .gitignore
|
55
55
|
- Gemfile
|
56
|
-
- README.
|
56
|
+
- README.md
|
57
57
|
- Rakefile
|
58
58
|
- bin/capobvious
|
59
59
|
- capobvious.gemspec
|
60
60
|
- lib/capistrano/ext/capobvious.rb
|
61
|
+
- lib/capobvious/recipes/assets.rb
|
62
|
+
- lib/capobvious/recipes/backup.rb
|
63
|
+
- lib/capobvious/recipes/bundle.rb
|
64
|
+
- lib/capobvious/recipes/db.rb
|
65
|
+
- lib/capobvious/recipes/delayed_job.rb
|
66
|
+
- lib/capobvious/recipes/import.rb
|
67
|
+
- lib/capobvious/recipes/logrotate.rb
|
68
|
+
- lib/capobvious/recipes/rake.rb
|
69
|
+
- lib/capobvious/recipes/sitemap_generator.rb
|
70
|
+
- lib/capobvious/recipes/unicorn.rb
|
71
|
+
- lib/capobvious/recipes/whenever.rb
|
61
72
|
- lib/capobvious/version.rb
|
62
73
|
homepage: ''
|
63
74
|
licenses: []
|
@@ -73,9 +84,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
73
84
|
none: false
|
74
85
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
75
86
|
requirements:
|
76
|
-
- - ! '
|
87
|
+
- - ! '>'
|
77
88
|
- !ruby/object:Gem::Version
|
78
|
-
version:
|
89
|
+
version: 1.3.1
|
79
90
|
none: false
|
80
91
|
requirements: []
|
81
92
|
rubyforge_project: capobvious
|
data/README.markdown
DELETED
@@ -1,63 +0,0 @@
|
|
1
|
-
How to use
|
2
|
-
======
|
3
|
-
|
4
|
-
Add to the end of Capfile
|
5
|
-
**require 'capistrano/ext/capobvious'**
|
6
|
-
|
7
|
-
some task need 7z
|
8
|
-
Ubuntu: sudo apt-get install p7zip-full
|
9
|
-
|
10
|
-
|
11
|
-
Cap recipies
|
12
|
-
======
|
13
|
-
|
14
|
-
**backup:db**
|
15
|
-
if you want to backup your production postgres database
|
16
|
-
it will create 7z archive at your tmp/backup project folder & shared/backup on server (NOTE: it need p7zip installed on server)
|
17
|
-
|
18
|
-
**backup:sys**
|
19
|
-
backup your system folder on server to 7z archive at tmp/backup & shared/backup on server (NOTE: need p7zip)
|
20
|
-
|
21
|
-
**backup:clean**
|
22
|
-
delete all files in server shared/backup folder
|
23
|
-
|
24
|
-
|
25
|
-
**assets:precompile**
|
26
|
-
precompiles assets on developer's machine & sends it to server
|
27
|
-
NOTE:
|
28
|
-
if in config/deploy.rb will be setted :assets to true, task will run automatically by deploy
|
29
|
-
|
30
|
-
|
31
|
-
**db:create**
|
32
|
-
will create a Postgresql database on server and user with password that stored in database.yml
|
33
|
-
|
34
|
-
**db:seed**
|
35
|
-
run rake db:seed with right RAILS_ENV
|
36
|
-
|
37
|
-
**db:pg_import**
|
38
|
-
import remote server postgresql database to your development postgresql database IT WILL DELETE YOUR DEV DATABASE (NOTE: need installed p7zip)
|
39
|
-
|
40
|
-
|
41
|
-
**rake TASK=db:seed**
|
42
|
-
runs custom rake task
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
**nginx:restart**
|
47
|
-
**nginx:reload**
|
48
|
-
**nginx:start**
|
49
|
-
**nginx:stop**
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
**bundle:install**
|
54
|
-
|
55
|
-
|
56
|
-
**log:tail**
|
57
|
-
catch errors with tail -f log
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
**unicorn:start**
|
62
|
-
**unicorn:stop**
|
63
|
-
**unicorn:restart**
|