weapon 0.0.6 → 0.0.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7fa2603ba8765aa269d7ef5451f12c2b2e09f54e
4
- data.tar.gz: 0c7bbc5e2084ecd4599c4a82a3e8516bc4128d1b
3
+ metadata.gz: 3ae11859314f4c7c80d289abe0bc3e7fea5b6588
4
+ data.tar.gz: cb977737f96c51e8a27b997b2df534346dc15b9f
5
5
  SHA512:
6
- metadata.gz: d56ae2d0435f9baa83fce56fbcbd96d7c2a1873265f492520424da0ba1d39a16f6734a87e9c3563452d9ff9fab5911444489a17e6d640e1a8fbaaa04a6661e94
7
- data.tar.gz: 4d2d110aa1a8c976d9616dd34ab004e99ac0826b56ed78b809d87f961ae0a558db5f00984584f6244b9b1eba97f3ea1ef981a4f9ee306efabbc6bdd533508e1a
6
+ metadata.gz: e250fb0c9fbedb9c4939de65fdc347406c6a454a991f7c5c960866acebb7556210c706c8209043ffc7caaf4f51569bbd10b8ebe7f107c2d9bd34a109b5d561d9
7
+ data.tar.gz: 40aa45a8e52a00ba1a74fa8053d82a57db40c20291f26feffdd77ea783719d47191017a7796200a59a82f31bf8ea48329309a3d05eaf46d8800c70134df60967
@@ -0,0 +1,120 @@
1
+ require 'mina/bundler'
2
+ require 'mina/rails'
3
+ require 'mina/git'
4
+ # require 'mina/rbenv' # for rbenv support. (http://rbenv.org)
5
+ require 'mina/rvm' # for rvm support. (http://rvm.io)
6
+ require 'mina/unicorn'
7
+
8
+ # Basic settings:
9
+ # domain - The hostname to SSH to.
10
+ # deploy_to - Path to deploy into.
11
+ # repository - Git repo to clone from. (needed by mina/git)
12
+ # branch - Branch name to deploy. (needed by mina/git)
13
+
14
+ set :user, 'user_name_fore_replace'
15
+ set :domain, 'domain_name_for_replace'
16
+ set :deploy_to, 'deploy_path_for_replace'
17
+ set :repository, 'repo_path_for_replace'
18
+ set :branch, 'master'
19
+
20
+ # For system-wide RVM install.
21
+ # set :rvm_path, '/usr/local/rvm/bin/rvm'
22
+
23
+ # Manually create these paths in shared/ (eg: shared/config/database.yml) in your server.
24
+ # They will be linked in the 'deploy:link_shared_paths' step.
25
+ set :shared_paths, ['config/database.yml', 'config/secrets.yml', 'log']
26
+
27
+ # Optional settings:
28
+ # set :user, 'foobar' # Username in the server to SSH to.
29
+ # set :port, '30000' # SSH port number.
30
+ # set :forward_agent, true # SSH forward_agent.
31
+
32
+ # This task is the environment that is loaded for most commands, such as
33
+ # `mina deploy` or `mina rake`.
34
+ task :environment do
35
+ # If you're using rbenv, use this to load the rbenv environment.
36
+ # Be sure to commit your .ruby-version or .rbenv-version to your repository.
37
+ # invoke :'rbenv:load'
38
+
39
+ # For those using RVM, use this to load an RVM version@gemset.
40
+ invoke :'rvm:use[ruby-2.0.0-p643@default]'
41
+ end
42
+
43
+ # Put any custom mkdir's in here for when `mina setup` is ran.
44
+ # For Rails apps, we'll make some of the shared paths that are shared between
45
+ # all releases.
46
+ task :setup => :environment do
47
+ queue! %[mkdir -p "#{deploy_to}/#{shared_path}/log"]
48
+ queue! %[chmod g+rx,u+rwx "#{deploy_to}/#{shared_path}/log"]
49
+
50
+ queue! %[mkdir -p "#{deploy_to}/#{shared_path}/config"]
51
+ queue! %[chmod g+rx,u+rwx "#{deploy_to}/#{shared_path}/config"]
52
+
53
+ queue! %[mkdir -p "#{deploy_to}/#{shared_path}/tmp/sockets"]
54
+ queue! %[chmod g+rx,u+rwx "#{deploy_to}/#{shared_path}/tmp/sockets"]
55
+
56
+ queue! %[mkdir -p "#{deploy_to}/#{shared_path}/tmp/pids"]
57
+ queue! %[chmod g+rx,u+rwx "#{deploy_to}/#{shared_path}/tmp/pids"]
58
+
59
+ queue! %[touch "#{deploy_to}/#{shared_path}/config/database.yml"]
60
+ queue! %[touch "#{deploy_to}/#{shared_path}/config/secrets.yml"]
61
+ queue %[echo "-----> Be sure to edit '#{deploy_to}/#{shared_path}/config/database.yml' and 'secrets.yml'."]
62
+
63
+ queue %[
64
+ repo_host=`echo $repo | sed -e 's/.*@//g' -e 's/:.*//g'` &&
65
+ repo_port=`echo $repo | grep -o ':[0-9]*' | sed -e 's/://g'` &&
66
+ if [ -z "${repo_port}" ]; then repo_port=22; fi &&
67
+ ssh-keyscan -p $repo_port -H $repo_host >> ~/.ssh/known_hosts
68
+ ]
69
+ end
70
+
71
+ desc "Deploys the current version to the server."
72
+ task :deploy => :environment do
73
+ to :before_hook do
74
+ # Put things to run locally before ssh
75
+ end
76
+ deploy do
77
+ # Put things that will set up an empty directory into a fully set-up
78
+ # instance of your project.
79
+ invoke :'git:clone'
80
+ invoke :'deploy:link_shared_paths'
81
+ invoke :'bundle:install'
82
+ invoke :'rails:db_migrate'
83
+ invoke :'rails:assets_precompile'
84
+ invoke :'deploy:cleanup'
85
+
86
+ to :launch do
87
+ queue "mkdir -p #{deploy_to}/#{current_path}/tmp/"
88
+ queue "mkdir -p #{deploy_to}/#{current_path}/tmp/logs"
89
+ queue "mkdir -p #{deploy_to}/#{current_path}/tmp/pids"
90
+ queue "mkdir -p #{deploy_to}/#{current_path}/tmp/sockets"
91
+ queue "touch #{deploy_to}/#{current_path}/tmp/restart.txt"
92
+ invoke :'unicorn:restart'
93
+ end
94
+ end
95
+ end
96
+
97
+ desc "kill unicorn"
98
+ task :kill_unicorn do
99
+ queue "pkill -f app_name_for_replace"
100
+ end
101
+
102
+ desc "Shows logs."
103
+ task :logs do
104
+ queue %[cd #{deploy_to!}/current && tail -f log/production.log]
105
+ end
106
+
107
+ desc "Display the unicorn logs."
108
+ task :unicorn_logs do
109
+ queue 'echo "Contents of the unicorn log file are as follows:"'
110
+ queue "tail -f #{deploy_to}/current/log/unicorn.log"
111
+ end
112
+
113
+ # For help in making your deploy script, see the Mina documentation:
114
+ #
115
+ # - http://nadarei.co/mina
116
+ # - http://nadarei.co/mina/tasks
117
+ # - http://nadarei.co/mina/settings
118
+ # - http://nadarei.co/mina/helpers
119
+
120
+
@@ -0,0 +1,29 @@
1
+ upstream app_name_for_replace {
2
+ # Path to Unicorn SOCK file, as defined previously
3
+ server unix:/tmp/app_name_for_replace.unicorn.sock;
4
+ }
5
+
6
+ server {
7
+
8
+
9
+ listen 80;
10
+ server_name domain_name_for_replace;
11
+
12
+ # Application root, as defined previously
13
+ root /home/chuck/www/app_name_for_replace/current/public;
14
+
15
+ try_files $uri @app_name_for_replace;
16
+ access_log /var/log/nginx/app_name_for_replace_access.log;
17
+ error_log /var/log/nginx/app_name_for_replace_error.log;
18
+
19
+ location @app_name_for_replace{
20
+ proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
21
+ proxy_set_header Host $http_host;
22
+ proxy_redirect off;
23
+ proxy_pass http://app_name_for_replace;
24
+ }
25
+
26
+ error_page 500 502 503 504 /500.html;
27
+ client_max_body_size 4G;
28
+ keepalive_timeout 10;
29
+ }
@@ -0,0 +1,35 @@
1
+ app_path = File.expand_path( File.join(File.dirname(__FILE__), '..'))
2
+ worker_processes 2
3
+ timeout 180
4
+ listen '/tmp/app_name_for_replace.unicorn.sock'
5
+ pid "#{app_path}/tmp/pids/unicorn.pid"
6
+ stderr_path "log/unicorn.log"
7
+ stdout_path "log/unicorn.log"
8
+
9
+ before_fork do |server, worker|
10
+ if defined?(ActiveRecord::Base)
11
+ ActiveRecord::Base.connection.disconnect!
12
+ end
13
+
14
+ old_pid = "#{server.config[:pid]}.oldbin"
15
+ if File.exists?(old_pid) && server.pid != old_pid
16
+ begin
17
+ Process.kill("QUIT", File.read(old_pid).to_i)
18
+ rescue Errno::ENOENT, Errno::ESRCH
19
+ # someone else did our job for us
20
+ end
21
+ end
22
+ end
23
+
24
+ after_fork do |server, worker|
25
+ if defined?(ActiveRecord::Base)
26
+ ActiveRecord::Base.establish_connection
27
+ end
28
+ end
29
+
30
+ working_directory("#{app_path}")
31
+ puts app_path
32
+
33
+ before_exec do |server| # 修正无缝重启unicorn后更新的Gem未生效的问题,原因是config/boot.rb会优先从ENV中获取BUNDLE_GEMFILE,而无缝重启时ENV['BUNDLE_GEMFILE']的值并未被清除,仍指向旧目录的Gemfile
34
+ ENV["BUNDLE_GEMFILE"] = "#{app_path}/Gemfile"
35
+ end
data/lib/weapon.rb CHANGED
@@ -34,28 +34,50 @@ class Weapon < Thor
34
34
  end
35
35
 
36
36
 
37
- desc "setup_mina_deploy", "setup mina deploy"
38
- def setup_mina_deploy
37
+ desc "setup_mina_unicorn", "setup mina deploy and unicorn server"
38
+ def setup_mina_unicorn
39
39
  makesure_in_git
40
+
41
+ gem 'mina-unicorn', require: false
42
+ gem 'unicorn'
43
+ run "bundle"
44
+ app_name = ask("input your app name, used to config unix sock file name: ")
45
+
46
+ copy_file 'support/mina_unicorn/unicorn.rb', 'config/unicorn.rb'
47
+ gsub_file "config/unicorn.rb", "app_name_for_replace", app_name
48
+
49
+ copy_file 'support/mina_unicorn/unicorn-nginx.conf', 'unicorn-nginx.conf'
50
+ gsub_file "config/unicorn.rb", "app_name_for_replace", app_name
51
+
52
+ domain_name = ask("input your domain name, used as nginx conf file's server_name, like www.example.com: ")
53
+ gsub_file "unicorn-nginx.conf", "app_name_for_replace", app_name
54
+ gsub_file "unicorn-nginx.conf", "domain_name_for_replace", domain_name
55
+
40
56
  puts "setup mina deploy"
41
- run "mina init"
57
+ copy_file 'support/mina_unicorn/deploy.rb', 'config/deploy.rb'
58
+
59
+ gsub_file "config/deploy.rb", "app_name_for_replaceA", app_name
60
+
42
61
  username = ask("input your user name on deploy host:")
43
- File.open('config/deploy.rb', 'a') { |f| f.write("\nset :user, '#{username}' ")}
62
+ gsub_file "config/deploy.rb", "user_name_fore_replace", username
63
+
44
64
  domain = ask("input your deploy host, like example.com or 123.100.100.100:")
45
- gsub_file "config/deploy.rb", "'foobar.com'", "'" + domain + "'"
65
+ gsub_file "config/deploy.rb", "domain_name_for_replace", domain
66
+
46
67
  directory = ask("input your deploy directory:")
47
68
  directory = directory.gsub(/\/$/, "")
48
- gsub_file "config/deploy.rb", "/var/www/foobar.com", directory
69
+ gsub_file "config/deploy.rb", "deploy_path_for_replace", directory
49
70
 
50
71
  default_repo = `git remote -v`.split(' ')[1]
51
72
  repository = ask("input your git remote url to pull from, default #{default_repo} ")
52
- gsub_file "config/deploy.rb", "git://...", (repository != "")?repository: default_repo
73
+ gsub_file "config/deploy.rb", "repo_path_for_replace", (repository != "")?repository: default_repo
53
74
 
54
75
  setup_dir_command = 'ssh ' + username + '@' + domain + " -t 'mkdir -p " + directory + ';chown -R ' + username + ' ' + directory + "'"
55
76
  run setup_dir_command
56
77
 
57
78
  run 'mina setup'
58
79
  run 'scp config/database.yml ' + username + '@' + domain + ':' + directory + '/shared/config/'
80
+ run 'scp unicorn-nginx.conf ' + username + '@' + domain + ':' + '/etc/nginx/sites-enabled/#{app_name}.conf'
59
81
  run 'mina deploy'
60
82
  end
61
83
 
@@ -120,6 +142,8 @@ class Weapon < Thor
120
142
  invoke :setup_settings_ui
121
143
  end
122
144
 
145
+
146
+
123
147
  desc "install_must_gems", "install must need gems like guard, guard-livereload, guard-rspec..."
124
148
  def install_must_gems
125
149
  makesure_in_git
@@ -142,9 +166,7 @@ class Weapon < Thor
142
166
  gem 'mina', require: false
143
167
  gem 'mina-multistage', require: false
144
168
  gem 'mina-sidekiq', require: false
145
- gem 'mina-unicorn', require: false
146
169
 
147
- gem 'unicorn'
148
170
  gem 'figaro'
149
171
  gem 'whenever', '~> 0.9.2'
150
172
  gem "rails-erd"
@@ -201,6 +223,9 @@ class Weapon < Thor
201
223
  run "bundle"
202
224
  run "guard init"
203
225
 
226
+ run "you might need to remove gem byebug, it might conflict with pry-byebug"
227
+
228
+
204
229
  end
205
230
 
206
231
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: weapon
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 0.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chuck.lei
@@ -84,6 +84,9 @@ files:
84
84
  - lib/support/custom_i18n/show.html.slim
85
85
  - lib/support/custom_i18n/zh-CN.yml
86
86
  - lib/support/exception_slack_notify/exception_notification.rb
87
+ - lib/support/mina_unicorn/deploy.rb
88
+ - lib/support/mina_unicorn/unicorn-nginx.conf
89
+ - lib/support/mina_unicorn/unicorn.rb
87
90
  - lib/support/rails_settings_ui/rails_settings_ui.rb
88
91
  - lib/support/rails_settings_ui/setting.rb
89
92
  - lib/weapon.rb