recipes_matic 1.1.0 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (38) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +25 -12
  3. data/{LICENSE.txt → MIT-LICENSE} +2 -2
  4. data/README.md +23 -16
  5. data/lib/generators/recipes_matic/install_generator.rb +1 -1
  6. data/lib/generators/recipes_matic/templates/config/deploy/recipes/base.rb +65 -64
  7. data/lib/generators/recipes_matic/templates/config/deploy/recipes/templates/backup_model.erb +23 -6
  8. data/lib/generators/recipes_matic/templates/config/deploy/recipes/templates/database.yml.erb +17 -6
  9. data/lib/generators/recipes_matic/templates/config/deploy/recipes/templates/maintenance.html.erb +0 -5
  10. data/lib/generators/recipes_matic/templates/config/deploy/recipes/templates/monit/monitrc.erb +1 -1
  11. data/lib/generators/recipes_matic/templates/config/deploy/recipes/templates/monit/postgresql.erb +1 -1
  12. data/lib/generators/recipes_matic/templates/config/deploy/recipes/templates/monit/unicorn.erb +3 -3
  13. data/lib/generators/recipes_matic/templates/config/deploy/recipes/templates/nginx.production.erb +7 -7
  14. data/lib/generators/recipes_matic/templates/config/deploy/recipes/templates/nginx.staging.erb +7 -7
  15. data/lib/generators/recipes_matic/templates/config/deploy/recipes/templates/unicorn.rb.erb +26 -6
  16. data/lib/generators/recipes_matic/templates/config/deploy/recipes/templates/unicorn_init.erb +8 -6
  17. data/lib/generators/recipes_matic/templates/lib/capistrano/tasks/backup.rake +29 -0
  18. data/lib/generators/recipes_matic/templates/lib/capistrano/tasks/db.rake +19 -0
  19. data/lib/generators/recipes_matic/templates/lib/capistrano/tasks/monit.rake +55 -0
  20. data/lib/generators/recipes_matic/templates/lib/capistrano/tasks/nginx.rake +24 -0
  21. data/lib/generators/recipes_matic/templates/lib/capistrano/tasks/postgresql.rake +66 -0
  22. data/lib/generators/recipes_matic/templates/lib/capistrano/tasks/unicorn.rake +34 -0
  23. data/lib/recipes_matic/version.rb +1 -1
  24. data/recipes_matic.gemspec +6 -1
  25. metadata +27 -18
  26. data/lib/generators/recipes_matic/templates/config/deploy.rb +0 -41
  27. data/lib/generators/recipes_matic/templates/config/deploy/production.rb +0 -5
  28. data/lib/generators/recipes_matic/templates/config/deploy/recipes/assets.rb +0 -10
  29. data/lib/generators/recipes_matic/templates/config/deploy/recipes/backup.rb +0 -40
  30. data/lib/generators/recipes_matic/templates/config/deploy/recipes/check.rb +0 -13
  31. data/lib/generators/recipes_matic/templates/config/deploy/recipes/db.rb +0 -15
  32. data/lib/generators/recipes_matic/templates/config/deploy/recipes/monit.rb +0 -37
  33. data/lib/generators/recipes_matic/templates/config/deploy/recipes/nginx.rb +0 -36
  34. data/lib/generators/recipes_matic/templates/config/deploy/recipes/postgresql.rb +0 -35
  35. data/lib/generators/recipes_matic/templates/config/deploy/recipes/symlinks.rb +0 -8
  36. data/lib/generators/recipes_matic/templates/config/deploy/recipes/unicorn.rb +0 -27
  37. data/lib/generators/recipes_matic/templates/config/deploy/recipes/whenever.rb +0 -16
  38. data/lib/generators/recipes_matic/templates/config/deploy/staging.rb +0 -5
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 41fbc8f83312a4be00153e624a7621fee1f764f2
4
- data.tar.gz: d8f593f85cd8626e928915940bbf6d7ce2b66769
3
+ metadata.gz: 289e82737561ae5004a27198131d941557c6ea72
4
+ data.tar.gz: 4157987cbe982600abb6336cdebd8c3b0c6997a2
5
5
  SHA512:
6
- metadata.gz: ac2b2882a3fe995dc4901bc66468188d5d61a8e58fd09615fb0e5db1cfd1b5e32d8a1ba6b7aecea922e90eb8b67b017c33961cd11f8a12089d8e15e3c5f007e1
7
- data.tar.gz: d2164569efd9c70eb34cc555a0b7069b1408e50ecefe7d9b9f57435b88ee37af1eed7ba5c69d4011e370e3a398a596aa4dfcc9f29ddbaf31f9d7af4bc921f105
6
+ metadata.gz: ec3efbd5a9273efdb8a351e6c828fc99032b3dfd275dbd10c7e236d4d37cf95576f5745f6b5f912b77298edb59906859c4e4a1e9ce50eca59763811aa4ff4259
7
+ data.tar.gz: 080c2712e3adaef567a8ca0a7ab9cb55ec258d5d4499cf79a2ae68e83d01ff97d9be67e799fe6c04a5f80fb952ec3afd6f1ee549be7cd21b1701269ef37888ff
@@ -1,22 +1,35 @@
1
1
 
2
2
  #### [Current]
3
- * [9936cca](../../commit/9936cca) - __(Muhammet DILEK)__ TB-32 postgresql install fixed
3
+ * [ea6110e](../../commit/ea6110e) - __(Tayfun Öziş ERİKAN)__ Improvements were done - LICENSE file was updated - README was updated - Gemspecs were updated
4
+ * [fcec848](../../commit/fcec848) - __(Ismail Akbudak)__ add maintenance mode for zero down time deploy
5
+ * [e6eec71](../../commit/e6eec71) - __(Ismail Akbudak)__ improve
6
+ * [cd7988e](../../commit/cd7988e) - __(Ismail Akbudak)__ add message
7
+ * [46fb404](../../commit/46fb404) - __(Ismail Akbudak)__ add zero down time deployment
8
+ * [93134df](../../commit/93134df) - __(Ismail Akbudak)__ increase time wait for unicorn commands
9
+ * [66ce790](../../commit/66ce790) - __(Ismail Akbudak)__ add first deploy method
10
+ * [aab03c6](../../commit/aab03c6) - __(İsmail)__ Update README.md
11
+ * [2cf520e](../../commit/2cf520e) - __(Ismail Akbudak)__ update readme
12
+ * [d541111](../../commit/d541111) - __(Ismail Akbudak)__ update recipes for capistrano 3
13
+ * [75894d1](../../commit/75894d1) - __(Murat Kemal BAYGÜN)__ #TB-65 Fix project name in credits
14
+ * [4ce239f](../../commit/4ce239f) - __(Murat Kemal BAYGÜN)__ TB-65 Fix contributors link
15
+ * [62a50db](../../commit/62a50db) - __(Muhammet DİLEK)__ bump version 1.1.0
16
+ * [9936cca](../../commit/9936cca) - __(Muhammet DİLEK)__ TB-32 postgresql install fixed
4
17
  * [eec4fe7](../../commit/eec4fe7) - __(Ahmet Sezgin Duran)__ LAB-31 #time 1m Add named logo
5
18
  * [b0a73cb](../../commit/b0a73cb) - __(Ahmet Sezgin Duran)__ LAB-31 #time 1 Fix year information
6
19
  * [ae3efb7](../../commit/ae3efb7) - __(Ahmet Sezgin Duran)__ LAB-31 #time 2m Update README.md
7
20
  * [c28a3ed](../../commit/c28a3ed) - __(Ahmet Sezgin Duran)__ TB-12 #time 15m Set number of unicorn workers in environments
8
- * [27fe3bf](../../commit/27fe3bf) - __(Onur zgr ZKAN)__ Update monitrc.erb
21
+ * [27fe3bf](../../commit/27fe3bf) - __(Onur Özgür ÖZKAN)__ Update monitrc.erb
22
+
23
+ #### 1.0.0
9
24
  * [884ac66](../../commit/884ac66) - __(Onur Ozgur OZKAN)__ bump version 1.0.0
10
25
  * [67e66ff](../../commit/67e66ff) - __(Onur Ozgur OZKAN)__ [#8](../../issues/8) Fixed unicorn restart
11
- * [9be5972](../../commit/9be5972) - __(Onur zgr ZKAN)__ document typo fixed
12
- * [a3cd0e1](../../commit/a3cd0e1) - __(Muhammet DILEK)__ [#5](../../issues/5) postgresql setup fixed
13
- * [8c36737](../../commit/8c36737) - __(Muhammet DILEK)__ [#4](../../issues/4) nginx setup bug fixed
14
-
15
- #### 0.2.0
16
- * [8622f89](../../commit/8622f89) - __(Muhammet DILEK)__ bump version 0.2.0
17
- * [5ca7c90](../../commit/5ca7c90) - __(Muhammet DILEK)__ [#2](../../issues/2) package install fixed
26
+ * [9be5972](../../commit/9be5972) - __(Onur Özgür ÖZKAN)__ document typo fixed
27
+ * [a3cd0e1](../../commit/a3cd0e1) - __(Muhammet DİLEK)__ [#5](../../issues/5) postgresql setup fixed
28
+ * [8c36737](../../commit/8c36737) - __(Muhammet DİLEK)__ [#4](../../issues/4) nginx setup bug fixed
29
+ * [8622f89](../../commit/8622f89) - __(Muhammet DİLEK)__ bump version 0.2.0
30
+ * [5ca7c90](../../commit/5ca7c90) - __(Muhammet DİLEK)__ [#2](../../issues/2) package install fixed
18
31
 
19
32
  #### 0.1.0
20
- * [6ab4bb6](../../commit/6ab4bb6) - __(Muhammet DILEK)__ bump version 0.1.0
21
- * [235d3b6](../../commit/235d3b6) - __(Muhammet DILEK)__ [#1](../../issues/1) gem application created
22
- * [dd38801](../../commit/dd38801) - __(Muhammet DILEK)__ Initial commit
33
+ * [6ab4bb6](../../commit/6ab4bb6) - __(Muhammet DİLEK)__ bump version 0.1.0
34
+ * [235d3b6](../../commit/235d3b6) - __(Muhammet DİLEK)__ [#1](../../issues/1) gem application created
35
+ * [dd38801](../../commit/dd38801) - __(Muhammet DİLEK)__ Initial commit
@@ -1,4 +1,4 @@
1
- Copyright (c) 2014 lab2023 information technologies
1
+ Copyright © 2013-2015 lab2023 - information technologies
2
2
 
3
3
  MIT License
4
4
 
@@ -19,4 +19,4 @@ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
19
  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
20
  LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
21
  OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
- WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md CHANGED
@@ -21,30 +21,37 @@ Or install it yourself as:
21
21
  Add following gem to Gemfile
22
22
 
23
23
  ```ruby
24
- gem 'capistrano', '~> 2.15.5'
25
- gem 'capistrano-ext', '~> 1.2.1'
26
- gem 'unicorn', '~> 4.6.3'
24
+ gem 'capistrano', '~> 3.4.0'
25
+ gem 'unicorn', '~> 4.9.0'
26
+ group :development do
27
+ gem 'capistrano-rails', '~> 1.1', require: false
28
+ gem 'capistrano-bundler', '~> 1.1', require: false
29
+ gem 'sshkit-sudo', require: false
30
+ gem 'capistrano-maintenance', '~> 1.0', require: false
31
+ gem 'recipes_matic'
32
+ end
27
33
  ```
28
34
 
29
35
  And then execute
30
36
 
31
37
  ```ruby
32
38
  bundle install
33
- capify .
39
+ bundle exec capistrano install
34
40
  rails g recipes_matic:install
35
41
  ```
36
42
 
37
- Now edit `config/deploy.rb`, `config/deploy/staging.rb` and `config/deploy/production.rb`
43
+ Now edit `config/deploy.rb`, `config/deploy/recipes/base.rb`
38
44
 
39
- If install server package for ruby and rails run the following command
40
- `cap deploy:install`
41
-
42
- and execute
43
-
44
- `cap staging deploy:setup`
45
- `cap staging deploy:cold`
45
+ Add this line to end of `config/deploy.rb` file
46
+ ```ruby
47
+ load 'config/deploy/recipes/base.rb'
48
+ ```
46
49
 
47
- Finish...
50
+ If you want to prepare your server, run the following command
51
+ For production :
52
+ `bundle exec cap production deploy:prepare`
53
+ For staging :
54
+ `bundle exec cap staging deploy:prepare`
48
55
 
49
56
  ## Contributing
50
57
 
@@ -58,10 +65,10 @@ Finish...
58
65
 
59
66
  ![lab2023](http://lab2023.com/assets/images/named-logo.png)
60
67
 
61
- - Cybele is maintained and funded by [lab2023 - information technologies](http://lab2023.com/)
62
- - Thank you to all the [contributors!](https://github.com/kebab-project/recipes_matic/graphs/contributors)
68
+ - RecipesMatic is maintained and funded by [lab2023 - information technologies](http://lab2023.com/)
69
+ - Thank you to all the [contributors!](../../graphs/contributors)
63
70
  - The names and logos for lab2023 are trademarks of lab2023, inc.
64
71
 
65
72
  ## License
66
73
 
67
- Copyright 2014 lab2023 information technologies
74
+ Copyright © 2013-2015 [lab2023 - information technologies](http://lab2023.com)
@@ -8,7 +8,7 @@ module RecipesMatic
8
8
 
9
9
  def copy_deploy_file
10
10
  directory 'config/deploy', 'config/deploy'
11
- copy_file 'config/deploy.rb', 'config/deploy.rb'
11
+ directory 'lib/capistrano/tasks', 'lib/capistrano/tasks'
12
12
  end
13
13
  end
14
14
  end
@@ -1,71 +1,72 @@
1
- def set_default(name, *args, &block)
2
- set(name, *args, &block) unless exists?(name)
3
- end
4
-
1
+ set :shared_path, "#{fetch(:deploy_to)}/shared"
2
+ set :current_path, "#{fetch(:deploy_to)}/current"
3
+ set :postgresql_pid, "/var/run/postgresql/9.3-main.pid"
4
+ set :unicorn_pid, "#{fetch(:current_path)}/tmp/pids/unicorn.pid"
5
+ set :run_path, '$HOME/.rbenv/shims/'
6
+ set :maintenance_template_path, File.expand_path('../templates/maintenance.html.erb', __FILE__)
7
+ # local user group on server. We use deploy group
8
+ set :local_user_group, fetch(:local_user)
9
+
10
+ # Use template
5
11
  def template(from, to)
6
12
  erb = File.read(File.expand_path("../templates/#{from}", __FILE__))
7
- put ERB.new(erb).result(binding), to
13
+ File.open(File.expand_path("tmp/temprory"), 'w') { |file| file.write(ERB.new(erb).result(binding)) }
14
+ upload! File.expand_path("tmp/temprory"), to
8
15
  end
9
16
 
10
- #set :whenever_command, 'bundle exec whenever'
11
- namespace :deploy do
12
- desc 'Install dependencies library for rails'
13
- task :install do
14
- #run "#{sudo} apt-get -y update && #{sudo} apt-get -y upgrade"
15
-
16
- run "#{sudo} apt-get -y install python-software-properties && #{sudo} apt-get -y install software-properties-common"
17
-
18
- #run "export LANGUAGE=en_US.UTF-8 && export LANG=en_US.UTF-8 && export LC_ALL=en_US.UTF-8 && locale-gen en_US.UTF-8 && #{sudo} dpkg-reconfigure locales"
19
-
20
- #run "bash <(curl -s https://gist.github.com/muhammetdilek/7138112/raw/c9af34bbda8df7ebf7f30d5daab18b8bc80326c6/removepackage.sh)"
21
-
22
- run "#{sudo} apt-get -y install htop"
23
-
24
- #run "#{sudo} apt-get -y install curl git-core"
25
-
26
- #run "ssh-keygen -t rsa -C 'user@example.com' << EOF \n \n \n \n"
27
-
28
- # Ruby dependencies package
29
- run "#{sudo} apt-get -y install zlib1g-dev openssl libopenssl-ruby1.9.1 libssl-dev libruby1.9.1 libreadline-dev git-core make make-doc"
30
-
31
- # Rvm install
32
- run "cd ~ && git clone git://github.com/sstephenson/rbenv.git .rbenv"
33
-
34
- run "echo 'export PATH=\"$HOME/.rbenv/bin:$PATH\"' >> ~/.bashrc"
35
- run "echo 'eval \"$(rbenv init -)\"' >> ~/.bashrc"
36
-
37
- run 'mkdir -p ~/.rbenv/plugins'
38
- run 'cd ~/.rbenv/plugins && git clone https://github.com/sstephenson/ruby-build.git ~/.rbenv/plugins/ruby-build && git clone https://github.com/sstephenson/rbenv-gem-rehash.git ~/.rbenv/plugins/rbenv-gem-rehash'
39
- run 'rbenv install 2.0.0-p247 && rbenv rehash && rbenv global 2.0.0-p247'
40
-
41
- # Update rubygems
42
- run 'gem update --system'
43
-
44
- # No rdoc
45
- run "echo 'gem: --no-rdoc --no-ri' >> ~/.gemrc"
46
-
47
- # Install bundler
48
- run 'gem install bundler --no-ri --no-rdoc && rbenv rehash'
49
-
50
- #Update rake
51
- #run 'gem update rake'
52
-
53
- # Node js
54
- run "#{sudo} add-apt-repository -y ppa:chris-lea/node.js && #{sudo} apt-get -y update && #{sudo} apt-get -y install nodejs"
55
-
56
- # For nokogiri gem
57
- run "#{sudo} apt-get -y install libxslt-dev libxml2-dev"
58
- end
59
-
17
+ # Gem execute path
18
+ def gem_execute(command)
19
+ execute "#{fetch(:run_path)}#{command}"
20
+ end
60
21
 
61
- desc 'Install bundler'
62
- task :install_bundler, :roles => :app do
63
- run 'type -P bundle &>/dev/null || { gem install bundler --no-rdoc --no-ri; }'
22
+ namespace :deploy do
23
+ ## If you want to use maintenance mode during deploy, use Scenario 1
24
+ ## Scenario 1 with maintenance mode
25
+ # before 'deploy', 'backup:perform'
26
+ # before 'deploy', 'maintenance:enable'
27
+ # after 'deploy', 'deploy:cleanup'
28
+ # after 'deploy', 'deploy:cleanup_assets'
29
+ # after 'deploy', 'unicorn:stop'
30
+ # after 'unicorn:stop', 'unicorn:start'
31
+ # after 'unicorn:start', 'maintenance:disable'
32
+
33
+ ## We use default zero down time
34
+ ## If you want to use zero down time deployment use this Scenario
35
+ ## Scenario 2 without maintenance mode
36
+ before 'deploy', 'backup:perform'
37
+ after 'deploy', 'deploy:cleanup'
38
+ after 'deploy', 'deploy:cleanup_assets'
39
+ before 'unicorn:upgrade', 'maintenance:enable'
40
+ after 'deploy', 'unicorn:upgrade'
41
+ after 'unicorn:upgrade', 'maintenance:disable'
42
+
43
+ desc <<-DESC
44
+ Prepare environment for first deploy. You can use this command for first deploy
45
+ This command invokes
46
+ - postgresql:create_database_file
47
+ - deploy(starting updating publishing finishing)
48
+ - postgresql:setup
49
+ - nginx:setup
50
+ - unicorn:setup
51
+ - bundler:install
52
+ - nginx:restart
53
+ - deploy
54
+ DESC
55
+ task :prepare do
56
+ puts 'prepare'
57
+ invoke 'postgresql:create_database_file'
58
+ %w{starting updating publishing finishing}.each do |task|
59
+ invoke "deploy:#{task}"
60
+ end
61
+ invoke 'postgresql:setup'
62
+ invoke 'nginx:setup'
63
+ invoke 'unicorn:setup'
64
+ invoke 'bundler:install'
65
+ invoke 'nginx:restart'
66
+ invoke 'deploy'
67
+ ## Remove comments if you are using monit
68
+ # invoke 'monit:install'
69
+ # invoke 'monit:setup'
64
70
  end
65
- end
66
71
 
67
- before 'deploy:setup', 'deploy:install'
68
- after 'deploy', 'deploy:cleanup'
69
- before 'deploy:cold', 'deploy:install_bundler'
70
- before 'deploy', 'deploy:web:disable'
71
- after 'deploy', 'deploy:web:enable'
72
+ end
@@ -1,4 +1,4 @@
1
- Backup::Model.new(:<%= application %>, '<%= application %> backup') do
1
+ Backup::Model.new(:<%= fetch(:application) %>, '<%= fetch(:application) %> backup') do
2
2
  ##
3
3
  # Split [Splitter]
4
4
  #
@@ -12,11 +12,11 @@ Backup::Model.new(:<%= application %>, '<%= application %> backup') do
12
12
  #
13
13
  database PostgreSQL do |db|
14
14
  # To dump all databases, set `db.name = :all` (or leave blank)
15
- db.name = "<%= postgresql_database %>"
16
- db.username = "<%= postgresql_user %>"
17
- db.password = "<%= postgresql_password %>"
18
- db.host = "<%= postgresql_host %>"
19
- db.port = "<%= postgresql_port %>"
15
+ db.name = "<%= "#{fetch(:postgresql_database)}_#{fetch(:rails_env)}" %>"
16
+ db.username = "<%= fetch(:postgresql_user) %>"
17
+ db.password = "<%= fetch(:postgresql_password) %>"
18
+ db.host = "<%= fetch(:postgresql_host) %>"
19
+ db.port = "<%= fetch(:postgresql_port) %>"
20
20
  end
21
21
 
22
22
  ##
@@ -32,4 +32,21 @@ Backup::Model.new(:<%= application %>, '<%= application %> backup') do
32
32
  #
33
33
  compress_with Gzip
34
34
 
35
+ ##
36
+ # Hipchat [Notifier]
37
+ #
38
+ =begin
39
+ notify_by Hipchat do |hipchat|
40
+ hipchat.on_success = true
41
+ hipchat.on_warning = true
42
+ hipchat.on_failure = true
43
+ hipchat.token = "change_token"
44
+ hipchat.from = "<%= fetch(:application) %> Backup"
45
+ hipchat.rooms_notified = ["backup"]
46
+ hipchat.success_color = "green"
47
+ hipchat.warning_color = "yellow"
48
+ hipchat.failure_color = "red"
49
+ end
50
+ =end
51
+
35
52
  end
@@ -1,11 +1,22 @@
1
- <%= rails_env %>:
1
+ development: &default
2
2
  adapter: postgresql
3
- username: <%= postgresql_user %>
4
- password: <%= postgresql_password %>
5
- database: <%= postgresql_database %>
3
+ username: <%= fetch(:postgresql_user) %>
4
+ password: <%= fetch(:postgresql_password) %>
6
5
  encoding: utf8
7
6
  min_messages: warning
8
7
  pool: 5
9
8
  timeout: 5000
10
- host: <%= postgresql_host %>
11
- port: <%= postgresql_port %>
9
+ host: <%= fetch(:postgresql_host) %>
10
+ port: <%= fetch(:postgresql_port) %>
11
+
12
+ test:
13
+ <<: *default
14
+ database: <%= fetch(:postgresql_database) %>_test
15
+
16
+ production:
17
+ <<: *default
18
+ database: <%= fetch(:postgresql_database) %>_production
19
+
20
+ staging:
21
+ <<: *default
22
+ database: <%= fetch(:postgresql_database) %>_staging
@@ -9,11 +9,6 @@
9
9
  font-size: 14px;
10
10
  }
11
11
 
12
- a {
13
- color: #0000FF;
14
- img { border: none; }
15
- }
16
-
17
12
  #container {
18
13
  width: 80%;
19
14
  margin: 0 auto;
@@ -13,7 +13,7 @@ set eventqueue
13
13
  # using tlsv1
14
14
  # with timeout 30 seconds
15
15
 
16
- set alert foo@example.com
16
+ set alert ismail.akbudak@lab2023.com
17
17
 
18
18
  set httpd port 2812
19
19
  allow admin:"secret"
@@ -1,4 +1,4 @@
1
- check process postgresql with pidfile <%= postgresql_pid %>
1
+ check process postgresql with pidfile <%= fetch(:postgresql_pid) %>
2
2
  start program = "/etc/init.d/postgresql start"
3
3
  stop program = "/etc/init.d/postgresql stop"
4
4
  if failed host localhost port 5432 protocol pgsql then restart
@@ -1,3 +1,3 @@
1
- check process <%= application %>_unicorn with pidfile <%= unicorn_pid %>
2
- start program = "/etc/init.d/unicorn_<%= application %> start"
3
- stop program = "/etc/init.d/unicorn_<%= application %> stop"
1
+ check process <%= fetch(:application) %>_unicorn with pidfile <%= fetch(:unicorn_pid) %>
2
+ start program = "/etc/init.d/unicorn_<%= fetch(:application) %> start"
3
+ stop program = "/etc/init.d/unicorn_<%= fetch(:application) %> stop"
@@ -1,11 +1,11 @@
1
- upstream <%= application %> {
2
- server unix:/tmp/unicorn.<%= application %>.sock fail_timeout=0;
1
+ upstream <%= fetch(:application) %> {
2
+ server unix:/tmp/unicorn.<%= fetch(:application) %>.sock fail_timeout=0;
3
3
  }
4
4
 
5
5
  server {
6
6
  listen 80;
7
- server_name *.<%= project_domain %> <%= project_domain %>;
8
- root <%= current_path %>/public;
7
+ server_name *.<%= fetch(:project_domain) %> <%= fetch(:project_domain) %>;
8
+ root <%= fetch(:current_path) %>/public;
9
9
 
10
10
  location ^~ /assets/ {
11
11
  gzip_static on;
@@ -13,12 +13,12 @@ upstream <%= application %> {
13
13
  add_header Cache-Control public;
14
14
  }
15
15
 
16
- try_files $uri/index.html $uri @<%= application %>;
17
- location @<%= application %> {
16
+ try_files $uri/index.html $uri @<%= fetch(:application) %>;
17
+ location @<%= fetch(:application) %> {
18
18
  proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
19
19
  proxy_set_header Host $http_host;
20
20
  proxy_redirect off;
21
- proxy_pass http://<%= application %>;
21
+ proxy_pass http://<%= fetch(:application) %>;
22
22
  }
23
23
 
24
24
  error_page 500 502 504 /500.html;
@@ -1,11 +1,11 @@
1
- upstream <%= application %> {
2
- server unix:/tmp/unicorn.<%= application %>.sock fail_timeout=0;
1
+ upstream <%= fetch(:application) %> {
2
+ server unix:/tmp/unicorn.<%= fetch(:application) %>.sock fail_timeout=0;
3
3
  }
4
4
 
5
5
  server {
6
6
  listen 80;
7
- server_name stage.<%= project_domain %>;
8
- root <%= current_path %>/public;
7
+ server_name stage.<%= fetch(:project_domain) %>;
8
+ root <%= fetch(:current_path) %>/public;
9
9
 
10
10
  location ^~ /assets/ {
11
11
  gzip_static on;
@@ -13,12 +13,12 @@ upstream <%= application %> {
13
13
  add_header Cache-Control public;
14
14
  }
15
15
 
16
- try_files $uri/index.html $uri @<%= application %>;
17
- location @<%= application %> {
16
+ try_files $uri/index.html $uri @<%= fetch(:application) %>;
17
+ location @<%= fetch(:application) %> {
18
18
  proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
19
19
  proxy_set_header Host $http_host;
20
20
  proxy_redirect off;
21
- proxy_pass http://<%= application %>;
21
+ proxy_pass http://<%= fetch(:application) %>;
22
22
  }
23
23
 
24
24
  error_page 500 502 504 /500.html;
@@ -1,10 +1,10 @@
1
- working_directory "<%= current_path %>"
2
- pid "<%= unicorn_pid %>"
3
- stderr_path "<%= unicorn_log %>"
4
- stdout_path "<%= unicorn_log %>"
1
+ working_directory "<%= fetch(:current_path) %>"
2
+ pid "<%= fetch(:unicorn_pid) %>"
3
+ stderr_path "<%= fetch(:unicorn_log) %>"
4
+ stdout_path "<%= fetch(:unicorn_log) %>"
5
5
 
6
- listen "/tmp/unicorn.<%= application %>.sock"
7
- worker_processes <%= unicorn_workers %>
6
+ listen "/tmp/unicorn.<%= fetch(:application) %>.sock"
7
+ worker_processes <%= fetch(:unicorn_workers) %>
8
8
  timeout 30
9
9
 
10
10
  preload_app true
@@ -33,4 +33,24 @@ after_fork do |server, worker|
33
33
  end
34
34
  child_pid = server.config[:pid].sub(".pid", ".#{worker.nr}.pid")
35
35
  system("echo #{Process.pid} > #{child_pid}")
36
+
37
+ begin
38
+ uid, gid = Process.euid, Process.egid
39
+ user, group = '<%= fetch(:unicorn_user) %>', '<%= fetch(:unicorn_user_group) %>'
40
+ target_uid = Etc.getpwnam(user).uid
41
+ target_gid = Etc.getgrnam(group).gid
42
+ worker.tmp.chown(target_uid, target_gid)
43
+ if uid != target_uid || gid != target_gid
44
+ Process.initgroups(user, target_gid)
45
+ Process::GID.change_privilege(target_gid)
46
+ Process::UID.change_privilege(target_uid)
47
+ end
48
+ rescue => e
49
+ if RAILS_ENV == 'development'
50
+ STDERR.puts "couldn't change user, oh well"
51
+ system("echo 'couldn't change user, oh well'")
52
+ else
53
+ raise e
54
+ end
55
+ end
36
56
  end
@@ -3,10 +3,10 @@ set -e
3
3
 
4
4
  # Feel free to change any of the following variables for your app:
5
5
  TIMEOUT=${TIMEOUT-60}
6
- APP_ROOT=<%= current_path %>
7
- PID=<%= unicorn_pid %>
8
- CMD="cd $APP_ROOT; bundle exec unicorn -D -c <%= unicorn_config %> -E <%= rails_env %>"
9
- AS_USER=<%= unicorn_user %>
6
+ APP_ROOT=<%= fetch(:current_path) %>
7
+ PID=<%= fetch(:unicorn_pid) %>
8
+ CMD="cd $APP_ROOT; <%= fetch(:run_path) %>bundle exec unicorn -D -c <%= fetch(:unicorn_config) %> -E <%= fetch(:rails_env) %>"
9
+ AS_USER=<%= fetch(:unicorn_user) %>
10
10
  set -u
11
11
 
12
12
  OLD_PIN="$PID.oldbin"
@@ -41,12 +41,14 @@ force-stop)
41
41
  echo >&2 "Not running"
42
42
  ;;
43
43
  restart|reload)
44
- sig USR2 && echo reloaded OK && exit 0
44
+ sig HUP && echo reloaded OK && exit 0
45
45
  echo >&2 "Couldn't reload, starting '$CMD' instead"
46
46
  run "$CMD"
47
47
  ;;
48
48
  upgrade)
49
- if sig USR2 && sleep 2 && sig 0 && oldsig QUIT
49
+ # we changed it for zero down time deploy
50
+ # if sig USR2 && sleep 2 && sig 0 && oldsig QUIT
51
+ if sig USR2 && sleep 3
50
52
  then
51
53
  n=$TIMEOUT
52
54
  while test -s $OLD_PIN && test $n -ge 0
@@ -0,0 +1,29 @@
1
+ namespace :backup do
2
+ desc 'Setup backup.'
3
+ task :setup do
4
+ on roles(:app) do
5
+ puts 'Creating backup model.'
6
+
7
+ # Check model is exist
8
+ full_path = "/home/#{fetch(:local_user)}/Backup/models/#{fetch(:application)}.rb"
9
+ if 'true' == capture("if [ -e #{full_path} ]; then echo 'true'; fi").strip
10
+ execute "mv #{full_path} #{full_path}.#{Time.now.to_i}"
11
+ end
12
+
13
+ # Generate new model
14
+ gem_execute "backup generate:model -t #{fetch(:application)} --storages=local --compressor=gzip --databases=postgresql"
15
+ execute "rm #{full_path}"
16
+ template 'backup_model.erb', full_path
17
+ puts "Now edit #{full_path}"
18
+ end
19
+ end
20
+
21
+ desc 'Get backup.'
22
+ task :perform do
23
+ on roles(:app) do
24
+ puts 'Performing backup.'
25
+ gem_execute "backup perform --trigger #{fetch(:application)}"
26
+ end
27
+ end
28
+
29
+ end
@@ -0,0 +1,19 @@
1
+ namespace :db do
2
+ desc 'Setup db configuration.'
3
+ task :setup do
4
+ on roles(:app) do
5
+ execute "mkdir -p #{fetch(:shared_path)}/config"
6
+ template 'database.yml.erb', "#{shared_path}/config/database.yml"
7
+ end
8
+ end
9
+ desc 'Run rake db:seed.'
10
+ task :seed do
11
+ on roles(:app) do
12
+ within release_path do
13
+ with rails_env: fetch(:rails_env) do
14
+ execute :rake, 'db:seed'
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,55 @@
1
+ namespace :monit do
2
+
3
+ desc 'Install Monit'
4
+ task :install do
5
+ on roles(:app) do
6
+ sudo "apt-get -y install monit"
7
+ end
8
+ end
9
+
10
+ desc 'Setup all Monit configuration'
11
+ task :setup do
12
+ on roles(:app) do
13
+ monit_config 'monitrc', '/etc/monit/monitrc'
14
+ invoke 'monit:nginx'
15
+ invoke 'monit:postgresql'
16
+ invoke 'monit:unicorn'
17
+ invoke 'monit:syntax'
18
+ invoke 'monit:reload'
19
+ end
20
+ end
21
+
22
+ task :nginx do
23
+ on roles(:app) do
24
+ monit_config "nginx"
25
+ end
26
+ end
27
+ task :postgresql do
28
+ on roles(:app) do
29
+ monit_config "postgresql"
30
+ end
31
+ end
32
+ task :unicorn do
33
+ on roles(:app) do
34
+ monit_config "unicorn"
35
+ end
36
+ end
37
+
38
+ %w[start stop restart syntax reload].each do |command|
39
+ desc "Run Monit #{command} script"
40
+ task command do
41
+ on roles(:app) do
42
+ sudo "service monit #{command}"
43
+ end
44
+ end
45
+ end
46
+
47
+ end
48
+
49
+ def monit_config(name, destination = nil)
50
+ destination ||= "/etc/monit/conf.d/#{name}.conf"
51
+ template "monit/#{name}.erb", "/tmp/monit_#{name}"
52
+ sudo "mv /tmp/monit_#{name} #{destination}"
53
+ sudo "chown root #{destination}"
54
+ sudo "chmod 600 #{destination}"
55
+ end
@@ -0,0 +1,24 @@
1
+ namespace :nginx do
2
+
3
+ desc 'Nginx setup.'
4
+ task :setup do
5
+ on roles(:app) do
6
+ puts "Creating #{fetch(:shared_path)}/config/nginx.#{fetch(:rails_env)}.conf"
7
+ template "nginx.#{fetch(:rails_env)}.erb", "#{fetch(:shared_path)}/config/nginx.#{fetch(:rails_env)}.conf"
8
+
9
+ puts "Symlinks #{fetch(:shared_path)}/config/nginx.#{fetch(:rails_env)}.conf to /etc/nginx/sites-enabled/#{fetch(:application)}"
10
+ sudo "ln -nfs #{fetch(:shared_path)}/config/nginx.#{fetch(:rails_env)}.conf /etc/nginx/sites-enabled/#{fetch(:application)}"
11
+
12
+ end
13
+ end
14
+
15
+ %w[start stop restart reload].each do |command|
16
+ desc "Nginx #{command}"
17
+ task command do
18
+ on roles(:app), in: :groups, limit: 2, wait: 2 do
19
+ sudo "service nginx #{command}"
20
+ end
21
+ end
22
+ end
23
+
24
+ end
@@ -0,0 +1,66 @@
1
+ namespace :postgresql do
2
+
3
+ desc 'Setup postgresql for application'
4
+ task :setup do
5
+ # Ask information
6
+ ask :user, "Postgresql username"
7
+ ask :password, "Postgresql password for #{fetch(:user)}"
8
+ ask :database, "Postgresql database"
9
+
10
+ # Set variables
11
+ set :postgresql_host, 'localhost'
12
+ set :postgresql_port, '5432'
13
+ set :postgresql_user, fetch(:user)
14
+ set :postgresql_database, fetch(:database)
15
+ set :postgresql_password, fetch(:password)
16
+
17
+ # Run queries
18
+ on roles(:app) do
19
+ puts 'Creating user with password'
20
+ # Create database user
21
+ sudo %Q{sudo -u postgres psql -c "create user #{fetch(:postgresql_user)} with password '#{fetch(:postgresql_password)}';"}
22
+ puts 'Creating database with owner'
23
+ sudo %Q{sudo -u postgres psql -c "create database "#{fetch(:postgresql_database)}_#{fetch(:rails_env)}" owner #{fetch(:postgresql_user)} encoding 'UTF8' LC_COLLATE = 'en_US.UTF-8' LC_CTYPE = 'en_US.UTF-8' TEMPLATE template0;"}
24
+
25
+ puts 'Creating database.yml.'
26
+ # Configure database settings
27
+ execute "mkdir -p #{fetch(:shared_path)}/config"
28
+ template 'database.yml.erb', "#{shared_path}/config/database.yml"
29
+
30
+ puts 'Creating backup model.'
31
+ # Check model is exist
32
+ full_path = "/home/#{fetch(:local_user)}/Backup/models/#{fetch(:application)}.rb"
33
+ if 'true' == capture("if [ -e #{full_path} ]; then echo 'true'; fi").strip
34
+ execute "mv #{full_path} #{full_path}.#{Time.now.to_i}"
35
+ end
36
+ # Generate new model
37
+ gem_execute "backup generate:model -t #{fetch(:application)} --storages=local --compressor=gzip --databases=postgresql"
38
+ execute "rm #{full_path}"
39
+ template 'backup_model.erb', full_path
40
+ puts "Now edit #{full_path}"
41
+
42
+ end
43
+ end
44
+
45
+ desc 'Restart postgresql'
46
+ task :restart do
47
+ on roles(:app) do
48
+ puts 'Postgresql restarting'
49
+ sudo 'service postgresql restart'
50
+ end
51
+ end
52
+
53
+ # Create database file on start
54
+ task :create_database_file do
55
+ on roles(:app) do
56
+ execute :mkdir, '-p', "#{fetch(:shared_path)}/config"
57
+ if test("[ -f #{fetch(:shared_path)}/config/database.yml ]")
58
+ debug "#{fetch(:shared_path)}/config/database.yml file is exist"
59
+ else
60
+ info "#{fetch(:shared_path)}/config/database.yml file does not exist, and it has been created"
61
+ template 'database.yml.erb', "#{shared_path}/config/database.yml"
62
+ end
63
+ end
64
+ end
65
+
66
+ end
@@ -0,0 +1,34 @@
1
+ namespace :unicorn do
2
+ desc 'Unicorn setup'
3
+ task :setup do
4
+ set :unicorn_user, fetch(:local_user)
5
+ set :unicorn_user_group, fetch(:local_user_group)
6
+ set :unicorn_config, "#{fetch(:shared_path)}/config/unicorn.rb"
7
+ set :unicorn_log, "#{fetch(:shared_path)}/log/unicorn.log"
8
+ set :unicorn_workers, 2
9
+
10
+ on roles(:app) do
11
+ execute "mkdir -p #{fetch(:shared_path)}/config"
12
+ template 'unicorn.rb.erb', fetch(:unicorn_config)
13
+ template 'unicorn_init.erb', "#{fetch(:shared_path)}/config/unicorn_init.sh"
14
+ execute "chmod +x #{fetch(:shared_path)}/config/unicorn_init.sh"
15
+ sudo "ln -nfs #{fetch(:shared_path)}/config/unicorn_init.sh /etc/init.d/unicorn_#{fetch(:application)}"
16
+ end
17
+ end
18
+
19
+ %w[start stop restart].each do |command|
20
+ desc "Unicorn server #{command}."
21
+ task command do
22
+ on roles(:app), in: :groups, limit: 3, wait: 4 do
23
+ execute "/etc/init.d/unicorn_#{fetch(:application)} #{command}"
24
+ end
25
+ end
26
+ end
27
+
28
+ desc "Unicorn server upgrade."
29
+ task :upgrade do
30
+ on roles(:app), in: :groups, limit: 3, wait: 1 do
31
+ execute "/etc/init.d/unicorn_#{fetch(:application)} upgrade"
32
+ end
33
+ end
34
+ end
@@ -1,3 +1,3 @@
1
1
  module RecipesMatic
2
- VERSION = '1.1.0'.freeze
2
+ VERSION = '1.2.0'
3
3
  end
@@ -2,6 +2,7 @@
2
2
  lib = File.expand_path('../lib', __FILE__)
3
3
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
  require 'recipes_matic/version'
5
+ require 'date'
5
6
 
6
7
  Gem::Specification.new do |spec|
7
8
  spec.name = 'recipes_matic'
@@ -12,6 +13,7 @@ Gem::Specification.new do |spec|
12
13
  spec.summary = %q{Copy beautiful recipes into project}
13
14
  spec.homepage = 'http://github.com/kebab-project/recipes_matic'
14
15
  spec.license = 'MIT'
16
+ spec.date = Date.today.strftime('%Y-%m-%d')
15
17
 
16
18
  spec.files = `git ls-files`.split($/)
17
19
  spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
@@ -20,4 +22,7 @@ Gem::Specification.new do |spec|
20
22
 
21
23
  spec.add_development_dependency 'bundler', '~> 1.3'
22
24
  spec.add_development_dependency 'rake'
23
- end
25
+ spec.add_development_dependency 'capistrano', '~> 3.4'
26
+
27
+ spec.extra_rdoc_files = %w[README.md MIT-LICENSE]
28
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: recipes_matic
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - lab2023
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-05-30 00:00:00.000000000 Z
11
+ date: 2015-08-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -38,31 +38,37 @@ dependencies:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: capistrano
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.4'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.4'
41
55
  description: Copy beautiful recipes into project
42
56
  email:
43
57
  - info@lab2023.com
44
58
  executables: []
45
59
  extensions: []
46
- extra_rdoc_files: []
60
+ extra_rdoc_files:
61
+ - README.md
62
+ - MIT-LICENSE
47
63
  files:
48
64
  - ".gitignore"
49
65
  - CHANGELOG.md
50
66
  - Gemfile
51
- - LICENSE.txt
67
+ - MIT-LICENSE
52
68
  - README.md
53
69
  - Rakefile
54
70
  - lib/generators/recipes_matic/install_generator.rb
55
- - lib/generators/recipes_matic/templates/config/deploy.rb
56
- - lib/generators/recipes_matic/templates/config/deploy/production.rb
57
- - lib/generators/recipes_matic/templates/config/deploy/recipes/assets.rb
58
- - lib/generators/recipes_matic/templates/config/deploy/recipes/backup.rb
59
71
  - lib/generators/recipes_matic/templates/config/deploy/recipes/base.rb
60
- - lib/generators/recipes_matic/templates/config/deploy/recipes/check.rb
61
- - lib/generators/recipes_matic/templates/config/deploy/recipes/db.rb
62
- - lib/generators/recipes_matic/templates/config/deploy/recipes/monit.rb
63
- - lib/generators/recipes_matic/templates/config/deploy/recipes/nginx.rb
64
- - lib/generators/recipes_matic/templates/config/deploy/recipes/postgresql.rb
65
- - lib/generators/recipes_matic/templates/config/deploy/recipes/symlinks.rb
66
72
  - lib/generators/recipes_matic/templates/config/deploy/recipes/templates/backup_model.erb
67
73
  - lib/generators/recipes_matic/templates/config/deploy/recipes/templates/database.yml.erb
68
74
  - lib/generators/recipes_matic/templates/config/deploy/recipes/templates/maintenance.html.erb
@@ -74,9 +80,12 @@ files:
74
80
  - lib/generators/recipes_matic/templates/config/deploy/recipes/templates/nginx.staging.erb
75
81
  - lib/generators/recipes_matic/templates/config/deploy/recipes/templates/unicorn.rb.erb
76
82
  - lib/generators/recipes_matic/templates/config/deploy/recipes/templates/unicorn_init.erb
77
- - lib/generators/recipes_matic/templates/config/deploy/recipes/unicorn.rb
78
- - lib/generators/recipes_matic/templates/config/deploy/recipes/whenever.rb
79
- - lib/generators/recipes_matic/templates/config/deploy/staging.rb
83
+ - lib/generators/recipes_matic/templates/lib/capistrano/tasks/backup.rake
84
+ - lib/generators/recipes_matic/templates/lib/capistrano/tasks/db.rake
85
+ - lib/generators/recipes_matic/templates/lib/capistrano/tasks/monit.rake
86
+ - lib/generators/recipes_matic/templates/lib/capistrano/tasks/nginx.rake
87
+ - lib/generators/recipes_matic/templates/lib/capistrano/tasks/postgresql.rake
88
+ - lib/generators/recipes_matic/templates/lib/capistrano/tasks/unicorn.rake
80
89
  - lib/recipes_matic.rb
81
90
  - lib/recipes_matic/version.rb
82
91
  - recipes_matic.gemspec
@@ -100,7 +109,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
100
109
  version: '0'
101
110
  requirements: []
102
111
  rubyforge_project:
103
- rubygems_version: 2.2.2
112
+ rubygems_version: 2.4.5.1
104
113
  signing_key:
105
114
  specification_version: 4
106
115
  summary: Copy beautiful recipes into project
@@ -1,41 +0,0 @@
1
- require 'bundler/capistrano'
2
- require 'capistrano/ext/multistage'
3
- #require 'whenever/capistrano'
4
-
5
- load 'config/deploy/recipes/base'
6
- load 'config/deploy/recipes/backup'
7
- load 'config/deploy/recipes/check'
8
- load 'config/deploy/recipes/db'
9
- load 'config/deploy/recipes/nginx'
10
- load 'config/deploy/recipes/symlinks'
11
- load 'config/deploy/recipes/unicorn'
12
- load 'config/deploy/recipes/assets'
13
- load 'config/deploy/recipes/postgresql'
14
- #load 'config/deploy/recipes/whenever'
15
- load 'config/deploy/recipes/monit'
16
-
17
- set :stages, %w(staging production)
18
-
19
- set :default_stage, 'production'
20
-
21
- default_run_options[:pty] = true
22
-
23
- set :application, 'application_name'
24
- set :user, 'deployer' # We use deployer
25
- set :deploy_to, "/home/#{user}/apps/#{application}"
26
-
27
- set :deploy_via, :remote_cache
28
- set :use_sudo, false
29
-
30
- set :scm, "git"
31
- set :repository, "git@github.com:username/#{application}.git"
32
-
33
- default_run_options[:pty] = true
34
- ssh_options[:forward_agent] = true
35
-
36
- set :maintenance_template_path, File.expand_path('../deploy/recipes/templates/maintenance.html.erb', __FILE__)
37
-
38
- # Production
39
- set :default_environment, {
40
- 'PATH' => '$HOME/.rbenv/shims:$HOME/.rbenv/bin:$PATH'
41
- }
@@ -1,5 +0,0 @@
1
- server '159.253.46.124', :web, :app, :db, primary: true
2
- #set :port, 2222
3
- set :rails_env, 'production'
4
- set :branch, 'master'
5
- set :unicorn_workers, 2
@@ -1,10 +0,0 @@
1
- namespace :assets do
2
- desc 'Run precompile.'
3
- task :precompile do
4
- puts 'Running assets:precompile'
5
- run "cd #{current_path}/ && rake assets:precompile RAILS_ENV=#{rails_env}"
6
- end
7
-
8
- after 'deploy', 'assets:precompile'
9
- after 'deploy:cold', 'assets:precompile'
10
- end
@@ -1,40 +0,0 @@
1
- namespace :backup do
2
- desc 'Setup backup.'
3
- task :setup do
4
- transaction do
5
- on_rollback do
6
- puts 'I can not setup backup.'
7
- end
8
-
9
- puts 'Installing backup gem.'
10
- run 'gem install backup --no-ri --no-rdoc'
11
-
12
- puts 'Creating backup model.'
13
- full_path = "/home/deployer/Backup/models/#{application}.rb"
14
- if 'true' == capture("if [ -e #{full_path} ]; then echo 'true'; fi").strip
15
- run "mv #{full_path} #{full_path}.#{Time.now.to_i}"
16
- end
17
-
18
- run "backup generate:model -t #{application} --storages='local' --compressors='gzip' --databases='postgresql'"
19
- run "rm #{full_path}"
20
- template 'backup_model.erb', full_path
21
- puts "Now edit #{full_path}"
22
- end
23
- end
24
-
25
- after 'deploy:setup', 'backup:setup'
26
-
27
- desc 'Get backup.'
28
- task :perform do
29
- transaction do
30
- on_rollback do
31
- puts 'I can not backup.'
32
- end
33
-
34
- puts 'Performing backup.'
35
- run "backup perform --trigger #{application}"
36
- end
37
- end
38
-
39
- before 'deploy', 'backup:perform'
40
- end
@@ -1,13 +0,0 @@
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
@@ -1,15 +0,0 @@
1
- namespace :db do
2
- desc 'Setup db configuration.'
3
- task :setup do
4
- run "mkdir -p #{shared_path}/config"
5
- template 'database.yml.erb', "#{shared_path}/config/database.yml"
6
- end
7
-
8
- desc 'rake db:migrate.'
9
- task :migrate do
10
- run "cd #{current_path} && rake db:migrate RAILS_ENV=#{rails_env}"
11
- end
12
-
13
- after 'deploy', 'db:migrate'
14
- after 'deploy:setup', 'db:setup'
15
- end
@@ -1,37 +0,0 @@
1
- namespace :monit do
2
- desc 'Install Monit'
3
- task :install do
4
- run "#{sudo} apt-get -y install monit"
5
- end
6
- after 'deploy:install', 'monit:install'
7
-
8
- desc 'Setup all Monit configuration'
9
- task :setup do
10
- monit_config 'monitrc', '/etc/monit/monitrc'
11
- nginx
12
- postgresql
13
- unicorn
14
- syntax
15
- reload
16
- end
17
- after 'deploy:setup', 'monit:setup'
18
-
19
- task(:nginx, roles: :web) { monit_config "nginx" }
20
- #task(:postgresql, roles: :db) { monit_config "postgresql" }
21
- task(:unicorn, roles: :app) { monit_config "unicorn" }
22
-
23
- %w[start stop restart syntax reload].each do |command|
24
- desc "Run Monit #{command} script"
25
- task command do
26
- run "#{sudo} service monit #{command}"
27
- end
28
- end
29
- end
30
-
31
- def monit_config(name, destination = nil)
32
- destination ||= "/etc/monit/conf.d/#{name}.conf"
33
- template "monit/#{name}.erb", "/tmp/monit_#{name}"
34
- run "#{sudo} mv /tmp/monit_#{name} #{destination}"
35
- run "#{sudo} chown root #{destination}"
36
- run "#{sudo} chmod 600 #{destination}"
37
- end
@@ -1,36 +0,0 @@
1
- set_default(:project_domain) { Capistrano::CLI.ui.ask 'Project Domain=> ' }
2
-
3
- namespace :nginx do
4
- desc 'Install nginx'
5
- task :install do
6
- run "#{sudo} add-apt-repository -y ppa:nginx/stable"
7
- run "#{sudo} apt-get -y update"
8
- run "#{sudo} apt-get -y install nginx"
9
- run "#{sudo} service nginx start"
10
- end
11
-
12
- after 'deploy:install', 'nginx:install'
13
-
14
- desc 'Nginx setup.'
15
- task :setup do
16
- puts "Creating #{shared_path}/config/nginx.#{rails_env}.conf"
17
- template "nginx.#{rails_env}.erb", "#{shared_path}/config/nginx.#{rails_env}.conf"
18
-
19
- puts "Symlinks #{shared_path}/config/nginx.#{rails_env}.conf to /etc/nginx/sites-enabled/#{application}"
20
- sudo "ln -nfs #{shared_path}/config/nginx.#{rails_env}.conf /etc/nginx/sites-enabled/#{application}"
21
-
22
- puts 'Removing /etc/nginx/sites-enabled/default'
23
- sudo 'rm -f /etc/nginx/sites-enabled/default'
24
- end
25
-
26
- %w[start stop restart reload].each do |command|
27
- desc "Nginx #{command}"
28
-
29
- task command, role: :web do
30
- sudo "service nginx #{command}"
31
- end
32
- end
33
-
34
- after 'deploy:setup', 'nginx:setup'
35
- after 'deploy:setup', 'nginx:reload'
36
- end
@@ -1,35 +0,0 @@
1
- set_default(:postgresql_host) { Capistrano::CLI.ui.ask 'Postgresql Host=> ' }
2
- set_default(:postgresql_port, '5432') #{ Capistrano::CLI.ui.ask 'Postgresql Port=> ' }
3
- set_default(:postgresql_user) { Capistrano::CLI.ui.ask 'Postgresql User=> ' }
4
- set_default(:postgresql_password) { Capistrano::CLI.password_prompt "Password for #{postgresql_user}:" }
5
- set_default(:postgresql_database) { Capistrano::CLI.ui.ask 'Postgresql Database=> ' }
6
- set_default(:postgresql_pid) { "/var/run/postgresql/9.1-main.pid" }
7
-
8
- namespace :postgresql do
9
- desc 'Install the latest stable release of PostgreSQL.'
10
- task :install, roles: :db, only: {primary: true} do
11
- run "#{sudo} sh -c 'echo \"deb http://apt.postgresql.org/pub/repos/apt/ precise-pgdg main\" >> /etc/apt/sources.list.d/pgdg.list'"
12
- run "wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -"
13
- run "#{sudo} apt-get -y update"
14
- run "#{sudo} apt-get -y install postgresql-9.3"
15
- end
16
-
17
- after "deploy:install", "postgresql:install"
18
-
19
- desc 'Create a database for this application.'
20
- task :create_database, roles: :db, only: {primary: true} do
21
- puts 'Creating user with password'
22
- run %Q{#{sudo} -u postgres psql -c "create user #{postgresql_user} with password '#{postgresql_password}';"}
23
-
24
- puts 'Creating database with owner'
25
- run %Q{#{sudo} -u postgres psql -c "create database #{postgresql_database} owner #{postgresql_user} encoding 'UTF8' LC_COLLATE = 'en_US.UTF-8' LC_CTYPE = 'en_US.UTF-8' TEMPLATE template0;"}
26
- end
27
-
28
- desc 'Restart postgresql'
29
- task :restart do
30
-
31
- puts 'Postgresql restarting'
32
- sudo 'service postgresql restart'
33
- end
34
- after 'deploy:setup', 'postgresql:create_database'
35
- end
@@ -1,8 +0,0 @@
1
- namespace :symlinks do
2
- desc 'database.yml symlink'
3
- task :database do
4
- run "ln -nfs #{shared_path}/config/database.yml #{release_path}/config/database.yml"
5
- end
6
-
7
- after 'deploy:finalize_update', 'symlinks:database'
8
- end
@@ -1,27 +0,0 @@
1
- set_default(:unicorn_user) { user }
2
- set_default(:unicorn_pid) { "#{current_path}/tmp/pids/unicorn.pid" }
3
- set_default(:unicorn_config) { "#{shared_path}/config/unicorn.rb" }
4
- set_default(:unicorn_log) { "#{shared_path}/log/unicorn.log" }
5
-
6
- namespace :unicorn do
7
- desc 'Unicorn setup'
8
- task :setup do
9
- run "mkdir -p #{shared_path}/config"
10
- template 'unicorn.rb.erb', unicorn_config
11
-
12
- template 'unicorn_init.erb', "#{shared_path}/config/unicorn_init.sh"
13
- run "chmod +x #{shared_path}/config/unicorn_init.sh"
14
- sudo "ln -nfs #{shared_path}/config/unicorn_init.sh /etc/init.d/unicorn_#{application}"
15
- end
16
-
17
- %w[start stop restart].each do |command|
18
- desc "Unicorn server #{command}."
19
- task command, except: {no_release: true} do
20
- run "/etc/init.d/unicorn_#{application} #{command}"
21
- end
22
- end
23
-
24
- after 'deploy:setup', 'unicorn:setup'
25
- after 'deploy:cold', 'unicorn:restart'
26
- after 'assets:precompile', 'unicorn:restart'
27
- end
@@ -1,16 +0,0 @@
1
- namespace :whenever do
2
- desc 'Whenever gem installing.'
3
- task :setup do
4
- run 'gem install whenever --no-ri --no-rdoc'
5
- end
6
-
7
- desc 'Update the crontab file'
8
- task :update_crontab, :roles => :db do
9
- run "cd #{current_path} && whenever --update-crontab #{application}"
10
- end
11
-
12
- after 'deploy:setup', 'whenever:setup'
13
-
14
- after 'deploy', 'whenever:update_crontab'
15
- after 'deploy:cold', 'whenever:update_crontab'
16
- end
@@ -1,5 +0,0 @@
1
- server "1.1.1.1", :web, :app, :db, primary: true
2
- set :port, 1111
3
- set :rails_env, 'staging'
4
- set :branch, 'develop'
5
- set :unicorn_workers, 2