cap-uwsgi 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: c39d5845a45cbbc925b9bbf521cd50dc68e55054
4
+ data.tar.gz: e197fe634cd316cd1334703c826e23b1dca195fd
5
+ SHA512:
6
+ metadata.gz: db6a117e3f2eefe089c25eb64c04919c7eef83abe4ddb8d1014195c3849b1d805fac5879f2a88927a8eac70eebeeb029bf5dd1dc32e5873fd351ee792eada51b
7
+ data.tar.gz: e76fc46483f7330d4e4e999551061a3d2cfa64dfecd756d9f8fc4cf02c655499ecca09fddcb9227e22382532049bc85a2a0aca59b5c32c6dc264c91c4b0d35e8
data/.gitignore ADDED
@@ -0,0 +1,5 @@
1
+ puma
2
+ sh
3
+ *~
4
+ pkg
5
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ #source 'https://rubygems.org'
2
+ source "http://ruby.taobao.org"
3
+
4
+ # Specify your gem's dependencies in capistrano-puma.gemspec
5
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,31 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ capistrano-uwsgi (0.0.1)
5
+ capistrano (~> 3.0)
6
+
7
+ GEM
8
+ remote: http://ruby.taobao.org/
9
+ specs:
10
+ capistrano (3.1.0)
11
+ i18n
12
+ rake (>= 10.0.0)
13
+ sshkit (~> 1.3)
14
+ i18n (0.6.9)
15
+ net-scp (1.1.2)
16
+ net-ssh (>= 2.6.5)
17
+ net-ssh (2.8.0)
18
+ rake (10.1.1)
19
+ sshkit (1.3.0)
20
+ net-scp (>= 1.1.2)
21
+ net-ssh
22
+ term-ansicolor
23
+ term-ansicolor (1.3.0)
24
+ tins (~> 1.0)
25
+ tins (1.0.0)
26
+
27
+ PLATFORMS
28
+ ruby
29
+
30
+ DEPENDENCIES
31
+ capistrano-uwsgi!
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/Readme.md ADDED
@@ -0,0 +1,10 @@
1
+ # A capistrano3+ integration for uWSGI.
2
+
3
+ ### Usage
4
+
5
+ gem 'cap-uwsgi'
6
+
7
+ ### Ref
8
+
9
+ * https://github.com/cao7113/uwsgi-rails-demo
10
+ * capistrano-puma
data/cap-uwsgi.gemspec ADDED
@@ -0,0 +1,21 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'capistrano/uwsgi/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'cap-uwsgi'
8
+ spec.version = Capistrano::Uwsgi::VERSION
9
+ spec.authors = ['cao7113']
10
+ spec.email = ['cao7113@hotmail.com']
11
+ spec.description = %q{uWSGI integration for Capistrano 3}
12
+ spec.summary = %q{uWSGI integration for Capistrano 3}
13
+ spec.homepage = 'http://shareup.me'
14
+ spec.license = 'MIT'
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.require_paths = ['lib']
18
+
19
+ spec.add_dependency 'capistrano', '~> 3.0'
20
+
21
+ end
data/lib/cap-uwsgi.rb ADDED
File without changes
@@ -0,0 +1,90 @@
1
+ namespace :load do
2
+ task :defaults do
3
+ set :uwsgi_emperor_conf_dir, '/etc/uwsgi'
4
+ set :uwsgi_emperor_user, fetch(:app_user)||ENV["USER"]
5
+ set :uwsgi_emperor_job_name, 'emperor'
6
+ set :uwsgi_emperor_init, "/etc/init/#{fetch(:uwsgi_emperor_job_name)}.conf"
7
+ set :uwsgi_emperor_log, "/var/log/#{fetch(:uwsgi_emperor_job_name)}.log"
8
+ end
9
+ end
10
+
11
+ namespace :uwsgi do
12
+ namespace :emperor do
13
+
14
+ desc 'Install uWSGI emperor'
15
+ task :install do
16
+ on roles(fetch(:uwsgi_role)) do |role|
17
+ @role = role
18
+ if test "[ ! -d #{fetch(:uwsgi_emperor_conf_dir)} ]"
19
+ sudo "mkdir -p #{fetch(:uwsgi_emperor_conf_dir)}"
20
+ sudo "chown -R #{fetch(:uwsgi_emperor_user)}:#{fetch(:uwsgi_emperor_user)} #{fetch(:uwsgi_emperor_conf_dir)}"
21
+ template_uwsgi 'uwsgi_emperor.conf', "#{fetch(:tmp_dir)}/uwsgi_emperor.conf", role
22
+ sudo "mv -b #{fetch(:tmp_dir)}/uwsgi_emperor.conf #{fetch(:uwsgi_emperor_init)}"
23
+ sudo "touch #{fetch(:uwsgi_emperor_log)}"
24
+ sudo "chown #{fetch(:uwsgi_emperor_user)}:#{fetch(:uwsgi_emperor_user)} #{fetch(:uwsgi_emperor_log)}"
25
+ end
26
+ end
27
+ end
28
+
29
+ desc 'Uninstall uWSGI emperor'
30
+ task :uninstall do
31
+ on roles(fetch(:uwsgi_role)) do |role|
32
+ #warning?
33
+ if test "[ -d #{fetch(:uwsgi_emperor_conf_dir)} ]"
34
+ #sudo "stop emperor"
35
+ sudo "rm -f #{fetch(:uwsgi_emperor_init)} #{fetch(:uwsgi_emperor_log)}"
36
+ sudo "rm -r #{fetch(:uwsgi_emperor_conf_dir)}"
37
+ end
38
+ end
39
+ end
40
+
41
+ %w[start stop restart status].each do |command|
42
+ desc "#{command} uwsgi emperor"
43
+ task "#{command}" do
44
+ on roles(fetch(:uwsgi_role)) do
45
+ sudo "#{command} #{fetch(:uwsgi_emperor_job_name)}"
46
+ end
47
+ end
48
+ end
49
+
50
+ desc 'List all emperor apps'
51
+ task :list do
52
+ on roles(fetch(:uwsgi_role)) do |role|
53
+ sudo "ls -l #{fetch(:uwsgi_emperor_conf_dir)}"
54
+ end
55
+ end
56
+
57
+ desc 'Backup emperor apps config'
58
+ task :backup do
59
+ on roles(fetch(:uwsgi_role)) do |role|
60
+ sudo "cp -r #{fetch(:uwsgi_emperor_conf_dir)} #{fetch(:uwsgi_emperor_conf_dir)}-#{Time.now.to_s.gsub(/\D/, '')}"
61
+ end
62
+ end
63
+
64
+ desc 'Add current project to the emperor'
65
+ task :add do
66
+ on roles(fetch(:uwsgi_role)), in: :sequence, wait: 1 do |role|
67
+ @role = role
68
+ template_uwsgi 'uwsgi.ini', "#{emperor_app_conf}", @role
69
+ end
70
+ end
71
+
72
+ desc 'Remove current project from the emperor'
73
+ task :remove do
74
+ on roles(fetch(:uwsgi_role)) do
75
+ sudo "rm -f '#{emperor_app_conf}'"
76
+ end
77
+ end
78
+
79
+ desc 'Touch current project for reload'
80
+ task :touch do
81
+ on roles(fetch(:uwsgi_role)) do
82
+ sudo "touch '#{emperor_app_conf}'"
83
+ end
84
+ end
85
+
86
+ def emperor_app_conf
87
+ "#{fetch(:uwsgi_emperor_conf_dir)}/#{fetch(:application)}-#{fetch(:stage)}.ini"
88
+ end
89
+ end
90
+ end
@@ -0,0 +1,56 @@
1
+ namespace :load do
2
+ task :defaults do
3
+ set :uwsgi_nginx_conf_dir, "/etc/nginx/conf.d"
4
+ end
5
+ end
6
+
7
+ namespace :uwsgi do
8
+ namespace :nginx do
9
+ desc 'Config uwsgi nginx service'
10
+ task :conf do
11
+ on roles(fetch(:uwsgi_role)) do |role|
12
+ @role = role
13
+ template_uwsgi 'uwsgi_nginx.conf', "#{fetch(:tmp_dir)}/nginx.conf", @role
14
+ sudo "mv -b #{fetch(:tmp_dir)}/nginx.conf #{uwsgi_nginx_app_conf}"
15
+ end
16
+ end
17
+
18
+ desc 'Remove uwsgi nginx service config file'
19
+ task :deconf do
20
+ on roles(fetch(:uwsgi_role)) do |role|
21
+ @role = role
22
+ sudo "rm -f #{uwsgi_nginx_app_conf}"
23
+ end
24
+ end
25
+
26
+ %w(status start stop restart reload configtest force-reload upgrade).each do |act|
27
+ desc "#{act} nginx service"
28
+ task "#{act}" do
29
+ on roles(fetch(:uwsgi_role)) do |role|
30
+ @role = role
31
+ sudo "service nginx #{act}"
32
+ end
33
+ end
34
+ end
35
+
36
+ desc "Cat nginx config file"
37
+ task :catconf do
38
+ on roles(fetch(:uwsgi_role)) do |role|
39
+ @role = role
40
+ sudo "cat #{uwsgi_nginx_app_conf}"
41
+ end
42
+ end
43
+
44
+ desc "Cat nginx service pid"
45
+ task :catpid do
46
+ on roles(fetch(:uwsgi_role)) do |role|
47
+ @role = role
48
+ sudo "cat /var/run/nginx.pid"
49
+ end
50
+ end
51
+
52
+ def uwsgi_nginx_app_conf
53
+ fetch(:uwsgi_nginx_app_conf, "#{fetch(:uwsgi_nginx_conf_dir)}/uwsgi-#{fetch(:application)}.conf")
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,70 @@
1
+ namespace :load do
2
+ task :defaults do
3
+ set :uwsgi_role, :app
4
+ set :uwsgi_env, -> { fetch(:rack_env, fetch(:rails_env, 'production')) }
5
+ set :uwsgi_access_log, -> { File.join(shared_path, 'log', 'uwsgi_access.log') }
6
+ set :uwsgi_error_log, -> { File.join(shared_path, 'log', 'uwsgi_error.log') }
7
+ set :uwsgi_bin_uwsgi, `which uwsgi`.chomp
8
+
9
+ #set :uwsgi_pid, -> { File.join(shared_path, 'tmp', 'pids', 'uwsgi.pid') }
10
+ #set :uwsgi_bind, -> { File.join('unix://', shared_path, 'tmp', 'sockets', 'uwsgi.sock') }
11
+ #set :uwsgi_init_active_record, false
12
+ #set :uwsgi_preload_app, true
13
+ # Rbenv and RVM integration
14
+ #set :rbenv_map_bins, fetch(:rbenv_map_bins).to_a.concat(%w{ uwsgi uwsgictl })
15
+ #set :rvm_map_bins, fetch(:rvm_map_bins).to_a.concat(%w{ uwsgi uwsgictl })
16
+ end
17
+ end
18
+
19
+ namespace :uwsgi do
20
+ desc "Test on remote"
21
+ task :test do
22
+ on roles(fetch(:uwsgi_role)) do |role|
23
+ @role = role
24
+ execute "echo $PATH"
25
+ execute "echo #{fetch(:uwsgi_bin_uwsgi)}"
26
+ end
27
+ end
28
+
29
+ desc "Install uwsgi for ruby/rack app"
30
+ task :install do
31
+ on roles(fetch(:uwsgi_role)) do |role|
32
+ @role = role
33
+ if test "! gem query -in uwsgi >/dev/null"
34
+ sudo "apt-get -y install libssl-dev libpcre3-dev"
35
+ execute "gem install uwsgi"
36
+ end
37
+ end
38
+ end
39
+
40
+ desc "Ps this application"
41
+ task :ps do
42
+ on roles(fetch(:uwsgi_role)) do |role|
43
+ @role = role
44
+ sudo "ps aux|grep #{fetch(:application)}"
45
+ end
46
+ end
47
+
48
+ def template_uwsgi(from, to, role)
49
+ [
50
+ "config/#{from}-#{role.hostname}}.erb",
51
+ "config/#{from}-#{fetch(:stage)}.erb",
52
+ "config/#{from}.erb",
53
+ "lib/capistrano/templates/#{from}-#{role.hostname}-#{fetch(:stage)}.rb",
54
+ "lib/capistrano/templates/#{from}-#{role.hostname}-#{fetch(:stage)}.rb",
55
+ "lib/capistrano/templates/#{from}-#{role.hostname}.rb",
56
+ "lib/capistrano/templates/#{from}-#{fetch(:stage)}.rb",
57
+ "lib/capistrano/templates/#{from}.rb.erb",
58
+ "lib/capistrano/templates/#{from}.rb",
59
+ "lib/capistrano/templates/#{from}.erb",
60
+ File.expand_path("../../templates/#{from}.rb.erb", __FILE__),
61
+ File.expand_path("../../templates/#{from}.erb", __FILE__)
62
+ ].each do |path|
63
+ if File.file?(path)
64
+ erb = File.read(path)
65
+ upload! StringIO.new(ERB.new(erb).result(binding)), to
66
+ break
67
+ end
68
+ end
69
+ end
70
+ end
@@ -0,0 +1,15 @@
1
+ [uwsgi]
2
+ socket = <%=shared_path%>/tmp/sockets/uwsgi.sock
3
+ chmod-socket = 666
4
+ #http = :3010
5
+ #http-modifier1 = 7
6
+ rack = config.ru
7
+ master = true
8
+ #processes = 2
9
+ # starting from 4.0, Rails support multiple threads(only for ruby2.0)
10
+ #rbthreads = 4
11
+ #lazy-apps = true
12
+ chdir = <%=current_path%>
13
+ rbrequire = bundler/setup
14
+ env = BUNDLE_GEMFILE=Gemfile
15
+ env = RAILS_ENV=<%=fetch(:rails_env)%>
@@ -0,0 +1,8 @@
1
+ description "uWSGI Emperor Job"
2
+ start on runlevel [2345]
3
+ stop on runlevel [06]
4
+
5
+ setuid <%=fetch(:uwsgi_emperor_user)%>
6
+ setgid <%=fetch(:uwsgi_emperor_user)%>
7
+
8
+ exec <%=fetch(:uwsgi_bin_uwsgi)%> --master --die-on-term --emperor <%=fetch(:uwsgi_emperor_conf_dir)%> --logto <%=fetch(:uwsgi_emperor_log)%>
@@ -0,0 +1,63 @@
1
+ upstream <%=fetch(:application)%>-<%=fetch(:stage)%>-sock {
2
+ server unix://<%=shared_path%>/tmp/sockets/uwsgi.sock;
3
+ }
4
+
5
+ server {
6
+ listen 80;
7
+ server_name <%=fetch(:nginx_server_name, "#{fetch(:application)}.lh")%>;
8
+
9
+ # ~2 seconds is often enough for most folks to parse HTML/CSS and
10
+ # retrieve needed images/icons/frames, connections are cheap in
11
+ # nginx so increasing this is generally safe...
12
+ keepalive_timeout 5;
13
+
14
+ # path for static files
15
+ root <%=deploy_to%>/current/public;
16
+ access_log <%=fetch(:uwsgi_access_log)%>;
17
+ error_log <%=fetch(:uwsgi_error_log)%>%> info;
18
+
19
+ # this rewrites all the requests to the maintenance.html
20
+ # page if it exists in the doc root. This is for capistrano's
21
+ # disable web task
22
+ if (-f $document_root/maintenance.html) {
23
+ rewrite ^(.*)$ /maintenance.html last;
24
+ break;
25
+ }
26
+
27
+ location / {
28
+ proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
29
+ proxy_set_header Host $http_host;
30
+
31
+ # If the file exists as a static file serve it directly without
32
+ # running all the other rewite tests on it
33
+ if (-f $request_filename) {
34
+ break;
35
+ }
36
+
37
+ # check for index.html for directory index
38
+ # if its there on the filesystem then rewite
39
+ # the url to add /index.html to the end of it
40
+ # and then break to send it to the next config rules.
41
+ if (-f $request_filename/index.html) {
42
+ rewrite (.*) $1/index.html break;
43
+ }
44
+
45
+ # this is the meat of the rack page caching config
46
+ # it adds .html to the end of the url and then checks
47
+ # the filesystem for that file. If it exists, then we
48
+ # rewite the url to have explicit .html on the end
49
+ # and then send it on its way to the next config rule.
50
+ # if there is no file on the fs then it sets all the
51
+ # necessary headers and proxies to our upstream uwsgis
52
+ if (-f $request_filename.html) {
53
+ rewrite (.*) $1.html break;
54
+ }
55
+
56
+ include uwsgi_params;
57
+ uwsgi_modifier1 7;
58
+ if (!-f $request_filename) {
59
+ uwsgi_pass <%=fetch(:application)%>-<%=fetch(:stage)%>-sock;
60
+ break;
61
+ }
62
+ }
63
+ }
@@ -0,0 +1 @@
1
+ load File.expand_path('../../tasks/emperor.cap', __FILE__)
@@ -0,0 +1 @@
1
+ load File.expand_path('../../tasks/nginx.cap', __FILE__)
@@ -0,0 +1,5 @@
1
+ module Capistrano
2
+ module Uwsgi
3
+ VERSION = '0.0.1'
4
+ end
5
+ end
@@ -0,0 +1 @@
1
+ load File.expand_path('../tasks/uwsgi.cap', __FILE__)
metadata ADDED
@@ -0,0 +1,75 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: cap-uwsgi
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - cao7113
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-02-22 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: '3.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '3.0'
27
+ description: uWSGI integration for Capistrano 3
28
+ email:
29
+ - cao7113@hotmail.com
30
+ executables: []
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - .gitignore
35
+ - Gemfile
36
+ - Gemfile.lock
37
+ - Rakefile
38
+ - Readme.md
39
+ - cap-uwsgi.gemspec
40
+ - lib/cap-uwsgi.rb
41
+ - lib/capistrano/tasks/emperor.cap
42
+ - lib/capistrano/tasks/nginx.cap
43
+ - lib/capistrano/tasks/uwsgi.cap
44
+ - lib/capistrano/templates/uwsgi.ini.erb
45
+ - lib/capistrano/templates/uwsgi_emperor.conf.erb
46
+ - lib/capistrano/templates/uwsgi_nginx.conf.erb
47
+ - lib/capistrano/uwsgi.rb
48
+ - lib/capistrano/uwsgi/emperor.rb
49
+ - lib/capistrano/uwsgi/nginx.rb
50
+ - lib/capistrano/uwsgi/version.rb
51
+ homepage: http://shareup.me
52
+ licenses:
53
+ - MIT
54
+ metadata: {}
55
+ post_install_message:
56
+ rdoc_options: []
57
+ require_paths:
58
+ - lib
59
+ required_ruby_version: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - '>='
62
+ - !ruby/object:Gem::Version
63
+ version: '0'
64
+ required_rubygems_version: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ requirements: []
70
+ rubyforge_project:
71
+ rubygems_version: 2.0.14
72
+ signing_key:
73
+ specification_version: 4
74
+ summary: uWSGI integration for Capistrano 3
75
+ test_files: []