georgia_recipes 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (49) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +17 -0
  3. data/Gemfile +4 -0
  4. data/LICENSE.txt +22 -0
  5. data/README.md +48 -0
  6. data/Rakefile +1 -0
  7. data/georgia_recipes.gemspec +24 -0
  8. data/lib/georgia_recipes/all.rb +24 -0
  9. data/lib/georgia_recipes/apache.rb +10 -0
  10. data/lib/georgia_recipes/assets.rb +36 -0
  11. data/lib/georgia_recipes/base.rb +54 -0
  12. data/lib/georgia_recipes/carrierwave.rb +39 -0
  13. data/lib/georgia_recipes/chef.rb +10 -0
  14. data/lib/georgia_recipes/elasticsearch.rb +21 -0
  15. data/lib/georgia_recipes/errbit.rb +25 -0
  16. data/lib/georgia_recipes/georgia.rb +53 -0
  17. data/lib/georgia_recipes/helper_methods.rb +90 -0
  18. data/lib/georgia_recipes/imagemagick.rb +10 -0
  19. data/lib/georgia_recipes/memcached.rb +27 -0
  20. data/lib/georgia_recipes/mongodb.rb +15 -0
  21. data/lib/georgia_recipes/monit.rb +56 -0
  22. data/lib/georgia_recipes/mysql.rb +62 -0
  23. data/lib/georgia_recipes/newrelic.rb +39 -0
  24. data/lib/georgia_recipes/nginx.rb +28 -0
  25. data/lib/georgia_recipes/nodejs.rb +12 -0
  26. data/lib/georgia_recipes/postgresql.rb +92 -0
  27. data/lib/georgia_recipes/rbenv.rb +40 -0
  28. data/lib/georgia_recipes/redis.rb +18 -0
  29. data/lib/georgia_recipes/sidekiq.rb +22 -0
  30. data/lib/georgia_recipes/solr.rb +77 -0
  31. data/lib/georgia_recipes/templates/chef-solo.rb.erb +4 -0
  32. data/lib/georgia_recipes/templates/memcached.erb +16 -0
  33. data/lib/georgia_recipes/templates/monit/mysql.erb +6 -0
  34. data/lib/georgia_recipes/templates/monit/nginx.erb +5 -0
  35. data/lib/georgia_recipes/templates/monit/postgresql.erb +5 -0
  36. data/lib/georgia_recipes/templates/monit/sidekiq.erb +4 -0
  37. data/lib/georgia_recipes/templates/monit/solr.erb +4 -0
  38. data/lib/georgia_recipes/templates/monit/unicorn.erb +15 -0
  39. data/lib/georgia_recipes/templates/monit.node.json.erb +14 -0
  40. data/lib/georgia_recipes/templates/nginx.erb +40 -0
  41. data/lib/georgia_recipes/templates/postgresql.yml.erb +8 -0
  42. data/lib/georgia_recipes/templates/sidekiq.yml.erb +7 -0
  43. data/lib/georgia_recipes/templates/solr.chef.node.json.erb +11 -0
  44. data/lib/georgia_recipes/templates/unicorn.rb.erb +36 -0
  45. data/lib/georgia_recipes/templates/unicorn_init.erb +84 -0
  46. data/lib/georgia_recipes/unicorn.rb +156 -0
  47. data/lib/georgia_recipes/version.rb +3 -0
  48. data/lib/georgia_recipes.rb +5 -0
  49. metadata +134 -0
@@ -0,0 +1,84 @@
1
+ #!/bin/sh
2
+ ### BEGIN INIT INFO
3
+ # Provides: unicorn
4
+ # Required-Start: $remote_fs $syslog
5
+ # Required-Stop: $remote_fs $syslog
6
+ # Default-Start: 2 3 4 5
7
+ # Default-Stop: 0 1 6
8
+ # Short-Description: Manage unicorn server
9
+ # Description: Start, stop, restart unicorn server for a specific application.
10
+ ### END INIT INFO
11
+ set -e
12
+
13
+ # Feel free to change any of the following variables for your app:
14
+ TIMEOUT=${TIMEOUT-60}
15
+ APP_ROOT=<%= current_path %>
16
+ PID=<%= unicorn_pid %>
17
+ CMD="cd <%= current_path %>; bundle exec unicorn -D -c <%= unicorn_config %> -E production"
18
+ AS_USER=<%= unicorn_user %>
19
+ set -u
20
+
21
+ OLD_PIN="$PID.oldbin"
22
+
23
+ sig () {
24
+ test -s "$PID" && kill -$1 `cat $PID`
25
+ }
26
+
27
+ oldsig () {
28
+ test -s $OLD_PIN && kill -$1 `cat $OLD_PIN`
29
+ }
30
+
31
+ run () {
32
+ if [ "$(id -un)" = "$AS_USER" ]; then
33
+ eval $1
34
+ else
35
+ su -c "$1" - $AS_USER
36
+ fi
37
+ }
38
+
39
+ case "$1" in
40
+ start)
41
+ sig 0 && echo >&2 "Already running" && exit 0
42
+ run "$CMD"
43
+ ;;
44
+ stop)
45
+ sig QUIT && exit 0
46
+ echo >&2 "Not running"
47
+ ;;
48
+ force-stop)
49
+ sig TERM && exit 0
50
+ echo >&2 "Not running"
51
+ ;;
52
+ restart|reload)
53
+ sig USR2 && echo reloaded OK && exit 0
54
+ echo >&2 "Couldn't reload, starting '$CMD' instead"
55
+ run "$CMD"
56
+ ;;
57
+ upgrade)
58
+ if sig USR2 && sleep 2 && sig 0 && oldsig QUIT
59
+ then
60
+ n=$TIMEOUT
61
+ while test -s $OLD_PIN && test $n -ge 0
62
+ do
63
+ printf '.' && sleep 1 && n=$(( $n - 1 ))
64
+ done
65
+ echo
66
+
67
+ if test $n -lt 0 && test -s $OLD_PIN
68
+ then
69
+ echo >&2 "$OLD_PIN still exists after $TIMEOUT seconds"
70
+ exit 1
71
+ fi
72
+ exit 0
73
+ fi
74
+ echo >&2 "Couldn't upgrade, starting '$CMD' instead"
75
+ run "$CMD"
76
+ ;;
77
+ reopen-logs)
78
+ sig USR1
79
+ ;;
80
+ *)
81
+ echo >&2 "Usage: $0 <start|stop|restart|upgrade|force-stop|reopen-logs>"
82
+ exit 1
83
+ ;;
84
+ esac
@@ -0,0 +1,156 @@
1
+ Capistrano::Configuration.instance.load do
2
+
3
+ set_default(:unicorn_user) { user }
4
+ set_default(:unicorn_pid) { "#{current_path}/tmp/pids/unicorn.pid" }
5
+ set_default(:unicorn_config) { "#{shared_path}/config/unicorn.rb" }
6
+ set_default(:unicorn_log) { "#{shared_path}/log/unicorn.log" }
7
+
8
+ def remote_file_exists?(full_path)
9
+ 'true' == capture("if [ -e #{full_path} ]; then echo 'true'; fi").strip
10
+ end
11
+
12
+ def remote_process_exists?(pid_file)
13
+ capture("ps -p $(cat #{pid_file}) ; true").strip.split("\n").size == 2
14
+ end
15
+
16
+ def unicorn_get_pid(pid_file=unicorn_pid)
17
+ if remote_file_exists?(pid_file) && remote_process_exists?(pid_file)
18
+ capture("cat #{pid_file}")
19
+ end
20
+ end
21
+
22
+ def unicorn_get_oldbin_pid
23
+ oldbin_pid_file = "#{unicorn_pid}.oldbin"
24
+ unicorn_get_pid(oldbin_pid_file)
25
+ end
26
+
27
+ def unicorn_send_signal(pid, signal)
28
+ run "#{try_sudo} kill -s #{signal} #{pid}"
29
+ end
30
+
31
+ def unicorn_workers
32
+ @unicorn_workers ||= Capistrano::CLI.ui.ask("How many unicorn workers?")
33
+ end
34
+
35
+ before [ 'unicorn:start', 'unicorn:stop', 'unicorn:shutdown', 'unicorn:restart', 'unicorn:reload', 'unicorn:add_worker', 'unicorn:remove_worker' ] do
36
+ _cset(:unicorn_pid) { "#{fetch(:current_path)}/tmp/pids/unicorn.pid" }
37
+ _cset(:app_env) { (fetch(:rails_env) rescue 'production') }
38
+ _cset(:unicorn_env) { fetch(:app_env) }
39
+ _cset(:unicorn_bin, "unicorn")
40
+ end
41
+
42
+ namespace :unicorn do
43
+
44
+ desc "Setup Unicorn initializer and app configuration"
45
+ task :setup, roles: :app do
46
+ run "mkdir -p #{shared_path}/config"
47
+ template "unicorn.rb.erb", unicorn_config
48
+ template "unicorn_init.erb", "/tmp/unicorn_init"
49
+ run "chmod +x /tmp/unicorn_init"
50
+ run "#{sudo} mv /tmp/unicorn_init /etc/init.d/unicorn_#{application}"
51
+ run "#{sudo} update-rc.d -f unicorn_#{application} defaults"
52
+ end
53
+
54
+ desc 'Start Unicorn master process'
55
+ task :start, :roles => :app, :except => {:no_release => true} do
56
+ if remote_file_exists?(unicorn_pid)
57
+ if remote_process_exists?(unicorn_pid)
58
+ logger.important("Unicorn is already running!", "Unicorn")
59
+ next
60
+ else
61
+ run "rm #{unicorn_pid}"
62
+ end
63
+ end
64
+
65
+ primary_config_path = "#{shared_path}/config/unicorn.rb"
66
+ if remote_file_exists?(primary_config_path)
67
+ config_path = primary_config_path
68
+ else
69
+ config_path = "#{current_path}/config/unicorn/#{unicorn_env}.rb"
70
+ end
71
+
72
+ if remote_file_exists?(config_path)
73
+ logger.important("Starting...", "Unicorn")
74
+ run "cd #{current_path} && BUNDLE_GEMFILE=#{current_path}/Gemfile bundle exec #{unicorn_bin} -c #{config_path} -E #{app_env} -D"
75
+ else
76
+ logger.important("Config file for \"#{unicorn_env}\" environment was not found at \"#{config_path}\"", "Unicorn")
77
+ end
78
+ end
79
+
80
+ desc 'Stop Unicorn'
81
+ task :stop, :roles => :app, :except => {:no_release => true} do
82
+ pid = unicorn_get_pid
83
+ unless pid.nil?
84
+ logger.important("Stopping...", "Unicorn")
85
+ unicorn_send_signal(pid, "QUIT")
86
+ else
87
+ logger.important("Unicorn is not running.", "Unicorn")
88
+ end
89
+ end
90
+
91
+ desc 'Immediately shutdown Unicorn'
92
+ task :shutdown, :roles => :app, :except => {:no_release => true} do
93
+ pid = unicorn_get_pid
94
+ unless pid.nil?
95
+ logger.important("Stopping...", "Unicorn")
96
+ unicorn_send_signal(pid, "TERM")
97
+ else
98
+ logger.important("Unicorn is not running.", "Unicorn")
99
+ end
100
+ end
101
+
102
+ desc 'Restart Unicorn'
103
+ task :restart, :roles => :app, :except => {:no_release => true} do
104
+ pid = unicorn_get_pid
105
+ unless pid.nil?
106
+ logger.important("Restarting...", "Unicorn")
107
+ unicorn_send_signal(pid, 'USR2')
108
+ newpid = unicorn_get_pid
109
+ oldpid = unicorn_get_oldbin_pid
110
+ unless oldpid.nil?
111
+ logger.important("Quiting old master...", "Unicorn")
112
+ unicorn_send_signal(oldpid, 'QUIT')
113
+ end
114
+ else
115
+ unicorn.start
116
+ end
117
+ end
118
+
119
+ desc 'Reload Unicorn'
120
+ task :reload, :roles => :app, :except => {:no_release => true} do
121
+ pid = unicorn_get_pid
122
+ unless pid.nil?
123
+ logger.important("Reloading...", "Unicorn")
124
+ unicorn_send_signal(pid, 'HUP')
125
+ else
126
+ unicorn.start
127
+ end
128
+ end
129
+
130
+ desc 'Add a new worker'
131
+ task :add_worker, :roles => :app, :except => {:no_release => true} do
132
+ pid = unicorn_get_pid
133
+ unless pid.nil?
134
+ logger.important("Adding a new worker...", "Unicorn")
135
+ unicorn_send_signal(pid, "TTIN")
136
+ else
137
+ logger.important("Server is not running.", "Unicorn")
138
+ end
139
+ end
140
+
141
+ desc 'Remove amount of workers'
142
+ task :remove_worker, :roles => :app, :except => {:no_release => true} do
143
+ pid = unicorn_get_pid
144
+ unless pid.nil?
145
+ logger.important("Removing worker...", "Unicorn")
146
+ unicorn_send_signal(pid, "TTOU")
147
+ else
148
+ logger.important("Server is not running.", "Unicorn")
149
+ end
150
+ end
151
+ end
152
+ after "deploy:restart", "unicorn:restart"
153
+ after "deploy:start", "unicorn:start"
154
+ after "deploy:stop", "unicorn:stop"
155
+
156
+ end
@@ -0,0 +1,3 @@
1
+ module GeorgiaRecipes
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,5 @@
1
+ require "georgia_recipes/version"
2
+ require "georgia_recipes/helper_methods"
3
+
4
+ module GeorgiaRecipes
5
+ end
metadata ADDED
@@ -0,0 +1,134 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: georgia_recipes
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Mathieu Gagne
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-03-19 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: capistrano
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2'
27
+ - !ruby/object:Gem::Dependency
28
+ name: capistrano-ext
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: capistrano-maintenance
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description: Capistrano recipes for Georgia CMS.
56
+ email:
57
+ - gagne.mathieu@hotmail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - Gemfile
64
+ - LICENSE.txt
65
+ - README.md
66
+ - Rakefile
67
+ - georgia_recipes.gemspec
68
+ - lib/georgia_recipes.rb
69
+ - lib/georgia_recipes/all.rb
70
+ - lib/georgia_recipes/apache.rb
71
+ - lib/georgia_recipes/assets.rb
72
+ - lib/georgia_recipes/base.rb
73
+ - lib/georgia_recipes/carrierwave.rb
74
+ - lib/georgia_recipes/chef.rb
75
+ - lib/georgia_recipes/elasticsearch.rb
76
+ - lib/georgia_recipes/errbit.rb
77
+ - lib/georgia_recipes/georgia.rb
78
+ - lib/georgia_recipes/helper_methods.rb
79
+ - lib/georgia_recipes/imagemagick.rb
80
+ - lib/georgia_recipes/memcached.rb
81
+ - lib/georgia_recipes/mongodb.rb
82
+ - lib/georgia_recipes/monit.rb
83
+ - lib/georgia_recipes/mysql.rb
84
+ - lib/georgia_recipes/newrelic.rb
85
+ - lib/georgia_recipes/nginx.rb
86
+ - lib/georgia_recipes/nodejs.rb
87
+ - lib/georgia_recipes/postgresql.rb
88
+ - lib/georgia_recipes/rbenv.rb
89
+ - lib/georgia_recipes/redis.rb
90
+ - lib/georgia_recipes/sidekiq.rb
91
+ - lib/georgia_recipes/solr.rb
92
+ - lib/georgia_recipes/templates/chef-solo.rb.erb
93
+ - lib/georgia_recipes/templates/memcached.erb
94
+ - lib/georgia_recipes/templates/monit.node.json.erb
95
+ - lib/georgia_recipes/templates/monit/mysql.erb
96
+ - lib/georgia_recipes/templates/monit/nginx.erb
97
+ - lib/georgia_recipes/templates/monit/postgresql.erb
98
+ - lib/georgia_recipes/templates/monit/sidekiq.erb
99
+ - lib/georgia_recipes/templates/monit/solr.erb
100
+ - lib/georgia_recipes/templates/monit/unicorn.erb
101
+ - lib/georgia_recipes/templates/nginx.erb
102
+ - lib/georgia_recipes/templates/postgresql.yml.erb
103
+ - lib/georgia_recipes/templates/sidekiq.yml.erb
104
+ - lib/georgia_recipes/templates/solr.chef.node.json.erb
105
+ - lib/georgia_recipes/templates/unicorn.rb.erb
106
+ - lib/georgia_recipes/templates/unicorn_init.erb
107
+ - lib/georgia_recipes/unicorn.rb
108
+ - lib/georgia_recipes/version.rb
109
+ homepage: ''
110
+ licenses:
111
+ - MIT
112
+ metadata: {}
113
+ post_install_message:
114
+ rdoc_options: []
115
+ require_paths:
116
+ - lib
117
+ required_ruby_version: !ruby/object:Gem::Requirement
118
+ requirements:
119
+ - - ">="
120
+ - !ruby/object:Gem::Version
121
+ version: '0'
122
+ required_rubygems_version: !ruby/object:Gem::Requirement
123
+ requirements:
124
+ - - ">="
125
+ - !ruby/object:Gem::Version
126
+ version: '0'
127
+ requirements: []
128
+ rubyforge_project:
129
+ rubygems_version: 2.2.1
130
+ signing_key:
131
+ specification_version: 4
132
+ summary: Capistrano recipes for Georgia CMS. Helps you setup a VM with the necessary
133
+ dependencies to run a full Rails stack with Georgia CMS
134
+ test_files: []