capserverext 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.
data/History.txt ADDED
@@ -0,0 +1,4 @@
1
+ == 0.0.1 / 2007-03-06
2
+
3
+ * Initial release
4
+
data/Manifest.txt ADDED
@@ -0,0 +1,21 @@
1
+ History.txt
2
+ Manifest.txt
3
+ README.txt
4
+ Rakefile
5
+ lib/cap_server_ext.rb
6
+ lib/nginx
7
+ lib/nginx/recipes.rb
8
+ lib/nginx/recipes
9
+ lib/nginx/recipes/nginx.rb
10
+ lib/nginx/recipes/templates
11
+ lib/nginx/recipes/templates/nginx.conf
12
+ lib/nginx/recipes/templates/nginxvh.conf
13
+ lib/nginx/recipes/resources
14
+ lib/nginx/recipes/resources/nginx
15
+ lib/postgres
16
+ lib/postgres/recipes.rb
17
+ lib/postgres/recipes
18
+ lib/postgres/recipes/postgres.rb
19
+ lib/capserverext
20
+ lib/capserverext/recipes.rb
21
+ test/test_capnginx.rb
data/README.txt ADDED
@@ -0,0 +1,53 @@
1
+ cap_server_ext
2
+ by Saimon Moore
3
+ http://rubyforge.org/projects/capserverext/
4
+
5
+ == DESCRIPTION:
6
+
7
+ Easily setup postgres, mysql databases and the nginx (http://sysoev.ru/nginx/)
8
+ and apache web servers in any combination and on any posix host (ubuntu for now) using capistrano.
9
+
10
+ == FEATURES/PROBLEMS:
11
+
12
+ * install nginx from source/binary
13
+ * setup & configure nginx
14
+ * add init script
15
+ * tasks to start/stop nginx
16
+
17
+ == SYNOPSIS:
18
+
19
+ FIX (code sample of usage)
20
+
21
+ == REQUIREMENTS:
22
+
23
+ * capistrano >= 1.4.0
24
+ * deprec >= 1.3.1
25
+
26
+ == INSTALL:
27
+
28
+ * sudo gem install capnginx
29
+
30
+ == LICENSE:
31
+
32
+ (The MIT License)
33
+
34
+ Copyright (c) 2007 FIX
35
+
36
+ Permission is hereby granted, free of charge, to any person obtaining
37
+ a copy of this software and associated documentation files (the
38
+ 'Software'), to deal in the Software without restriction, including
39
+ without limitation the rights to use, copy, modify, merge, publish,
40
+ distribute, sublicense, and/or sell copies of the Software, and to
41
+ permit persons to whom the Software is furnished to do so, subject to
42
+ the following conditions:
43
+
44
+ The above copyright notice and this permission notice shall be
45
+ included in all copies or substantial portions of the Software.
46
+
47
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
48
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
49
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
50
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
51
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
52
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
53
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile ADDED
@@ -0,0 +1,15 @@
1
+ #:mode=ruby:
2
+
3
+ require 'rubygems'
4
+ require 'hoe'
5
+ require './lib/cap_server_ext.rb'
6
+
7
+ Hoe.new('capserverext', CapistranoServerExtentions::VERSION) do |p|
8
+ p.rubyforge_name = 'capserverext'
9
+ p.author = 'Saimon Moore'
10
+ p.summary = 'Easily setup postgresql & nginx (http://sysoev.ru/nginx/) on ubuntu hosts.'
11
+ p.description = p.paragraphs_of('README.txt', 2..5).join("\n\n")
12
+ p.url = p.paragraphs_of('README.txt', 0).first.split(/\n/)[1..-1]
13
+ p.changes = p.paragraphs_of('History.txt', 0..1).join("\n\n")
14
+ p.extra_deps = [["capistrano", ">= 1.4.0"], ["deprec", ">= 1.3.1"]]
15
+ end
@@ -0,0 +1,3 @@
1
+ class CapistranoServerExtentions
2
+ VERSION = '0.0.1'
3
+ end
@@ -0,0 +1,255 @@
1
+ require 'deprec/recipes'
2
+ require 'nginx/recipes/nginx'
3
+ require 'postgres/recipes/postgres'
4
+
5
+ class Capistrano::CLI
6
+ def self.prompt(msg)
7
+ sync = STDOUT.sync
8
+ begin
9
+ STDOUT.sync = true
10
+ print(msg)
11
+ STDIN.gets.chomp
12
+ ensure
13
+ STDOUT.sync = sync
14
+ puts
15
+ end
16
+ end
17
+ end
18
+
19
+ Capistrano.configuration(:must_exist).load do
20
+
21
+ #Set apt packages combinations
22
+ set :base_rails_ubuntu, {
23
+ :base => %w(build-essential ntp-server wget ruby irb ri rdoc ruby1.8-dev
24
+ libopenssl-ruby zlib1g-dev zlib1g openssl libssl-dev subversion
25
+ subversion-helper-scripts subversion-tools)
26
+ }
27
+
28
+ set :mysql_ubuntu, {
29
+ :base => %w(mysql-server libmysql-ruby)
30
+ }
31
+
32
+ set :postgres_ubuntu, {
33
+ :base => %w(postgresql-8.1 libpgsql-ruby1.8)
34
+ }
35
+
36
+ #Set the different server setup combinations
37
+ set :deprec_combinations, {
38
+ :nginx_postgres => %w(install_rails_stack_nginx_postgres nginx_postgres_rails_setup),
39
+ :nginx_mysql => %w(install_rails_stack_nginx_mysql nginx_mysql_rails_setup),
40
+ :apache_mysql => %w(install_rails_stack_apache_mysql apache_mysql_rails_setup),
41
+ :apache_postgres => %w(install_rails_stack_apache_postgres apache_postgres_rails_setup)
42
+ }
43
+
44
+ #set the nginx_postgres combination by default
45
+ set :deprec_combination, (defined?(deprec_combination) ? deprec_combination : deprec_combinations[:nginx_postgres])
46
+
47
+ #set the new non standard port through which ssh communication will happen
48
+ set :ssh_security_port, (defined?(ssh_security_port) ? ssh_security_port : 8888)
49
+
50
+ desc <<-DESC
51
+ Usage of prepare host task:
52
+ DESC
53
+ task :capserverext_usage do
54
+
55
+ puts <<-EOS
56
+ * rails myproject
57
+ * cd /path/to/myproject
58
+ * deprec --apply-to . --name user --domain myprojectsdomain.com
59
+ * Add following entries to deploy.rb:
60
+
61
+ require 'capserverext/recipes'
62
+ require 'capistrano/ext/monitor'
63
+
64
+ * Edit deploy.rb appropriately:
65
+
66
+ * set deprec_combination to either (:nginx_postgres, :nginx_mysql, :apache_mysql, :apache_postgres)
67
+ for a combination other than the default: ':nginx_postgres'
68
+ * set ssh_options[:security_port] for an ssh port other than the default: '8888'
69
+ * set mongrel options (best to accept the defaults)
70
+ * set repository
71
+ * any other custom options
72
+
73
+ * run: "cap prepare_ssh"
74
+ * set ssh_options[:port] to ssh_options[:security_port] in deploy.rb
75
+ * run: "cap prepare_host"
76
+ EOS
77
+
78
+ end
79
+
80
+ desc <<-DESC
81
+ prepare_host takes a stock standard ubuntu 'dapper' 6.06.1 server
82
+ and installs, compiles, configures everything needed to be a rails machine.
83
+ The combination of web server and database is given by the ':deprec_combination'
84
+ variable (default: nginx_postgres)
85
+ DESC
86
+ task :prepare_host do
87
+ #prepare
88
+ setup_ssh_keys_for_admin_user
89
+
90
+ deprec_combination.each do |task|
91
+ send(task.intern)
92
+ end
93
+ end
94
+
95
+ #############################################################################
96
+
97
+ desc <<-DESC
98
+ Takes a stock standard ubuntu 'dapper' 6.06.1 server
99
+ and installs everything needed to be a rails machine with nginx and postgres db
100
+ DESC
101
+ task :install_rails_stack_nginx_postgres do
102
+ setup_user_perms
103
+ enable_universe # we'll need some packages from the 'universe' repository
104
+ disable_cdrom_install # we don't want to have to insert cdrom
105
+ install_packages_for_rails_postgres # install packages that come with distribution
106
+ install_rubygems
107
+ install_gems
108
+ install_nginx
109
+ end
110
+
111
+ desc <<-DESC
112
+ Takes a stock standard ubuntu 'dapper' 6.06.1 server
113
+ and installs everything needed to be a rails machine with nginx and mysql db
114
+ DESC
115
+ task :install_rails_stack_nginx_mysql do
116
+ setup_user_perms
117
+ enable_universe # we'll need some packages from the 'universe' repository
118
+ disable_cdrom_install # we don't want to have to insert cdrom
119
+ install_packages_for_rails_mysql # install packages that come with distribution
120
+ install_rubygems
121
+ install_gems
122
+ install_nginx
123
+ end
124
+
125
+
126
+ desc <<-DESC
127
+ Takes a stock standard ubuntu 'dapper' 6.06.1 server
128
+ and installs everything needed to be a rails machine with apache and postgres db
129
+ DESC
130
+ task :install_rails_stack_apache_postgres do
131
+ setup_user_perms
132
+ enable_universe # we'll need some packages from the 'universe' repository
133
+ disable_cdrom_install # we don't want to have to insert cdrom
134
+ install_packages_for_rails_postgres # install packages that come with distribution
135
+ install_rubygems
136
+ install_gems
137
+ install_apache
138
+ end
139
+
140
+
141
+ desc <<-DESC
142
+ Takes a stock standard ubuntu 'dapper' 6.06.1 server
143
+ and installs everything needed to be a rails machine with apache and mysql db
144
+ DESC
145
+ task :install_rails_stack_apache_mysql do
146
+ install_rails_stack #default deprec task
147
+ end
148
+
149
+ desc "installs packages required for a rails box with mysql"
150
+ task :install_packages_for_rails_mysql do
151
+ apt.install(base_rails_ubuntu, :stable) # install packages for rails box
152
+ apt.install(mysql_ubuntu, :stable) # install packages for mysql
153
+ end
154
+
155
+ desc "installs packages required for a rails box with postgres"
156
+ task :install_packages_for_rails_postgres do
157
+ apt.install(base_rails_ubuntu, :stable) # install packages for rails box
158
+ apt.install(postgres_ubuntu, :stable) # install packages for postgres
159
+ end
160
+
161
+ desc "Set up the expected application directory structure on all boxes"
162
+ task :nginx_postgres_rails_setup, :except => { :no_release => true } do
163
+ setup_paths
164
+ setup
165
+ setup_nginx_postgres_servers
166
+ end
167
+
168
+ desc "setup and configure servers for nginx and postgres"
169
+ task :setup_nginx_postgres_servers do
170
+ setup_web_for_nginx
171
+ setup_paths
172
+ setup_app
173
+ setup_symlinks
174
+ setup_postgres_db
175
+ end
176
+
177
+ desc "setup and configure servers for nginx and mysql"
178
+ task :setup_nginx_mysql_servers do
179
+ setup_web_for_nginx
180
+ setup_paths
181
+ setup_app
182
+ setup_symlinks
183
+ setup_mysql_db
184
+ end
185
+
186
+ desc "setup and configure servers for apache and postgres"
187
+ task :setup_apache_postgres_servers do
188
+ setup_web
189
+ setup_paths
190
+ setup_app
191
+ setup_symlinks
192
+ setup_postgres_db
193
+ end
194
+
195
+ desc "setup and configure servers for apache and mysql"
196
+ task :setup_apache_mysql_servers do
197
+ setup_web
198
+ setup_paths
199
+ setup_app
200
+ setup_symlinks
201
+ setup_mysql_db
202
+ end
203
+
204
+ desc "Setup nginx web server."
205
+ task :setup_web_for_nginx, :roles => :web do
206
+ set :nginx_server_name, domain unless nginx_server_name
207
+ setup_nginx
208
+ configure_nginx
209
+ end
210
+
211
+ desc "Setup postgres database server."
212
+ task :setup_postgres_db, :roles => :db, :only => { :primary => true } do
213
+ setup_postgres
214
+ end
215
+
216
+ desc "Sets up future ssh connections through a non-standard port given by ssh_security_port (default: 8888)"
217
+ task :prepare_ssh do
218
+ raise "Don't set ssh_options[:port] to anything non-standard" unless (ssh_options[:port].nil? || ssh_options[:port] == 22)
219
+ as_root do |temp_user|
220
+ run_with_input("passwd root", /UNIX password/)
221
+ run "perl -pi -e \'s/Port\s?(22$)/Port #{ssh_security_port}/g\' /etc/ssh/sshd_config"
222
+ run "/etc/init.d/ssh restart"
223
+ end
224
+
225
+ setup_user_account
226
+ puts "Before continuing set ssh_options[:port] in deploy.rb to #{ssh_security_port}"
227
+ end
228
+
229
+ desc "Sets up a unix user admin account. Gives full sudoer privileges to this user.
230
+ This will be the current deployment user."
231
+ task :setup_user_account do
232
+ as_root do |temp_user|
233
+ userid = Capistrano::CLI.prompt("Type a different userid or press enter to accept default userid '#{temp_user}':").strip.chomp
234
+ userid = temp_user if userid.empty?
235
+ puts "Creating account for '#{userid}'"
236
+ deprec.useradd(userid)
237
+ puts "Setting pasword for new account"
238
+ sudo_with_input("passwd #{userid}", /UNIX password/) # ??? how many versions of the prompt are there?
239
+ deprec.groupadd('admin')
240
+ deprec.add_user_to_group(userid, 'admin')
241
+ deprec.append_to_file_if_missing('/etc/sudoers', '%admin ALL=(ALL) ALL')
242
+ puts "Update the user variable in deploy.rb with the new user: #{userid}" unless temp_user == userid
243
+ end
244
+ end
245
+
246
+ # set :user, (defined?(user) ? user : ENV['USER'])
247
+ desc "Copies contents of ssh public keys into authorized_keys file"
248
+ task :setup_ssh_keys_for_admin_user do
249
+ run "test -d ~/.ssh || mkdir ~/.ssh"
250
+ run "chmod 0700 ~/.ssh"
251
+ put(ssh_options[:keys].collect{|key| File.read(key+'.pub')}.join("\n"),
252
+ File.join('/home', user, '.ssh/authorized_keys'),
253
+ :mode => 0600 )
254
+ end
255
+ end
@@ -0,0 +1,18 @@
1
+ require 'postgres/recipes/postgres'
2
+
3
+ Capistrano.configuration(:must_exist).load do
4
+
5
+ desc <<-DESC
6
+ prints usage
7
+ DESC
8
+ task :postgres_usage do
9
+ puts <<-EOS
10
+ Apart from any other installations to get nginx setup on your server
11
+ call the following tasks in order:
12
+ * cap install_nginx
13
+ * cap setup
14
+ * cap configure_nginx
15
+ EOS
16
+ end
17
+
18
+ end
@@ -0,0 +1,162 @@
1
+ require 'open-uri'
2
+
3
+ Capistrano.configuration(:must_exist).load do
4
+
5
+ set :nginx_path, '/usr/local/nginx'
6
+ set :nginx_conf_path, "#{nginx_path}/conf"
7
+ set :nginx_apps_conf_path, "#{nginx_conf_path}/apps"
8
+ set :nginx_log_path, "/var/logs/nginx"
9
+ set :nginx_server_name, nil
10
+ set :nginx_server_port, 80
11
+ set :nginx_ssl_port, 443
12
+ set :nginx_conf, "#{nginx_conf_path}/nginx.conf"
13
+ set :nginx_worker_processes, 2
14
+ set :nginx_ctl, "/etc/init.d/nginx"
15
+ set :nginx_server_aliases, []
16
+ set :nginx_proxy_port, 8090
17
+ set :nginx_proxy_servers, 2
18
+ set :nginx_proxy_address, "127.0.0.1"
19
+ set :nginx_ssl_enabled, false
20
+
21
+
22
+ set :nginx_ubuntu, {
23
+ :base => %w(build-essential wget libgcrypt11-dev libpcre3-dev
24
+ zlib1g-dev zlib1g openssl libssl-dev)
25
+ }
26
+
27
+ desc "installs nginx on a ubuntu box"
28
+ task :install_nginx, :roles => :web do
29
+ install_nginx_prequisites
30
+ compile_nginx
31
+ install_nginx_start_script
32
+ end
33
+
34
+ desc "Sets up required directories for nginx configuration"
35
+ task :setup_nginx, :roles => :web do
36
+ nginx_exists = capture("sudo test -d #{nginx_path} || echo true").chomp != 'true'
37
+ puts 'nginx not installed' unless nginx_exists
38
+ sudo "test -d #{nginx_conf_path} || sudo mkdir -p #{nginx_conf_path}"
39
+ sudo "test -d #{nginx_apps_conf_path} || sudo mkdir -p #{nginx_apps_conf_path}"
40
+ sudo "chgrp #{group} #{nginx_apps_conf_path}"
41
+ sudo "chmod g+w #{nginx_apps_conf_path}"
42
+ end
43
+
44
+ desc "Configure Nginx. Depends on setup_nginx and setup tasks. This uses the :use_sudo
45
+ variable to determine whether to use sudo or not. By default, :use_sudo is
46
+ set to true."
47
+ task :configure_nginx, :roles => :web do
48
+
49
+ setup_nginx_conf
50
+
51
+ #server_aliases = []
52
+ #server_aliases << "www.#{nginx_server_name}"
53
+ #server_aliases.concat nginx_server_aliases
54
+ #set :nginx_server_aliases_array, server_aliases
55
+
56
+ #dummy sudo to get password out of the way
57
+ sudo "echo"
58
+ #sudo_with_input("echo", /UNIX password/)
59
+ nginx_conf_exists = capture("sudo test -s #{nginx_conf} || echo true").chomp != 'true'
60
+ unless nginx_conf_exists
61
+ file = File.join(File.dirname(__FILE__), "templates", "nginx.conf")
62
+ main_config_buffer = render :template => File.read(file)
63
+
64
+ put main_config_buffer, "#{shared_path}/nginx.conf", :mode => 0444
65
+ send(run_method, "cp #{shared_path}/nginx.conf #{nginx_conf}")
66
+ delete "#{shared_path}/nginx.conf"
67
+ end
68
+
69
+ app_conf_exists = capture("sudo test -s #{nginx_apps_conf_path}/#{application}.conf || echo true").chomp != 'true'
70
+ unless app_conf_exists
71
+ file = File.join(File.dirname(__FILE__), "templates", "nginxvh.conf")
72
+ app_config_buffer = render :template => File.read(file)
73
+
74
+ put app_config_buffer, "#{shared_path}/nginx_#{application}.conf", :mode => 0444
75
+ send(run_method, "cp #{shared_path}/nginx_#{application}.conf #{nginx_apps_conf_path}/#{application}.conf")
76
+ delete "#{shared_path}/nginx_#{application}.conf"
77
+
78
+ inc_cmd = "include conf/apps/#{application}.conf;"
79
+ sudo "chmod 766 #{nginx_conf}"
80
+ lines = capture("sudo wc -l #{nginx_conf}").match(/^(\d+)\s/)[1].to_i
81
+ sudo "grep '#{inc_cmd}' #{nginx_conf} || (sudo head -n #{lines - 1} #{nginx_conf} > #{shared_path}/nginx_conf.tmp && cat #{shared_path}/nginx_conf.tmp > #{nginx_conf} && echo -e '\\n #{inc_cmd}\\n}' >> #{nginx_conf})"
82
+ sudo "test -f #{shared_path}/nginx_conf.tmp || rm #{shared_path}/nginx_conf.tmp"
83
+ sudo "chmod 755 #{nginx_conf}"
84
+ end
85
+ end
86
+
87
+ desc "downloads, configures, compiles and installs latest nginx version"
88
+ task :compile_nginx, :roles => :web do
89
+
90
+ sudo "test -d #{nginx_log_path} || sudo mkdir -p #{nginx_log_path}"
91
+
92
+ find_current_nginx_version
93
+ version = "nginx-#{current_nginx_version}"
94
+ set :src_package, {
95
+ :file => version + '.tar.gz',
96
+ :dir => version,
97
+ :url => "http://sysoev.ru/nginx/#{version}.tar.gz",
98
+ :unpack => "tar zxf #{version}.tar.gz;",
99
+ :configure => "./configure --sbin-path=/usr/local/sbin --pid-path=/var/run/nginx.pid --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --with-http_ssl_module;",
100
+ :make => 'make;',
101
+ :install => 'make install;',
102
+ :post_install => "rm #{nginx_conf};"
103
+ }
104
+ deprec.download_src(src_package, src_dir)
105
+ deprec.install_from_src(src_package, src_dir)
106
+ # ubuntu specific - should instead call generic name which can be picked up by different distros
107
+ #send(run_method, "update-rc.d httpd defaults")
108
+ end
109
+
110
+ desc "installs nginx compile prerequisites on a ubuntu box"
111
+ task :install_nginx_prequisites, :roles => :web do
112
+ apt.install(nginx_ubuntu, :stable)
113
+ end
114
+
115
+ desc "Install init script on the web server"
116
+ task :install_nginx_start_script, :roles => :web do
117
+ rc_script = File.read(File.join(File.dirname(__FILE__), 'resources', 'nginx'))
118
+ std.su_put(rc_script, '/etc/init.d/nginx', '/tmp', :mode => 0755)
119
+ send(run_method, "update-rc.d nginx defaults")
120
+ end
121
+
122
+ #init script control tasks
123
+
124
+ desc "Start Nginx "
125
+ task :start_nginx, :roles => :web do
126
+ send(run_method, "#{nginx_ctl} start")
127
+ end
128
+
129
+ desc "Restart Nginx "
130
+ task :restart_nginx, :roles => :web do
131
+ send(run_method, "#{nginx_ctl} restart")
132
+ end
133
+
134
+ desc "Stop Nginx "
135
+ task :stop_nginx, :roles => :web do
136
+ send(run_method, "#{nginx_ctl} stop")
137
+ end
138
+
139
+ desc "Reload Nginx "
140
+ task :reload_nginx, :roles => :web do
141
+ send(run_method, "#{nginx_ctl} reload")
142
+ end
143
+
144
+ def setup_nginx_conf
145
+ set :nginx_server_name, domain unless nginx_server_name
146
+ end
147
+
148
+ #Finds the current nginx version by reading the first line of
149
+ #http://www.nginx.net/CHANGES
150
+ def find_current_nginx_version
151
+ version = nil
152
+ open('http://www.nginx.net/CHANGES') do |f|
153
+ version = f.readline.match(/^Changes\swith\snginx\s([\d\.]+)\s/)[1] rescue nil
154
+ end
155
+ version ||= '0.5.14'
156
+ set :current_nginx_version, version
157
+ rescue
158
+ version = '0.5.14'
159
+ set :current_nginx_version, version
160
+ end
161
+
162
+ end
@@ -0,0 +1,107 @@
1
+ #! /bin/sh
2
+ ### BEGIN INIT INFO
3
+ # Provides: skeleton
4
+ # Required-Start: $local_fs $remote_fs
5
+ # Required-Stop: $local_fs $remote_fs
6
+ # Default-Start: 2 3 4 5
7
+ # Default-Stop: S 0 1 6
8
+ # Short-Description: Example initscript
9
+ # Description: This file should be used to construct scripts to be
10
+ # placed in /etc/init.d.
11
+ ### END INIT INFO
12
+ #
13
+ # Author: Ryan Norbauer <ryan.norbauer@gmail.com>
14
+ #
15
+
16
+ set -e
17
+
18
+ PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
19
+ DESC="nginx daemon"
20
+ NAME=nginx
21
+ DAEMON=/usr/local/sbin/$NAME
22
+ PIDFILE=/var/run/$NAME.pid
23
+ SCRIPTNAME=/etc/init.d/$NAME
24
+
25
+ # Gracefully exit if the package has been removed.
26
+ test -x $DAEMON || exit 0
27
+
28
+ # Read config file if it is present.
29
+ #if [ -r /etc/default/$NAME ]
30
+ #then
31
+ # . /etc/default/$NAME
32
+ #fi
33
+
34
+ #
35
+ # Function that starts the daemon/service.
36
+ #
37
+ d_start() {
38
+ start-stop-daemon --start --quiet --pidfile $PIDFILE \
39
+ --exec $DAEMON \
40
+ || echo -n " already running"
41
+ }
42
+
43
+ #
44
+ # Function that stops the daemon/service.
45
+ #
46
+ d_stop() {
47
+ start-stop-daemon --stop --quiet --pidfile $PIDFILE \
48
+ --name $NAME \
49
+ || echo -n " not running"
50
+ }
51
+
52
+ #
53
+ # Function that sends a SIGHUP to the daemon/service.
54
+ #
55
+ d_reload() {
56
+ start-stop-daemon --stop --quiet --pidfile $PIDFILE \
57
+ --name $NAME --signal 1
58
+ }
59
+
60
+ case "$1" in
61
+ start)
62
+ echo -n "Starting $DESC: $NAME"
63
+ d_start
64
+ echo "."
65
+ ;;
66
+ stop)
67
+ echo -n "Stopping $DESC: $NAME"
68
+ d_stop
69
+ echo "."
70
+ ;;
71
+ #reload)
72
+ #
73
+ # If the daemon can reload its configuration without
74
+ # restarting (for example, when it is sent a SIGHUP),
75
+ # then implement that here.
76
+ #
77
+ # If the daemon responds to changes in its config file
78
+ # directly anyway, make this an "exit 0".
79
+ #
80
+ # echo -n "Reloading $DESC configuration..."
81
+ # d_reload
82
+ # echo "done."
83
+ #;;
84
+ restart|force-reload)
85
+ #
86
+ # If the "reload" option is implemented, move the "force-reload"
87
+ # option to the "reload" entry above. If not, "force-reload" is
88
+ # just the same as "restart".
89
+ #
90
+ echo -n "Restarting $DESC: $NAME"
91
+ d_stop
92
+ # One second might not be time enough for a daemon to stop,
93
+ # if this happens, d_start will fail (and dpkg will break if
94
+ # the package is being upgraded). Change the timeout if needed
95
+ # be, or change d_stop to have start-stop-daemon use --retry.
96
+ # Notice that using --retry slows down the shutdown process somewhat.
97
+ sleep 1
98
+ d_start
99
+ echo "."
100
+ ;;
101
+ *)
102
+ echo "Usage: $SCRIPTNAME {start|stop|restart|force-reload}" >&2
103
+ exit 3
104
+ ;;
105
+ esac
106
+
107
+ exit 0
@@ -0,0 +1,55 @@
1
+ #:mode=apacheconf:
2
+
3
+ # user and group to run as
4
+ #user www-data www-data;
5
+
6
+ # number of nginx workers
7
+ worker_processes <%= nginx_worker_processes%>;
8
+
9
+ # pid of nginx master process
10
+ pid /var/run/nginx.pid;
11
+
12
+ # Number of worker connections. 1024 is a good default
13
+ events {
14
+ worker_connections 1024;
15
+ }
16
+
17
+ # start the http module where we config http access.
18
+ http {
19
+ # pull in mime-types. You can break out your config
20
+ # into as many include's as you want to make it cleaner
21
+ include conf/mime.types;
22
+ # set a default type for the rare situation that
23
+ # nothing matches from the mimie-type include
24
+ default_type application/octet-stream;
25
+
26
+ # configure log format
27
+ log_format main '$remote_addr - $remote_user [$time_local] $status '
28
+ '"$request" $body_bytes_sent "$http_referer" '
29
+ '"$http_user_agent" "$http_x_forwarded_for"';
30
+
31
+ # main access log
32
+ access_log /var/log/nginx/access.log main;
33
+ # main error log
34
+ error_log /var/log/nginx/error.log info;
35
+
36
+ # no sendfile on OSX uncomment
37
+ #this if your on linux or bsd
38
+ #sendfile on;
39
+
40
+ # These are good default values.
41
+ tcp_nopush on;
42
+ keepalive_timeout 65;
43
+ tcp_nodelay on;
44
+
45
+ # output compression saves bandwidth
46
+ gzip on;
47
+ gzip_comp_level 2;
48
+ gzip_min_length 1100;
49
+ gzip_buffers 4 8k;
50
+ #gzip_proxied any;
51
+ gzip_types text/plain text/html text/css application/x-javascript text/xml application/xml application/xml+rss text/javascript;
52
+
53
+ #server_names_hash_bucket_size 32/64/128
54
+ server_names_hash_bucket_size 64;
55
+
@@ -0,0 +1,156 @@
1
+ # this is where you define your mongrel clusters.
2
+ # you need one of these blocks for each cluster
3
+ # and each one needs its own name to refer to it later.
4
+ # To determine how many mongrels are necessary follow:
5
+ # http://mongrel.rubyforge.org/docs/how_many_mongrels.html
6
+ upstream mongrel_<%= application %> {
7
+ <% port = nginx_proxy_port %>
8
+ <% nginx_proxy_servers.times do %>
9
+ server <%= nginx_proxy_address%>:<%= port %>;
10
+ <% port += 1 %>
11
+ <% end %>
12
+ }
13
+
14
+ #vhost for www.<%= domain %>
15
+ server {
16
+ listen <%= nginx_server_port %>;
17
+
18
+ server_name www.<%= domain %>;
19
+
20
+ root <%= deploy_to %>/current/public;
21
+
22
+ access_log /var/log/nginx/<%= application %>.access.log main;
23
+ error_log /var/log/nginx/<%= application %>.error.log info;
24
+
25
+ rewrite_log on;
26
+
27
+ <% if nginx_ssl_enabled %>
28
+ listen <%= nginx_ssl_port%>;
29
+ ssl on;
30
+ ssl_certificate <%= nginx_apps_conf_path %>/<%= application %>.pem;
31
+ ssl_certificate_key <%= nginx_apps_conf_path %>/<%= application %>.key;
32
+ keepalive_timeout 70;
33
+ <% end %>
34
+
35
+ if (-f $document_root/maintenance.html){
36
+ rewrite ^(.*)$ /maintenance.html last;
37
+ break;
38
+ }
39
+
40
+ location /index2 {
41
+ rewrite (.*) / permanent;
42
+ }
43
+
44
+ location / {
45
+ proxy_set_header X-Real-IP $remote_addr;
46
+ proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
47
+ proxy_set_header Host $http_host;
48
+ proxy_redirect false;
49
+
50
+ # If the file exists as a static file serve it directly without
51
+ # running all the other rewite tests on it
52
+ if (-f $request_filename) {
53
+ break;
54
+ }
55
+
56
+ # check for index.html for directory index
57
+ # if its there on the filesystem then rewite
58
+ # the url to add /index.html to the end of it
59
+ # and then break to send it to the next config rules.
60
+ if (-f $request_filename/index.html) {
61
+ rewrite (.*) $1/index.html break;
62
+ }
63
+
64
+ # this is the meat of the rails page caching config
65
+ # it adds .html to the end of the url and then checks
66
+ # the filesystem for that file. If it exists, then we
67
+ # rewite the url to have explicit .html on the end
68
+ # and then send it on its way to the next config rule.
69
+ # if there is no file on the fs then it sets all the
70
+ # necessary headers and proxies to our upstream mongrels
71
+ if (-f $request_filename.html) {
72
+ rewrite (.*) $1.html break;
73
+ }
74
+
75
+ if (!-f $request_filename) {
76
+ proxy_pass http://mongrel_<%= application %>;
77
+ break;
78
+ }
79
+ }
80
+ }
81
+
82
+ #vhost for <%= domain %>
83
+ server {
84
+ listen <%= nginx_server_port %>;
85
+
86
+ server_name <%= domain %>;
87
+
88
+ root <%= deploy_to %>/current/public;
89
+
90
+ access_log /var/log/nginx/<%= application %>.access.log main;
91
+ error_log /var/log/nginx/<%= application %>.error.log info;
92
+
93
+ rewrite_log on;
94
+
95
+ <% if nginx_ssl_enabled %>
96
+ listen <%= nginx_ssl_port%>;
97
+ ssl on;
98
+ ssl_certificate <%= nginx_apps_conf_path %>/<%= application %>.pem;
99
+ ssl_certificate_key <%= nginx_apps_conf_path %>/<%= application %>.key;
100
+ keepalive_timeout 70;
101
+ <% end %>
102
+
103
+ if (-f $document_root/maintenance.html){
104
+ rewrite ^(.*)$ /maintenance.html last;
105
+ break;
106
+ }
107
+
108
+ location /index2 {
109
+ rewrite (.*) / permanent;
110
+ }
111
+
112
+ location / {
113
+ proxy_set_header X-Real-IP $remote_addr;
114
+ proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
115
+ proxy_set_header Host $http_host;
116
+ proxy_redirect false;
117
+
118
+ # If the file exists as a static file serve it directly without
119
+ # running all the other rewite tests on it
120
+ if (-f $request_filename) {
121
+ break;
122
+ }
123
+
124
+ # check for index.html for directory index
125
+ # if its there on the filesystem then rewite
126
+ # the url to add /index.html to the end of it
127
+ # and then break to send it to the next config rules.
128
+ if (-f $request_filename/index.html) {
129
+ rewrite (.*) $1/index.html break;
130
+ }
131
+
132
+ # this is the meat of the rails page caching config
133
+ # it adds .html to the end of the url and then checks
134
+ # the filesystem for that file. If it exists, then we
135
+ # rewite the url to have explicit .html on the end
136
+ # and then send it on its way to the next config rule.
137
+ # if there is no file on the fs then it sets all the
138
+ # necessary headers and proxies to our upstream mongrels
139
+ if (-f $request_filename.html) {
140
+ rewrite (.*) $1.html break;
141
+ }
142
+
143
+ if (!-f $request_filename) {
144
+ proxy_pass http://mongrel_<%= application %>;
145
+ break;
146
+ }
147
+ }
148
+ }
149
+
150
+ #Any other subdomain is redirected to www
151
+ server {
152
+ listen 80;
153
+
154
+ server_name wwww.<%= domain %> *.<%= domain %>;
155
+ rewrite ^(.*) http://www.<%= domain %>$1 permanent;
156
+ }
@@ -0,0 +1,18 @@
1
+ require 'nginx/recipes/nginx'
2
+
3
+ Capistrano.configuration(:must_exist).load do
4
+
5
+ desc <<-DESC
6
+ prints usage
7
+ DESC
8
+ task :nginx_usage do
9
+ puts <<-EOS
10
+ Apart from any other installations to get nginx setup on your server
11
+ call the following tasks in order:
12
+ * cap install_nginx
13
+ * cap setup
14
+ * cap configure_nginx
15
+ EOS
16
+ end
17
+
18
+ end
@@ -0,0 +1,56 @@
1
+ require 'yaml'
2
+ require 'capistrano'
3
+ require 'capistrano/cli'
4
+
5
+ module PostgreSQLMethods
6
+
7
+ def execute(sql, user)
8
+ run_with_input "echo '#{sql}' | sudo su - #{user} psql"
9
+ end
10
+
11
+ def handle_postgres_password(user, channel, stream, data)
12
+ logger.info data, "[database on #{channel[:host]} asked for password]"
13
+ if data =~ /^Password for user #{user}:/
14
+ pass = Capistrano::CLI.password_prompt "Enter database password for '#{user}':"
15
+ channel.send_data "#{pass}\n"
16
+ end
17
+ end
18
+ end
19
+
20
+ Capistrano.plugin :postgresql, PostgreSQLMethods
21
+
22
+ Capistrano.configuration(:must_exist).load do
23
+
24
+ set :postgres_admin, 'postgres'
25
+
26
+ desc "Execute PostgreSQL statements using --command option. Set the 'sql' variable."
27
+ task :execute_postgres, :roles => :db, :only => { :primary => true } do
28
+ set_postgres_admin
29
+ postgresql.execute sql, mysql_admin
30
+ end
31
+
32
+ desc "Create PostgreSQL database and user based on config/database.yml"
33
+ task :setup_postgres, :roles => :db, :only => { :primary => true } do
34
+ # on_rollback {}
35
+
36
+ set_postgres_admin
37
+ read_config
38
+
39
+ sql = "CREATE USER #{db_user} WITH PASSWORD '\\''#{db_password}'\\'';"
40
+ sql += "CREATE DATABASE #{db_name} ENCODING = '\\''UTF8'\\'';"
41
+ sql += %Q( GRANT ALL PRIVILEGES ON DATABASE #{db_name} TO #{db_user};)
42
+ postgresql.execute sql, postgres_admin
43
+ end
44
+
45
+ def read_config
46
+ db_config = YAML.load_file('config/database.yml')
47
+ set :db_user, db_config[rails_env]["username"]
48
+ set :db_password, db_config[rails_env]["password"]
49
+ set :db_name, db_config[rails_env]["database"]
50
+ end
51
+
52
+ def set_postgres_admin
53
+ set :postgres_admin, 'postgres' unless postgres_admin
54
+ end
55
+
56
+ end
File without changes
metadata ADDED
@@ -0,0 +1,92 @@
1
+ --- !ruby/object:Gem::Specification
2
+ rubygems_version: 0.9.0
3
+ specification_version: 1
4
+ name: capserverext
5
+ version: !ruby/object:Gem::Version
6
+ version: 0.0.1
7
+ date: 2007-03-15 00:00:00 +00:00
8
+ summary: Easily setup postgresql & nginx (http://sysoev.ru/nginx/) on ubuntu hosts.
9
+ require_paths:
10
+ - lib
11
+ email: ryand-ruby@zenspider.com
12
+ homepage: " by Saimon Moore"
13
+ rubyforge_project: capserverext
14
+ description: "Easily setup postgres, mysql databases and the nginx (http://sysoev.ru/nginx/) and apache web servers in any combination and on any posix host (ubuntu for now) using capistrano. == FEATURES/PROBLEMS: * install nginx from source/binary * setup & configure nginx * add init script * tasks to start/stop nginx == SYNOPSIS:"
15
+ autorequire:
16
+ default_executable:
17
+ bindir: bin
18
+ has_rdoc: true
19
+ required_ruby_version: !ruby/object:Gem::Version::Requirement
20
+ requirements:
21
+ - - ">"
22
+ - !ruby/object:Gem::Version
23
+ version: 0.0.0
24
+ version:
25
+ platform: ruby
26
+ signing_key:
27
+ cert_chain:
28
+ post_install_message:
29
+ authors:
30
+ - Saimon Moore
31
+ files:
32
+ - History.txt
33
+ - Manifest.txt
34
+ - README.txt
35
+ - Rakefile
36
+ - lib/cap_server_ext.rb
37
+ - lib/nginx
38
+ - lib/nginx/recipes.rb
39
+ - lib/nginx/recipes
40
+ - lib/nginx/recipes/nginx.rb
41
+ - lib/nginx/recipes/templates
42
+ - lib/nginx/recipes/templates/nginx.conf
43
+ - lib/nginx/recipes/templates/nginxvh.conf
44
+ - lib/nginx/recipes/resources
45
+ - lib/nginx/recipes/resources/nginx
46
+ - lib/postgres
47
+ - lib/postgres/recipes.rb
48
+ - lib/postgres/recipes
49
+ - lib/postgres/recipes/postgres.rb
50
+ - lib/capserverext
51
+ - lib/capserverext/recipes.rb
52
+ - test/test_capnginx.rb
53
+ test_files:
54
+ - test/test_capnginx.rb
55
+ rdoc_options: []
56
+
57
+ extra_rdoc_files: []
58
+
59
+ executables: []
60
+
61
+ extensions: []
62
+
63
+ requirements: []
64
+
65
+ dependencies:
66
+ - !ruby/object:Gem::Dependency
67
+ name: capistrano
68
+ version_requirement:
69
+ version_requirements: !ruby/object:Gem::Version::Requirement
70
+ requirements:
71
+ - - ">="
72
+ - !ruby/object:Gem::Version
73
+ version: 1.4.0
74
+ version:
75
+ - !ruby/object:Gem::Dependency
76
+ name: deprec
77
+ version_requirement:
78
+ version_requirements: !ruby/object:Gem::Version::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: 1.3.1
83
+ version:
84
+ - !ruby/object:Gem::Dependency
85
+ name: hoe
86
+ version_requirement:
87
+ version_requirements: !ruby/object:Gem::Version::Requirement
88
+ requirements:
89
+ - - ">="
90
+ - !ruby/object:Gem::Version
91
+ version: 1.2.0
92
+ version: