winton-cookbook 1.0.0

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.
@@ -0,0 +1,137 @@
1
+ #
2
+ # The MySQL database server configuration file.
3
+ #
4
+ # You can copy this to one of:
5
+ # - "/etc/mysql/my.cnf" to set global options,
6
+ # - "~/.my.cnf" to set user-specific options.
7
+ #
8
+ # One can use all long options that the program supports.
9
+ # Run program with --help to get a list of available options and with
10
+ # --print-defaults to see which it would actually understand and use.
11
+ #
12
+ # For explanations see
13
+ # http://dev.mysql.com/doc/mysql/en/server-system-variables.html
14
+
15
+ # This will be passed to all mysql clients
16
+ # It has been reported that passwords should be enclosed with ticks/quotes
17
+ # escpecially if they contain "#" chars...
18
+ # Remember to edit /etc/mysql/debian.cnf when changing the socket location.
19
+ [client]
20
+ port = 3306
21
+ socket = /var/run/mysqld/mysqld.sock
22
+
23
+ # Here is entries for some specific programs
24
+ # The following values assume you have at least 32M ram
25
+
26
+ # This was formally known as [safe_mysqld]. Both versions are currently parsed.
27
+ [mysqld_safe]
28
+ socket = /var/run/mysqld/mysqld.sock
29
+ nice = 0
30
+
31
+ [mysqld]
32
+ #
33
+ # * Basic Settings
34
+ #
35
+ user = mysql
36
+ pid-file = /var/run/mysqld/mysqld.pid
37
+ socket = /var/run/mysqld/mysqld.sock
38
+ port = 3306
39
+ basedir = /usr
40
+ datadir = /var/lib/mysql
41
+ tmpdir = /tmp
42
+ language = /usr/share/mysql/english
43
+ skip-external-locking
44
+ #
45
+ # Instead of skip-networking the default is now to listen only on
46
+ # localhost which is more compatible and is not less secure.
47
+ bind-address = 127.0.0.1
48
+ #
49
+ # * Fine Tuning
50
+ #
51
+ key_buffer = 256M
52
+ max_allowed_packet = 16M
53
+ thread_stack = 128K
54
+ thread_cache_size = 8
55
+ max_connections = 500
56
+ table_cache = 1536
57
+ #thread_concurrency = 10
58
+ #
59
+ # * Query Cache Configuration
60
+ #
61
+ query_cache_limit = 1M
62
+ query_cache_size = 16M
63
+ #
64
+ # * Logging and Replication
65
+ #
66
+ # Both location gets rotated by the cronjob.
67
+ # Be aware that this log type is a performance killer.
68
+ #log = /var/log/mysql/mysql.log
69
+ #
70
+ # Error logging goes to syslog. This is a Debian improvement :)
71
+ #
72
+ # Here you can see queries with especially long duration
73
+ #log_slow_queries = /var/log/mysql/mysql-slow.log
74
+ #long_query_time = 2
75
+ #log-queries-not-using-indexes
76
+ #
77
+ # The following can be used as easy to replay backup logs or for replication.
78
+ #server-id = 1
79
+ log_bin = /var/log/mysql/mysql-bin.log
80
+ # WARNING: Using expire_logs_days without bin_log crashes the server! See README.Debian!
81
+ expire_logs_days = 10
82
+ max_binlog_size = 100M
83
+ #binlog_do_db = include_database_name
84
+ #binlog_ignore_db = include_database_name
85
+ #
86
+ # * BerkeleyDB
87
+ #
88
+ # Using BerkeleyDB is now discouraged as its support will cease in 5.1.12.
89
+ skip-bdb
90
+ #
91
+ # * InnoDB
92
+ #
93
+ # InnoDB is enabled by default with a 10MB datafile in /var/lib/mysql/.
94
+ # Read the manual for more InnoDB related options. There are many!
95
+ # You might want to disable InnoDB to shrink the mysqld process by circa 100MB.
96
+ skip-innodb
97
+ #
98
+ # * Security Features
99
+ #
100
+ # Read the manual, too, if you want chroot!
101
+ # chroot = /var/lib/mysql/
102
+ #
103
+ # For generating SSL certificates I recommend the OpenSSL GUI "tinyca".
104
+ #
105
+ # ssl-ca=/etc/mysql/cacert.pem
106
+ # ssl-cert=/etc/mysql/server-cert.pem
107
+ # ssl-key=/etc/mysql/server-key.pem
108
+
109
+
110
+
111
+ [mysqldump]
112
+ quick
113
+ quote-names
114
+ max_allowed_packet = 16M
115
+
116
+ [mysql]
117
+ #no-auto-rehash # faster start of mysql but no tab completition
118
+
119
+ [isamchk]
120
+ key_buffer = 16M
121
+
122
+ #
123
+ # * NDB Cluster
124
+ #
125
+ # See /usr/share/doc/mysql-server-*/README.Debian for more information.
126
+ #
127
+ # The following configuration is read by the NDB Data Nodes (ndbd processes)
128
+ # not from the NDB Management Nodes (ndb_mgmd processes).
129
+ #
130
+ # [MYSQL_CLUSTER]
131
+ # ndb-connectstring=127.0.0.1
132
+
133
+
134
+ #
135
+ # * IMPORTANT: Additional settings that can override those from this file!
136
+ #
137
+ !includedir /etc/mysql/conf.d/
@@ -0,0 +1,30 @@
1
+ worker_processes 3;
2
+
3
+ events {
4
+ worker_connections 1024;
5
+ }
6
+
7
+ http {
8
+ default_type application/octet-stream;
9
+
10
+ sendfile on;
11
+ tcp_nopush on;
12
+ tcp_nodelay off;
13
+
14
+ keepalive_timeout 65;
15
+
16
+ gzip on;
17
+ gzip_http_version 1.0;
18
+ gzip_comp_level 2;
19
+ gzip_proxied any;
20
+ gzip_types text/plain text/html text/css application/x-javascript text/xml
21
+ application/xml application/xml+rss text/javascript;
22
+
23
+ log_format main '$remote_addr - $remote_user [$time_local] $request '
24
+ '"$status" $body_bytes_sent "$http_referer" '
25
+ '"$http_user_agent" "$http_x_forwarded_for"';
26
+
27
+ include mime.types;
28
+ include fastcgi_params;
29
+ include vhosts/*.conf;
30
+ }
@@ -0,0 +1,57 @@
1
+ #! /bin/sh
2
+
3
+ ### BEGIN INIT INFO
4
+ # Provides: nginx
5
+ # Required-Start: $all
6
+ # Required-Stop: $all
7
+ # Default-Start: 2 3 4 5
8
+ # Default-Stop: 0 1 6
9
+ # Short-Description: starts the nginx web server
10
+ # Description: starts nginx using start-stop-daemon
11
+ ### END INIT INFO
12
+
13
+ PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
14
+ DAEMON=/usr/local/sbin/nginx
15
+ NAME=nginx
16
+ DESC=nginx
17
+
18
+ test -x $DAEMON || exit 0
19
+ set -e
20
+
21
+ case "$1" in
22
+ start)
23
+ echo -n "Starting $DESC: "
24
+ start-stop-daemon --start --quiet --pidfile /usr/local/nginx/logs/$NAME.pid \
25
+ --exec $DAEMON -- $DAEMON_OPTS
26
+ echo "$NAME started."
27
+ ;;
28
+ stop)
29
+ echo -n "Stopping $DESC: "
30
+ start-stop-daemon --stop --quiet --pidfile /usr/local/nginx/logs/$NAME.pid \
31
+ --exec $DAEMON
32
+ echo "$NAME stopped."
33
+ ;;
34
+
35
+ restart|force-reload)
36
+ echo -n "Restarting $DESC: "
37
+ start-stop-daemon --stop --quiet --pidfile \
38
+ /usr/local/nginx/logs/$NAME.pid --exec $DAEMON
39
+ sleep 1
40
+ start-stop-daemon --start --quiet --pidfile \
41
+ /usr/local/nginx/logs/$NAME.pid --exec $DAEMON -- $DAEMON_OPTS
42
+ echo "$NAME restarted."
43
+ ;;
44
+ reload)
45
+ echo -n "Reloading $DESC configuration: "
46
+ start-stop-daemon --stop --signal HUP --quiet --pidfile /usr/local/nginx/logs/$NAME.pid \
47
+ --exec $DAEMON
48
+ echo "$NAME reloaded."
49
+ ;;
50
+ *)
51
+ N=/etc/init.d/$NAME
52
+ echo "Usage: $N {start|stop|restart|reload|force-reload}" >&2
53
+ exit 1
54
+ ;;
55
+ esac
56
+
57
+ exit 0
@@ -0,0 +1,26 @@
1
+ #!/bin/bash
2
+
3
+ PHP_SCRIPT=/usr/local/bin/php-fastcgi
4
+ RETVAL=0
5
+
6
+ case "$1" in
7
+ start)
8
+ $PHP_SCRIPT
9
+ RETVAL=$?
10
+ ;;
11
+ stop)
12
+ killall -9 php5-cgi
13
+ RETVAL=$?
14
+ ;;
15
+ restart)
16
+ killall -9 php5-cgi
17
+ $PHP_SCRIPT
18
+ RETVAL=$?
19
+ ;;
20
+ *)
21
+ echo "Usage: php-fastcgi {start|stop|restart}"
22
+ exit 1
23
+ ;;
24
+ esac
25
+
26
+ exit $RETVAL
@@ -0,0 +1,27 @@
1
+ server {
2
+ listen 80;
3
+ server_name <%= domains.join ' ' %>;
4
+
5
+ access_log <%= deploy_to %>/shared/log/nginx.log main;
6
+
7
+ location / {
8
+ root <%= deploy_to %>/current/public;
9
+ index index.html index.htm;
10
+ }
11
+
12
+ # redirect server error pages to the static page /50x.html
13
+
14
+ error_page 500 502 503 504 /50x.html;
15
+ location = /50x.html {
16
+ root <%= deploy_to %>/current/public;
17
+ }
18
+
19
+ # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
20
+
21
+ location ~ \.php$ {
22
+ fastcgi_pass 127.0.0.1:9000;
23
+ fastcgi_index index.php;
24
+ fastcgi_param SCRIPT_FILENAME <%= deploy_to %>/current/public$fastcgi_script_name;
25
+ include fastcgi_params;
26
+ }
27
+ }
@@ -0,0 +1,2 @@
1
+ #!/bin/sh
2
+ /usr/local/bin/spawn-fcgi -a 127.0.0.1 -p 9000 -f /usr/bin/php5-cgi -P /var/run/spawn-fcgi.pid
@@ -0,0 +1,13 @@
1
+ development: &defaults
2
+ adapter: mysql
3
+ database: <%= db_table %>
4
+ username: <%= db_user %>
5
+ password: <%= db_pass %>
6
+ host: localhost
7
+ socket: /var/run/mysqld/mysqld.sock
8
+
9
+ test:
10
+ <<: *defaults
11
+
12
+ production:
13
+ <<: *defaults
data/cookbook.rb ADDED
@@ -0,0 +1,66 @@
1
+ # Require helpers and recipes
2
+
3
+ require File.expand_path('cookbook_helpers.rb', File.dirname(__FILE__))
4
+ Dir[ File.expand_path('recipes/*.rb', File.dirname(__FILE__))].each do |f|
5
+ require f
6
+ end
7
+
8
+
9
+ Capistrano::Configuration.instance(:must_exist).load do
10
+
11
+ ROOT = self
12
+
13
+ # See cookbook hash in config/deploy.rb
14
+
15
+ cookbook[:port] = cookbook[:ssh_port] # Port is too ambiguous for me
16
+ cookbook.each do |key, value| # Merge cookbook with capistrano
17
+ value.respond_to?(:keys) ? value.each { |k, v| set "#{key}_#{k}".intern, v } : set(key, value)
18
+ end
19
+
20
+ # Default values
21
+
22
+ set :port, fetch(:port, 22)
23
+ set :user, fetch(:user, 'deploy')
24
+ set :stage, fetch(:stage, :production)
25
+ set :db_user, fetch(:db_user, 'app')
26
+ set :db_pass, fetch(:db_pass, '')
27
+ set :platform, fetch(:platform, :rails) # Or :php
28
+ set :ssl_cert, fetch(:ssl_cert, false)
29
+ set :use_sudo, fetch(:use_sudo, false)
30
+ set :auth_user, fetch(:auth_user, false)
31
+ set :nginx_dir, fetch(:nginx_dir, '/usr/local/nginx/conf')
32
+ set :mysql_dir, fetch(:mysql_dir, '/etc/mysql')
33
+ set :ultrasphinx, fetch(:ultrasphinx, false)
34
+ set :attachment_fu, fetch(:attachment_fu, false)
35
+ set :asset_packager, fetch(:asset_packager, false)
36
+ set :mongrel_etc_dir, fetch(:mongrel_etc_dir, '/usr/local/etc/mongrel_cluster')
37
+ set :mongrel_gem_dir, fetch(:mongrel_gem_dir, '/usr/local/lib/ruby/gems/1.8/gems/mongrel_cluster-1.0.5')
38
+ set :staging_mongrels, fetch(:staging_mongrels, 1)
39
+ set :production_mongrels, fetch(:production_mongrels, 2)
40
+
41
+ # Git by default
42
+
43
+ set :scm, :git
44
+ set :deploy_via, :remote_cache
45
+ set :repository_cache, 'git_cache'
46
+
47
+ ssh_options[:paranoid] = false
48
+
49
+ # Events
50
+
51
+ on :before, 'setup_stage', :except => [ :staging, :testing ] # Executed before every task
52
+ if platform == :rails
53
+ after 'deploy:update_code', 'rails:setup_git' # Initialize submodules
54
+ after 'deploy:update_code', 'rails:config:to_app' # Copy shared config to app
55
+ if asset_packager
56
+ after 'deploy:update_code', 'rails:config:asset_packager' # Configure attachment_fu
57
+ end
58
+ if attachment_fu
59
+ after 'deploy:update_code', 'rails:config:attachment_fu' # Configure attachment_fu
60
+ end
61
+ if ultrasphinx
62
+ after 'deploy:update_code', 'rails:config:ultrasphinx' # Configure ultrasphinx
63
+ end
64
+ end
65
+
66
+ end
@@ -0,0 +1,119 @@
1
+ require 'erb'
2
+
3
+
4
+ # Install
5
+
6
+ def gem_install(name, options='')
7
+ sudo_puts "gem install #{name} #{options}"
8
+ end
9
+
10
+ def unpack_source(source)
11
+ url = eval "sources_#{source}" # see cookbook[:sources]
12
+ name = File.basename url
13
+ src = "/home/#{user}/sources"
14
+ base = nil
15
+ [ 'tar.gz', 'tgz' ].each do |ext|
16
+ base = name[0..((ext.length + 2) * -1)] if name.include?(ext)
17
+ end
18
+ run_each [
19
+ "mkdir -p #{src}",
20
+ "cd #{src} && wget --quiet #{url}",
21
+ "tar -xzvf #{src}/#{name} -C #{src}"
22
+ ]
23
+ "#{src}/#{base}"
24
+ end
25
+
26
+ def install_source(source)
27
+ path = unpack_source source
28
+ yield path
29
+ sudo "rm -Rf #{path}"
30
+ end
31
+
32
+
33
+ # Files
34
+
35
+ def get_ssh_keys
36
+ keys = Dir[File.expand_path('~/.ssh/*.pub')].collect do |f|
37
+ File.open(f).collect { |line| line.strip.empty? ? nil : line.strip }.compact
38
+ end
39
+ keys.flatten.join("\n").strip
40
+ end
41
+
42
+ def upload_from_erb(destination, bind=nil, options={})
43
+ # options[ :chown => owner of file (default: deploy user),
44
+ # :chmod => 0644 etc
45
+ # :folder => 'postfix' etc,
46
+ # :name => name of template if differs from destination ]
47
+ if destination.respond_to?(:uniq)
48
+ destination.each { |d| upload_from_erb d, bind, options }
49
+ else
50
+ template = File.basename destination
51
+ template = template[1..-1] if template[0..0] == '.'
52
+ folder = options[:folder] ? options[:folder] + '/' : ''
53
+ template = File.expand_path("config/#{folder}#{options[:name]||template}.erb", File.dirname(__FILE__))
54
+ template = File.read template
55
+ sudo "touch #{destination}"
56
+ sudo "chown #{user} #{destination}"
57
+ put ERB.new(template).result(bind || binding), destination
58
+ sudo("chown #{options[:chown]} #{destination}") if options[:chown]
59
+ sudo("chmod #{options[:chmod]} #{destination}") if options[:chmod]
60
+ end
61
+ end
62
+
63
+
64
+ # MySQL
65
+
66
+ def mysql_run(sql)
67
+ if sql.respond_to?(:uniq)
68
+ sql.each { |s| mysql_run s }
69
+ else
70
+ run "echo \"#{sql}\" | #{mysql_call}"
71
+ end
72
+ end
73
+
74
+ def mysql_call
75
+ @mysql_root_password = @mysql_root_password || ask("Password for mysql root:")
76
+ "mysql -u root --password=#{@mysql_root_password}"
77
+ end
78
+
79
+
80
+ # Questions
81
+
82
+ def ask(question, default='')
83
+ question = "\n" + question.join("\n") if question.respond_to?(:uniq)
84
+ answer = Capistrano::CLI.ui.ask(question).strip
85
+ answer.empty? ? default : answer
86
+ end
87
+
88
+ def yes(question)
89
+ question = "\n" + question.join("\n") if question.respond_to?(:uniq)
90
+ question += ' (y/n)'
91
+ ask(question).downcase.include? 'y'
92
+ end
93
+
94
+
95
+ # Runners
96
+
97
+ def run_each(*args, &block)
98
+ cmd = args[0]
99
+ sudo = args[1]
100
+ if cmd.respond_to?(:uniq)
101
+ cmd.each { |c| run_each c, sudo, &block }
102
+ elsif sudo
103
+ sudo(cmd) { |ch, st, data| block.call(data) if block }
104
+ else
105
+ run(cmd) { |ch, st, data| block.call(data) if block }
106
+ end
107
+ end
108
+
109
+ def sudo_each(cmds, &block)
110
+ run_each cmds, true, &block
111
+ end
112
+
113
+ def run_puts(cmds, &block)
114
+ run_each(cmds) { |data| puts data }
115
+ end
116
+
117
+ def sudo_puts(cmds, &block)
118
+ sudo_each(cmds) { |data| puts data }
119
+ end
data/deploy.rb.example ADDED
@@ -0,0 +1,45 @@
1
+ set :cookbook, {
2
+ :application => 'my_app',
3
+ :base_dir => '/var/www',
4
+ :repository => 'git@github.com:user/my-app.git',
5
+ #:platform => :php # If enabled, you can remove all mongrel* lines
6
+ :mongrel_port => 3000, # Your next app should be 3003
7
+ :ssh_port => 22, # Or any unused port above 1024 (best practice)
8
+
9
+ :production => {
10
+ :domain => 'myapp.com',
11
+ :other_domains => [ 'www.myapp.com' ],
12
+ :mongrels => 2 # Ports 3000-3001
13
+ },
14
+
15
+ :staging => {
16
+ :domain => 'staging.myapp.com',
17
+ :mongrels => 1, # Port 3002
18
+ :auth_user => 'staging', # Nginx HTTP authorization
19
+ :auth_pass => 'password'
20
+ },
21
+
22
+ # Below is necessary for cap debian:setup
23
+
24
+ :monit => {
25
+ :domain => 'monit.myapp.com',
26
+ :from => 'monit@myapp.com',
27
+ :to => 'me@myapp.com',
28
+ :port => 8100,
29
+ :auth_user => 'admin',
30
+ :auth_pass => 'password'
31
+ },
32
+
33
+ :sources => {
34
+ :git => 'http://kernel.org/pub/software/scm/git/git-1.5.5.3.tar.gz',
35
+ :lighttpd => 'http://www.lighttpd.net/download/lighttpd-1.4.19.tar.gz',
36
+ :nginx => 'http://sysoev.ru/nginx/nginx-0.6.31.tar.gz',
37
+ :ruby => 'ftp://ftp.ruby-lang.org/pub/ruby/1.8/ruby-1.8.6-p114.tar.gz',
38
+ :rubygems => 'http://rubyforge.org/frs/download.php/35283/rubygems-1.1.1.tgz',
39
+ :sphinx => 'http://www.sphinxsearch.com/downloads/sphinx-0.9.8-rc2.tar.gz'
40
+ }
41
+ }
42
+
43
+ # See config/cookbook/cookbook.rb for more cookbook options
44
+
45
+ require 'config/cookbook/cookbook'