brightbox-server-tools 2.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,85 @@
1
+ #!/usr/bin/env ruby
2
+ # Brightbox - Easy Ruby Web Application Deployment
3
+ # Copyright (C) 2008, Neil Wilson, Brightbox Systems
4
+ #
5
+ # This file is part of the Brightbox @application system
6
+ #
7
+ # Brightbox gem is free software: you can redistribute it and/or modify it
8
+ # under the terms of the GNU Affero General Public License as published
9
+ # by the Free Software Foundation, either version 3 of the License,
10
+ # or (at your option) any later version.
11
+ #
12
+ # This program is distributed in the hope that it will be useful,
13
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15
+ # Affero General Public License for more details.
16
+ #
17
+ # You should have received a copy of the GNU Affero General
18
+ # Public License along with this program. If not, see
19
+ # <http://www.gnu.org/licenses/>.
20
+ #
21
+
22
+
23
+ WEBSERVER='nginx'
24
+ require 'brightbox/webserver-common'
25
+
26
+
27
+ def http_config
28
+ <<-EOT
29
+ #{config_time_stamp}
30
+ upstream #{@application}_mongrels {
31
+ fair;
32
+ # List of mongrels
33
+ #{balancer_members}
34
+ }
35
+ server {
36
+ server_name #{@domain} #{local_app_alias} #{@aliases};
37
+ root #{@webroot};
38
+ access_log /var/log/web/#{@application}.log main;
39
+
40
+ # Capistrano maintenance message support
41
+ if (-f $document_root/system/maintenance.html) {
42
+ rewrite ^(.*)$ /system/maintenance.html last;
43
+ break;
44
+ }
45
+
46
+ location / {
47
+ ## General Rails error page stuff
48
+ error_page 404 /404.html;
49
+ error_page 422 /422.html;
50
+ error_page 500 502 503 504 /500.html;
51
+ error_page 403 /403.html;
52
+
53
+ # If the file exists then stop here. Saves 4 more stats and some
54
+ # rewrites.
55
+ if (-f $request_filename) {
56
+ break;
57
+ }
58
+ # Rails page caching
59
+ if (-f $request_filename/index.html) {
60
+ rewrite (.*) $1/index.html break;
61
+ }
62
+ if (-f $request_filename.html) {
63
+ rewrite (.*) $1.html break;
64
+ }
65
+ # If it hasn't been handled above, and isn't a static file
66
+ # then send to the mongrels
67
+ if (!-f $request_filename) {
68
+ proxy_pass http://#{@application}_mongrels;
69
+ }
70
+ }
71
+ }
72
+ EOT
73
+ end
74
+
75
+ def balancer_members
76
+ (@port..@port+@mongrels-1).collect do |i|
77
+ " server #{@mongrelhost}:#{i};"
78
+ end.join("\n")
79
+ end
80
+
81
+ #MAIN PROGRAM
82
+
83
+ #Create a normal HTTP config
84
+ @config=http_config
85
+ configure_site(@application)
@@ -0,0 +1,46 @@
1
+ # Brightbox - Easy Ruby Web Application Deployment
2
+ # Copyright (C) 2008, Neil Wilson, Brightbox Systems
3
+ #
4
+ # This file is part of the Brightbox deployment system
5
+ #
6
+ # Brightbox gem is free software: you can redistribute it and/or modify it
7
+ # under the terms of the GNU Affero General Public License as published
8
+ # by the Free Software Foundation, either version 3 of the License,
9
+ # or (at your option) any later version.
10
+ #
11
+ # This program is distributed in the hope that it will be useful,
12
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14
+ # Affero General Public License for more details.
15
+ #
16
+ # You should have received a copy of the GNU Affero General
17
+ # Public License along with this program. If not, see
18
+ # <http://www.gnu.org/licenses/>.
19
+ #
20
+ require File.join(File.dirname(__FILE__),"lib/brightbox/version")
21
+ def add_common(spec)
22
+ spec.version = Brightbox::VERSION
23
+ spec.authors = ["John Leach","Neil Wilson"]
24
+ spec.email = "support@brightbox.co.uk"
25
+ spec.homepage = "http://wiki.brightbox.co.uk/docs:thebrightboxgem"
26
+ spec.rubyforge_project = 'brightbox'
27
+ spec.has_rdoc = false
28
+ end
29
+
30
+ @server = Gem::Specification.new do |s|
31
+ add_common(s)
32
+ s.name = "brightbox-server-tools"
33
+ s.files = FileList["LICENSE", "Rakefile", "*.rb", "bin/railsapp-*","{lib,spec}/**/*.rb"].exclude(/recipe/).to_a
34
+ s.summary = "Brightbox Server configuration scripts"
35
+ s.executables = FileList["bin/railsapp-*"].sub(/bin\//,'')
36
+ end
37
+
38
+ @client = Gem::Specification.new do |s|
39
+ add_common(s)
40
+ s.name = "brightbox"
41
+ s.files = FileList["LICENSE", "Rakefile", "*.rb", "lib/**/*.rb","bin/brightbox"].exclude("lib/brightbox/webserver-common.rb").to_a
42
+ s.add_dependency("capistrano", ">= 2.3")
43
+ s.summary = "Brightbox rails deployment scripts for Capistrano"
44
+ s.executable = 'brightbox'
45
+ end
46
+
@@ -0,0 +1,3 @@
1
+ module Brightbox
2
+ VERSION = "2.0.1"
3
+ end
@@ -0,0 +1,153 @@
1
+ # Brightbox - Easy Ruby Web Application Deployment
2
+ # Copyright (C) 2008, Neil Wilson, Brightbox Systems
3
+ #
4
+ # This file is part of the Brightbox deployment system
5
+ #
6
+ # Brightbox gem is free software: you can redistribute it and/or modify it
7
+ # under the terms of the GNU Affero General Public License as published
8
+ # by the Free Software Foundation, either version 3 of the License,
9
+ # or (at your option) any later version.
10
+ #
11
+ # This program is distributed in the hope that it will be useful,
12
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14
+ # Affero General Public License for more details.
15
+ #
16
+ # You should have received a copy of the GNU Affero General
17
+ # Public License along with this program. If not, see
18
+ # <http://www.gnu.org/licenses/>.
19
+ #
20
+
21
+ require 'rubygems'
22
+ require 'optparse'
23
+ require 'fileutils'
24
+
25
+ @mongrelhost = "127.0.0.1"
26
+ @mongrels = 2
27
+ @aliases = nil
28
+ @certificate = nil
29
+ @key_file = nil
30
+ @app_name = File.basename $0
31
+
32
+ def has_required_options?
33
+ [@application, @webroot, @domain, @port].all? &&
34
+ (@certificate || @certificate_key.nil?)
35
+ end
36
+
37
+ def certificate_file
38
+ return @certificate if File.file?(@certificate)
39
+ cert_base = File.basename(@certificate, File.extname(@certificate))
40
+ test_path = File.join('','etc','ssl','certs', cert_base + '.*')
41
+ candidates = Dir[test_path]
42
+ if candidates.empty?
43
+ abort "#{@app_name}: Unable to find certificate file for #{@cert_base}"
44
+ end
45
+ result = candidates.pop
46
+ unless candidates.empty?
47
+ abort "#{@app_name}: #{@cert_base} resolves to more than one file. Please be more specific"
48
+ end
49
+ result
50
+ end
51
+
52
+ def key_file
53
+ if @certificate_key
54
+ return @certificate_key if File.file?(@certificate_key)
55
+ key_base = File.basename(@certificate_key, File.extname(@certificate_key))
56
+ else
57
+ key_base = File.basename(@certificate, File.extname(@certificate))
58
+ end
59
+ test_path = File.join('','etc','ssl','private', key_base + '.*')
60
+ candidates = Dir[test_path]
61
+ return nil if candidates.empty?
62
+ result = candidates.pop
63
+ unless candidates.empty?
64
+ abort "#{@app_name}: #{key_base} resolves to more than one file. Please be more specific"
65
+ end
66
+ result
67
+ end
68
+
69
+ OptionParser.new do |opts|
70
+ opts.banner = "#{@app_name} creates an #{WEBSERVER} config for a Rails app\n"
71
+ opts.banner << "Usage: #{@app_name} [options] [args]"
72
+
73
+ opts.on("-n APPLICATION_NAME", "--name APPLICATION_NAME",
74
+ "Name of application (a short useful name for the app such as 'myforum')"
75
+ ) { |value| @application = value }
76
+
77
+ opts.on("-w", "--webroot WEB_ROOT",
78
+ "Full path to web root (e.g: /home/rails/myforum/current/public)"
79
+ ) { |value| @webroot = value }
80
+
81
+ opts.on("-d", "--domain DOMAIN_NAME",
82
+ "Domain name for application (e.g: www.example.com)"
83
+ ) { |value| @domain = value }
84
+
85
+ opts.on("-a", "--aliases ALIASES",
86
+ "Aliases for domain name, comma separated (e.g: www.example.org,www.example.net)"
87
+ ) { |value| @aliases = value.to_s.split(',').join(' ')}
88
+
89
+ opts.on("-p", "--port MONGREL_PORT", Integer,
90
+ "Port of the first mongrel service"
91
+ ) { |value| @port = value.to_i }
92
+
93
+ opts.on("-s", "--servers MONGRELS", Integer,
94
+ "Number of mongrel servers running (default: #{@mongrels})"
95
+ ) { |value| @mongrels = value.to_i }
96
+
97
+ opts.on("-h", "--mongrelhost MONGREL_HOST",
98
+ "ip/host where mongrel is running (default: #{@mongrelhost})"
99
+ ) { |value| @mongrelhost = value }
100
+
101
+ opts.on("-c", "--ssl-cert CERTIFICATE_NAME",
102
+ "create an SSL configuration using CERTIFICATE_NAME"
103
+ ) { |value| @certificate = value }
104
+
105
+ opts.on("-k", "--ssl-key KEY_NAME",
106
+ "Name of private key to use CERTIFICATE"
107
+ ) { |value| @certificate_key = value }
108
+
109
+ begin
110
+ opts.parse(ARGV)
111
+ raise OptionParser::ParseError,
112
+ "You must supply the required arguments" unless has_required_options?
113
+ rescue OptionParser::ParseError => e
114
+ warn e.message
115
+ puts opts
116
+ exit 1
117
+ end
118
+ if @certificate
119
+ @certificate_file = certificate_file
120
+ @key_file = key_file
121
+ end
122
+ end
123
+
124
+ def configure_site(site_name)
125
+ webserver_config = File.join('','etc', WEBSERVER)
126
+ appfile = "rails-#{site_name}"
127
+
128
+ sites_available = File.join(webserver_config, 'sites-available')
129
+ sites_enabled = sites_available.sub("available", "enabled")
130
+ sites_archived = sites_available.sub("available", "archived")
131
+
132
+ filename = File.join(sites_available, appfile)
133
+ archivefile = File.join(sites_archived, appfile + "." + Time.now.strftime('%y%m%d%H%M%S'))
134
+ enablelink = File.join(sites_enabled, appfile)
135
+ FileUtils.mkdir_p(sites_available)
136
+ FileUtils.mkdir_p(sites_enabled)
137
+
138
+ if File.exists?(filename)
139
+ FileUtils.mkdir_p(sites_archived)
140
+ FileUtils.cp filename, archivefile
141
+ end
142
+
143
+ File.open(filename, "w") { |f| f.write @config }
144
+ FileUtils.ln_s(filename, enablelink, :force => true)
145
+ end
146
+
147
+ def config_time_stamp
148
+ "# Created by #{@app_name} at #{Time.now}"
149
+ end
150
+
151
+ def local_app_alias
152
+ @local_app_alias ||= @application+"."+`hostname`.chomp
153
+ end
metadata ADDED
@@ -0,0 +1,67 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: brightbox-server-tools
3
+ version: !ruby/object:Gem::Version
4
+ version: 2.0.1
5
+ platform: ruby
6
+ authors:
7
+ - John Leach
8
+ - Neil Wilson
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+
13
+ date: 2008-06-10 00:00:00 +01:00
14
+ default_executable:
15
+ dependencies: []
16
+
17
+ description:
18
+ email: support@brightbox.co.uk
19
+ executables:
20
+ - railsapp-nginx
21
+ - railsapp-apache
22
+ - railsapp-logrotate
23
+ - railsapp-monit
24
+ - railsapp-mongrel
25
+ extensions: []
26
+
27
+ extra_rdoc_files: []
28
+
29
+ files:
30
+ - LICENSE
31
+ - Rakefile
32
+ - brightbox-gemspec.rb
33
+ - bin/railsapp-nginx
34
+ - bin/railsapp-apache
35
+ - bin/railsapp-logrotate
36
+ - bin/railsapp-monit
37
+ - bin/railsapp-mongrel
38
+ - lib/brightbox/version.rb
39
+ - lib/brightbox/webserver-common.rb
40
+ has_rdoc: false
41
+ homepage: http://wiki.brightbox.co.uk/docs:thebrightboxgem
42
+ post_install_message:
43
+ rdoc_options: []
44
+
45
+ require_paths:
46
+ - lib
47
+ required_ruby_version: !ruby/object:Gem::Requirement
48
+ requirements:
49
+ - - ">="
50
+ - !ruby/object:Gem::Version
51
+ version: "0"
52
+ version:
53
+ required_rubygems_version: !ruby/object:Gem::Requirement
54
+ requirements:
55
+ - - ">="
56
+ - !ruby/object:Gem::Version
57
+ version: "0"
58
+ version:
59
+ requirements: []
60
+
61
+ rubyforge_project: brightbox
62
+ rubygems_version: 1.1.1
63
+ signing_key:
64
+ specification_version: 2
65
+ summary: Brightbox Server configuration scripts
66
+ test_files: []
67
+