luban-rack 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 88aed31e8c5bd4a6902db96f703cb1033697aa34
4
+ data.tar.gz: a7c17e9b1bb17d88e222490bda22c95ed88441c2
5
+ SHA512:
6
+ metadata.gz: 28b52f98ba0219a1bae69d782147c701f3a764be622b7cf9dfa1bb11ce459dfdaa48bcb38575495a990bb3fd5eb831d911ac7f5579e3980ec26d241331766ff6
7
+ data.tar.gz: ebcccb620f86e27be90ae52f9ae015a26690925f81abe9911ecf408d4db7d111aeda73a205db971fb7c38cb910c62d06e6d11a7751dd65f84384e96f540b4d71
data/.gitignore ADDED
@@ -0,0 +1,10 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ .DS_Store
data/CHANGELOG.md ADDED
@@ -0,0 +1,7 @@
1
+ # Change log
2
+
3
+ ## Version 0.1.0 (Jul 08, 2016)
4
+
5
+ New features:
6
+ * Initialized Luban deployment application for Rack
7
+ * Added support for web server Thin
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in luban-rack.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Chi Man Lei
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,38 @@
1
+ # Luban::Rack
2
+
3
+ Luban deployment application to manage Rack based web application deployment and control
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'luban-rack'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install luban-rack
20
+
21
+ ## Usage
22
+
23
+ TODO: Write usage instructions here
24
+
25
+ ## Development
26
+
27
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
28
+
29
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
30
+
31
+ ## Contributing
32
+
33
+ Bug reports and pull requests are welcome on GitHub at https://github.com/lubanrb/rack.
34
+
35
+ ## License
36
+
37
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
38
+
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "luban/rack"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,48 @@
1
+ module Luban
2
+ module Deployment
3
+ module Applications
4
+ class Rack < Luban::Deployment::Application
5
+ using Luban::CLI::CoreRefinements
6
+
7
+ module Parameters
8
+ extend Luban::Deployment::Parameters::Base
9
+
10
+ DefaultWebServer = :thin
11
+
12
+ parameter :web_server
13
+
14
+ protected
15
+
16
+ def set_default_rack_parameters
17
+ set_default :web_server, DefaultWebServer
18
+ end
19
+ end
20
+
21
+ include Parameters
22
+
23
+ def default_templates_path
24
+ @default_templates_path ||= super(__FILE__).join(web_server.to_s)
25
+ end
26
+
27
+ dispatch_task :phased_restart_process, to: :controller
28
+
29
+ protected
30
+
31
+ def set_default_application_parameters
32
+ super
33
+ linked_dirs.push('sockets')
34
+ set_default_rack_parameters
35
+ end
36
+
37
+ def setup_control_tasks
38
+ super
39
+
40
+ task :phased_restart do
41
+ desc "Phased restart process"
42
+ action! :phased_restart_process
43
+ end
44
+ end
45
+ end
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,26 @@
1
+ module Luban
2
+ module Deployment
3
+ module Applications
4
+ class Rack
5
+ class Configurator < Luban::Deployment::Application::Configurator
6
+ using Luban::CLI::CoreRefinements
7
+
8
+ include Paths
9
+ include Parameters
10
+
11
+ protected
12
+
13
+ def init
14
+ load_web_server
15
+ end
16
+
17
+ def load_web_server
18
+ require_relative "web_servers/#{web_server}"
19
+ server_module = WebServers.const_get(web_server.camelcase).const_get('Common')
20
+ singleton_class.send(:prepend, server_module)
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,70 @@
1
+ module Luban
2
+ module Deployment
3
+ module Applications
4
+ class Rack
5
+ class Controller < Luban::Deployment::Application::Controller
6
+ using Luban::CLI::CoreRefinements
7
+
8
+ include Luban::Deployment::Service::Controller::Cluster
9
+ include Paths
10
+ include Parameters
11
+
12
+ def release_matched?
13
+ release_tag =~ /^#{Regexp.escape(application_version)}/
14
+ end
15
+
16
+ def release_tag
17
+ @release_tag ||= release_path.basename
18
+ end
19
+
20
+ def release_path
21
+ @release_path ||= Pathname.new(readlink(app_path.join('app')))
22
+ end
23
+
24
+ def restart_process(phased: false)
25
+ if process_stopped?
26
+ update_result "Skipped! Already stopped. Please start #{application_full_name} normally.", status: :skipped
27
+ return
28
+ end
29
+
30
+ unmonitor_process
31
+ output = (phased ? phased_restart_process! : restart_process!) || 'OK'
32
+
33
+ if check_until { process_started? }
34
+ update_result "Restart #{service_full_name}: [OK] #{output}"
35
+ monitor_process
36
+ else
37
+ remove_orphaned_pid_file
38
+ update_result "Restart #{service_full_name}: [FAILED] #{output}",
39
+ status: :failed, level: :error
40
+ end
41
+ end
42
+
43
+ def phased_restart_process
44
+ restart_process(phased: true)
45
+ end
46
+
47
+ protected
48
+
49
+ def init
50
+ load_web_server
51
+ end
52
+
53
+ def load_web_server
54
+ require_relative "web_servers/#{web_server}"
55
+ server_module = WebServers.const_get(web_server.camelcase)
56
+ singleton_class.send(:prepend, server_module)
57
+ end
58
+
59
+ def restart_process!
60
+ capture("#{restart_command} 2>&1")
61
+ end
62
+
63
+ def phased_restart_process!
64
+ capture("#{phased_restart_command} 2>&1")
65
+ end
66
+ end
67
+ end
68
+ end
69
+ end
70
+ end
@@ -0,0 +1,53 @@
1
+ module Luban
2
+ module Deployment
3
+ module Applications
4
+ class Rack
5
+ module Paths
6
+ def log_file_name
7
+ @log_file_name ||= "#{web_server}.log"
8
+ end
9
+
10
+ def pid_file_name
11
+ @pid_file_name ||= "#{web_server}.pid"
12
+ end
13
+
14
+ def pid_file_pattern
15
+ @pid_file_pattern ||= "#{web_server}.*.pid"
16
+ end
17
+
18
+ def control_file_name
19
+ @control_file_name ||= "#{web_server}.#{control_file_extname}"
20
+ end
21
+
22
+ def control_file_extname
23
+ @control_file_extname ||= "rb"
24
+ end
25
+
26
+ def logrotate_file_name
27
+ @logrotate_file_name ||= "#{web_server}.logrotate"
28
+ end
29
+
30
+ def sockets_path
31
+ @sockets_path ||= shared_path.join('sockets')
32
+ end
33
+
34
+ def socket_file_path
35
+ @socket_file_path ||= sockets_path.join(socket_file_name)
36
+ end
37
+
38
+ def socket_file_name
39
+ @socket_file_name ||= "#{web_server}.sock"
40
+ end
41
+
42
+ def ruby_bin_path
43
+ @ruby_bin_path ||= package_bin_path('ruby')
44
+ end
45
+
46
+ def bundle_executable
47
+ @bundle_executable ||= ruby_bin_path.join('bundle')
48
+ end
49
+ end
50
+ end
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,14 @@
1
+ # Thin logrotate configuration
2
+
3
+ <%= log_path.join('thin*.log') %> {
4
+ daily
5
+ missingok
6
+ rotate 14
7
+ compress
8
+ dateext
9
+ notifempty
10
+ sharedscripts
11
+ postrotate
12
+ pgrep -f "<%= process_pattern %>" >/dev/null 2>&1 || pkill -USR1 -f "<%= process_pattern %>" >/dev/null 2>&1 || true
13
+ endscript
14
+ }
@@ -0,0 +1,14 @@
1
+ # Monit Monit configuration for Thin
2
+
3
+ check process <%= service_entry %>
4
+ with pidfile <%= pid_file_path %>
5
+ start program = "/bin/bash -c 'sleep 1; <%= start_command %>'"
6
+ stop program = "/bin/bash -c '<%= stop_command %>'"
7
+ if totalmem is greater than 150.0 MB for 40 cycles then alert
8
+ if failed port 3000 for 4 times within 8 cycles then restart
9
+ if failed port 3001 for 4 times within 8 cycles then restart
10
+ if failed port 3002 for 4 times within 8 cycles then restart
11
+ if failed port 3003 for 4 times within 8 cycles then restart
12
+ # if failed unixsocket <%= socket_file_path %> for 4 times within 8 cycles then restart
13
+ if cpu is greater than 80% for 20 cycles then alert
14
+ if loadavg(5min) greater than 10 for 40 cycles then alert
@@ -0,0 +1,27 @@
1
+ ---
2
+ # Server options
3
+ # address: 0.0.0.0
4
+ # port: 3000
5
+ # socket: <%= socket_file_path %>
6
+ chdir: <%= release_path %>
7
+
8
+ # Adapter options
9
+ environment: <%= stage %>
10
+
11
+ # Daemon options
12
+ daemonize: true
13
+ log: <%= log_file_path %>
14
+ pid: <%= pid_file_path %>
15
+ tag: <%= "#{env_name}:#{release_tag}" %>
16
+
17
+ # Cluster options
18
+ servers: 4
19
+ wait: 30
20
+
21
+ # Tuning options
22
+ # timeout: 30
23
+ # max_conns: 1024
24
+ # max_persistent_conns: 100
25
+
26
+ # Common options
27
+ # trace: true
@@ -0,0 +1,9 @@
1
+ module Luban
2
+ module Deployment
3
+ module Applications
4
+ class Rack
5
+ VERSION = '0.1.0'
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,43 @@
1
+ module Luban
2
+ module Deployment
3
+ module Applications
4
+ class Rack
5
+ module WebServers
6
+ module Thin
7
+ module Common
8
+ def control_file_extname
9
+ @control_file_extname ||= "yml"
10
+ end
11
+
12
+ def thin_command
13
+ @thin_command ||= "#{bundle_executable} exec thin -C #{control_file_path}"
14
+ end
15
+
16
+ def start_command
17
+ @start_command ||= "cd #{release_path}; #{thin_command} start"
18
+ end
19
+
20
+ def stop_command
21
+ @stop_command ||= "cd #{release_path}; #{thin_command} stop"
22
+ end
23
+
24
+ def process_pattern
25
+ @process_pattern ||= "^thin server.+\\[#{Regexp.escape(env_name)}:#{Regexp.escape(application_version)}-[0-9a-f]+\\]"
26
+ end
27
+ end
28
+
29
+ include Common
30
+
31
+ def restart_command
32
+ @restart_command ||= "cd #{release_path}; #{thin_command} restart"
33
+ end
34
+
35
+ def phased_restart_command
36
+ @phased_restart_command ||= "cd #{release_path}; #{thin_command} restart --onebyone"
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,6 @@
1
+ require 'luban'
2
+ require_relative 'rack/base'
3
+ require_relative 'rack/paths'
4
+ require_relative 'rack/controller'
5
+ require_relative 'rack/configurator'
6
+ require_relative 'rack/version'
data/lib/luban/rack.rb ADDED
@@ -0,0 +1 @@
1
+ require_relative "deployment/applications/rack"
data/lib/luban-rack.rb ADDED
File without changes
@@ -0,0 +1,28 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'luban/deployment/applications/rack/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "luban-rack"
8
+ spec.version = Luban::Deployment::Applications::Rack::VERSION
9
+ spec.authors = ["Rubyist Chi"]
10
+ spec.email = ["rubyist.chi@gmail.com"]
11
+
12
+ spec.summary = %q{Rack support for Luban}
13
+ spec.description = %q{Luban::Rack is a Luban deployment application to manage Rack based web application deployment and control}
14
+ spec.homepage = "https://github.com/lubanrb/rack"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.bindir = "exe"
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.required_ruby_version = ">= 2.1.0"
23
+ spec.add_dependency 'luban'
24
+
25
+ spec.add_development_dependency "bundler", "~> 1.12"
26
+ spec.add_development_dependency "rake", "~> 10.0"
27
+ spec.add_development_dependency "minitest", "~> 5.0"
28
+ end
metadata ADDED
@@ -0,0 +1,122 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: luban-rack
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Rubyist Chi
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-07-08 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: luban
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.12'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.12'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: minitest
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '5.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '5.0'
69
+ description: Luban::Rack is a Luban deployment application to manage Rack based web
70
+ application deployment and control
71
+ email:
72
+ - rubyist.chi@gmail.com
73
+ executables: []
74
+ extensions: []
75
+ extra_rdoc_files: []
76
+ files:
77
+ - ".gitignore"
78
+ - CHANGELOG.md
79
+ - Gemfile
80
+ - LICENSE.txt
81
+ - README.md
82
+ - Rakefile
83
+ - bin/console
84
+ - bin/setup
85
+ - lib/luban-rack.rb
86
+ - lib/luban/deployment/applications/rack.rb
87
+ - lib/luban/deployment/applications/rack/base.rb
88
+ - lib/luban/deployment/applications/rack/configurator.rb
89
+ - lib/luban/deployment/applications/rack/controller.rb
90
+ - lib/luban/deployment/applications/rack/paths.rb
91
+ - lib/luban/deployment/applications/rack/templates/thin/thin.logrotate.erb
92
+ - lib/luban/deployment/applications/rack/templates/thin/thin.monitrc.erb
93
+ - lib/luban/deployment/applications/rack/templates/thin/thin.yml.erb
94
+ - lib/luban/deployment/applications/rack/version.rb
95
+ - lib/luban/deployment/applications/rack/web_servers/thin.rb
96
+ - lib/luban/rack.rb
97
+ - luban-rack.gemspec
98
+ homepage: https://github.com/lubanrb/rack
99
+ licenses:
100
+ - MIT
101
+ metadata: {}
102
+ post_install_message:
103
+ rdoc_options: []
104
+ require_paths:
105
+ - lib
106
+ required_ruby_version: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: 2.1.0
111
+ required_rubygems_version: !ruby/object:Gem::Requirement
112
+ requirements:
113
+ - - ">="
114
+ - !ruby/object:Gem::Version
115
+ version: '0'
116
+ requirements: []
117
+ rubyforge_project:
118
+ rubygems_version: 2.5.1
119
+ signing_key:
120
+ specification_version: 4
121
+ summary: Rack support for Luban
122
+ test_files: []