capistrano-server 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in capistrano-server.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Wael M. Nasreddine
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
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.
@@ -0,0 +1,29 @@
1
+ # Capistrano::Server
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'capistrano-server'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install capistrano-server
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
@@ -0,0 +1,22 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |gem|
4
+ gem.authors = ["Wael M. Nasreddine"]
5
+ gem.email = ["wael.nasreddine@gmail.com"]
6
+ gem.description = 'Capistrano recipes for managing servers'
7
+ gem.summary = gem.summary
8
+ gem.homepage = 'http://technogate.github.com/contao'
9
+ gem.required_ruby_version = Gem::Requirement.new('>= 1.9.2')
10
+
11
+ gem.files = `git ls-files`.split($\)
12
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
13
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
14
+ gem.name = "capistrano-server"
15
+ gem.require_paths = ["lib"]
16
+ gem.version = '0.0.2'
17
+
18
+ # Runtime dependencies
19
+ gem.add_dependency 'rake'
20
+ gem.add_dependency 'capistrano'
21
+ gem.add_dependency 'capistrano-utils'
22
+ end
@@ -0,0 +1,70 @@
1
+ # encoding: utf-8
2
+
3
+ # Verify that Capistrano is version 2
4
+ unless Capistrano::Configuration.respond_to?(:instance)
5
+ abort 'capistrano/ext/nginx requires capistrano 2'
6
+ end
7
+
8
+ Capistrano::Configuration.instance(:must_exist).load do
9
+ namespace :deploy do
10
+ namespace :server do
11
+ namespace :web_server do
12
+ namespace :nginx do
13
+
14
+ _cset :nginx_init_path, "/etc/init.d/nginx"
15
+
16
+ desc "[internal] Generate Nginx configuration"
17
+ task :configuration, :roles => :web, :except => { :no_release => true } do
18
+ template = File.read File.expand_path('../../../templates/nginx.conf.erb', __FILE__)
19
+
20
+ nginx = OpenStruct.new
21
+ nginx.listen_port = fetch :web_server_listen_port, 80
22
+ nginx.application_url = fetch :application_url
23
+ nginx.indexes = fetch :web_server_indexes, %w(index.php index.html)
24
+ nginx.denied_access = fetch :denied_access, %w(.htaccess /system/logs)
25
+ nginx.auth_file = fetch :web_server_auth_file, nil
26
+ nginx.auth_credentials = fetch :web_server_auth_credentials, nil
27
+ nginx.rewrite = fetch :web_server_mod_rewrite, true
28
+ nginx.php_fpm_host = fetch :php_fpm_host, 'localhost'
29
+ nginx.php_fpm_port = fetch :php_fpm_port, '9000'
30
+ nginx.logs_path = fetch :logs_path
31
+ nginx.public_path = fetch :public_path
32
+
33
+ write ERB.new(template).result(binding),
34
+ fetch(:web_conf_file),
35
+ use_sudo: true
36
+ end
37
+
38
+ desc "Start nginx web server"
39
+ task :start, :roles => :web, :except => { :no_release => true } do
40
+ run <<-CMD
41
+ #{try_sudo} #{fetch :nginx_init_path} start
42
+ CMD
43
+ end
44
+
45
+ desc "Stop nginx web server"
46
+ task :stop, :roles => :web, :except => { :no_release => true } do
47
+ run <<-CMD
48
+ #{try_sudo} #{fetch :nginx_init_path} stop
49
+ CMD
50
+ end
51
+
52
+ desc "Restart nginx web server"
53
+ task :restart, :roles => :web, :except => { :no_release => true } do
54
+ run <<-CMD
55
+ #{try_sudo} #{fetch :nginx_init_path} restart
56
+ CMD
57
+ end
58
+
59
+ desc "Resload nginx web server"
60
+ task :reload, :roles => :web, :except => { :no_release => true } do
61
+ run <<-CMD
62
+ #{try_sudo} #{fetch :nginx_init_path} reload
63
+ CMD
64
+ end
65
+
66
+ end
67
+ end
68
+ end
69
+ end
70
+ end
@@ -0,0 +1,21 @@
1
+ unless Capistrano::Configuration.respond_to?(:instance)
2
+ abort 'capistrano/ext/contao requires capistrano 2'
3
+ end
4
+
5
+ Capistrano::Configuration.instance(:must_exist).load do
6
+ desc 'Send SSH key to the server'
7
+ task :scp_rsa, :roles => [:app, :web, :db] do
8
+ rsa = "#{ENV['HOME']}/.ssh/id_rsa.pub"
9
+
10
+ begin
11
+ run <<-CMD
12
+ mkdir -p ~/.ssh; \
13
+ touch ~/.ssh/authorized_keys; \
14
+ echo '#{File.read rsa}' >> ~/.ssh/authorized_keys;
15
+ CMD
16
+ rescue Capistrano::CommandError
17
+ logger.import 'Cannot send the SSH key to the server'
18
+ abort 'Cannot send the SSH key to the server'
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,26 @@
1
+ require 'capistrano/ext/helpers'
2
+ require 'capistrano/ext/rsa'
3
+ require 'capistrano/ext/web_server'
4
+
5
+ unless Capistrano::Configuration.respond_to?(:instance)
6
+ abort 'capistrano/ext/server requires capistrano 2'
7
+ end
8
+
9
+ Capistrano::Configuration.instance(:must_exist).load do
10
+ namespace :deploy do
11
+ namespace :server do
12
+ namespace :setup do
13
+ desc 'Prepare the server (database server, web server and folders)'
14
+ task :default, :roles => [:app, :db, :web] do
15
+ # Empty task, server preparation goes into callbacks
16
+ end
17
+
18
+ task :finish do
19
+ # Empty task for callbacks
20
+ end
21
+ end
22
+ end
23
+ end
24
+
25
+ after 'deploy:server:setup', 'deploy:server:web_server:setup'
26
+ end
@@ -0,0 +1,85 @@
1
+ require 'capistrano/ext/nginx'
2
+
3
+ unless Capistrano::Configuration.respond_to?(:instance)
4
+ abort 'capistrano/ext/web_server requires capistrano 2'
5
+ end
6
+
7
+ Capistrano::Configuration.instance(:must_exist).load do
8
+ namespace :deploy do
9
+ namespace :server do
10
+ namespace :web_server do
11
+ desc "Prepare the web server"
12
+ task :setup, :roles => :web, :except => { :no_release => true } do
13
+ # Empty task, server preparation goes into callbacks
14
+ end
15
+
16
+ task :finish, :roles => :web, :except => { :no_release => true } do
17
+ # Empty task, server preparation goes into callbacks
18
+ end
19
+
20
+ desc '[internal] Setup folders'
21
+ task :folders, :roles => :web do
22
+ sudo <<-CMD
23
+ mkdir -p #{File.dirname fetch(:web_conf_file)} #{File.dirname fetch(:web_server_auth_file, '')}
24
+ CMD
25
+ end
26
+
27
+ desc "[internal] Generate Web configuration"
28
+ task :configuration, :roles => :web, :except => { :no_release => true } do
29
+ case fetch(:web_server_app)
30
+ when :nginx
31
+ find_and_execute_task 'deploy:server:web_server:nginx:configuration'
32
+ else
33
+ abort "I don't know how to build '#{web_server_app}' configuration."
34
+ end
35
+ end
36
+
37
+ desc "[internal] Generate authentification"
38
+ task :authentification, :roles => :web, :except => { :no_release => true } do
39
+ if exists?(:web_server_auth_credentials)
40
+ content = Array.new
41
+ unencrypted_content = Array.new
42
+
43
+ fetch(:web_server_auth_credentials).each do |credentials|
44
+ if credentials[:password].respond_to?(:call)
45
+ password = credentials[:password].call
46
+ else
47
+ password = credentials[:password]
48
+ end
49
+
50
+ unencrypted_content << "#{credentials[:user]}:#{password}"
51
+ content << "#{credentials[:user]}:#{password.crypt(gen_pass(8))}"
52
+ end
53
+
54
+ # Write the encrypted content
55
+ write content.join("\n"),
56
+ fetch(:web_server_auth_file),
57
+ use_sudo: true
58
+
59
+ # Write the unencrypted content
60
+ write unencrypted_content.join("\n"),
61
+ "#{fetch :deploy_to}/.http_basic_auth"
62
+
63
+ logger.info "This site uses http basic auth, the credentials are:"
64
+ unencrypted_content.each do |m|
65
+ logger.trace "username: #{m.split(':').first.chomp} password: #{m.split(':').last.chomp}"
66
+ end
67
+ end
68
+ end
69
+
70
+ desc "print authentification file"
71
+ task :print_http_auth, :roles => :web, :except => { :no_release => true } do
72
+ read("#{fetch :deploy_to}/.http_basic_auth").split("\n").each do |m|
73
+ logger.trace "username: #{m.split(':').first.chomp} password: #{m.split(':').last.chomp}"
74
+ end
75
+ end
76
+ end
77
+ end
78
+ end
79
+
80
+ # Internal Dependencies
81
+ before 'deploy:server:web_server:configuration', 'deploy:server:web_server:folders'
82
+ before 'deploy:server:web_server:configuration', 'deploy:server:web_server:authentification'
83
+ before 'deploy:server:web_server:setup', 'deploy:server:web_server:configuration'
84
+ after 'deploy:server:web_server:setup', 'deploy:server:web_server:finish'
85
+ end
@@ -0,0 +1,100 @@
1
+ server {
2
+ listen <%= nginx.listen_port || 80 %>;
3
+ server_name <%= nginx.application_url.join(' ') %>;
4
+
5
+ <% if nginx.auth_file && nginx.auth_credentials %>
6
+ # Authentification
7
+ auth_basic "Valid user required to access this server";
8
+ auth_basic_user_file <%= nginx.auth_file %>;
9
+ <% end %>
10
+
11
+ <% if nginx.logs_path %>
12
+ access_log <%= nginx.logs_path %>/access.log;
13
+ error_log <%= nginx.logs_path %>/error.log;
14
+ <% end %>
15
+
16
+ root <%= nginx.public_path %>;
17
+
18
+ <% if nginx.indexes.present? %>
19
+ index <%= nginx.indexes.join(' ') %>;
20
+ <% end %>
21
+
22
+ # Enable recursive error pages to catch 405 in a 503 error.
23
+ recursive_error_pages on;
24
+
25
+ # This allows people to use stylesheet, javascript and images in their
26
+ # maintenance html file
27
+ if ($request_filename ~* \.(css|js|jpg|gif|png)$) {
28
+ break;
29
+ }
30
+
31
+ # If the maintenance page exists, throw a 503 error which we'd catch later.
32
+ if (-f $document_root/__system__/maintenance/index.html) {
33
+ return 503;
34
+ }
35
+
36
+ # Catch the 503 error and send it to the @maintenance location
37
+ error_page 503 @maintenance;
38
+
39
+ # The @maintenance location
40
+ location @maintenance {
41
+ # Nginx will refuse POST requests to a static file and will throw a 405 error
42
+ # So we need to catch that and display again our maintenance page
43
+ error_page 405 = /__system__/maintenance/index.html;
44
+
45
+ # Rewrite all the requests to the maintenance page if it exists.
46
+ rewrite ^(.*)$ /__system__/maintenance/index.html break;
47
+ }
48
+
49
+ # Error Pages
50
+ error_page 404 /404.html;
51
+ error_page 500 502 504 /500.html;
52
+
53
+ # Root Location
54
+ location / {
55
+ # this serves static files that exist without running other rewrite tests
56
+ if (-f $request_filename) {
57
+ expires 30d;
58
+ break;
59
+ }
60
+
61
+ <% if nginx.rewrite %>
62
+ # this sends all non-existing file or directory requests to index.php
63
+ if (!-e $request_filename) {
64
+ rewrite ^(.+)$ /index.php?q=$1 last;
65
+ }
66
+ <% end %>
67
+ }
68
+
69
+ <% nginx.denied_access.each do |f| %>
70
+ location ~ <%= Regexp.escape f %> {
71
+ deny all;
72
+ }
73
+ <% end if nginx.denied_access.present? %>
74
+
75
+ location ~ .php$ {
76
+ fastcgi_pass <%= nginx.php_fpm_host %>:<%= nginx.php_fpm_port %>;
77
+ fastcgi_index index.php;
78
+ fastcgi_param SCRIPT_FILENAME <%= nginx.public_path %>$fastcgi_script_name;
79
+
80
+ fastcgi_param QUERY_STRING $query_string;
81
+ fastcgi_param REQUEST_METHOD $request_method;
82
+ fastcgi_param CONTENT_TYPE $content_type;
83
+ fastcgi_param CONTENT_LENGTH $content_length;
84
+
85
+ fastcgi_param SCRIPT_NAME $fastcgi_script_name;
86
+ fastcgi_param REQUEST_URI $request_uri;
87
+ fastcgi_param DOCUMENT_URI $document_uri;
88
+ fastcgi_param DOCUMENT_ROOT $document_root;
89
+ fastcgi_param SERVER_PROTOCOL $server_protocol;
90
+
91
+ fastcgi_param GATEWAY_INTERFACE CGI/1.1;
92
+ fastcgi_param SERVER_SOFTWARE nginx/$nginx_version;
93
+
94
+ fastcgi_param REMOTE_ADDR $remote_addr;
95
+ fastcgi_param REMOTE_PORT $remote_port;
96
+ fastcgi_param SERVER_ADDR $server_addr;
97
+ fastcgi_param SERVER_PORT $server_port;
98
+ fastcgi_param SERVER_NAME $server_name;
99
+ }
100
+ }
metadata ADDED
@@ -0,0 +1,107 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: capistrano-server
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Wael M. Nasreddine
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-07-01 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rake
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: capistrano
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: capistrano-utils
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ description: Capistrano recipes for managing servers
63
+ email:
64
+ - wael.nasreddine@gmail.com
65
+ executables: []
66
+ extensions: []
67
+ extra_rdoc_files: []
68
+ files:
69
+ - .gitignore
70
+ - Gemfile
71
+ - LICENSE
72
+ - README.md
73
+ - Rakefile
74
+ - capistrano-server.gemspec
75
+ - lib/capistrano/ext/nginx.rb
76
+ - lib/capistrano/ext/rsa.rb
77
+ - lib/capistrano/ext/server.rb
78
+ - lib/capistrano/ext/web_server.rb
79
+ - lib/templates/nginx.conf.erb
80
+ homepage: http://technogate.github.com/contao
81
+ licenses: []
82
+ post_install_message:
83
+ rdoc_options: []
84
+ require_paths:
85
+ - lib
86
+ required_ruby_version: !ruby/object:Gem::Requirement
87
+ none: false
88
+ requirements:
89
+ - - ! '>='
90
+ - !ruby/object:Gem::Version
91
+ version: 1.9.2
92
+ required_rubygems_version: !ruby/object:Gem::Requirement
93
+ none: false
94
+ requirements:
95
+ - - ! '>='
96
+ - !ruby/object:Gem::Version
97
+ version: '0'
98
+ segments:
99
+ - 0
100
+ hash: 933416732281928716
101
+ requirements: []
102
+ rubyforge_project:
103
+ rubygems_version: 1.8.23
104
+ signing_key:
105
+ specification_version: 3
106
+ summary: ''
107
+ test_files: []