winton-cookbook 1.0.2 → 1.0.3

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,106 @@
1
+ Capistrano::Configuration.instance(:must_exist).load do
2
+
3
+ namespace :mysql do
4
+ namespace :create do
5
+ desc "Create database and user"
6
+ task :default, :roles => :db do
7
+ mysql.create.db
8
+ mysql.create.user
9
+ end
10
+
11
+ desc "Create database"
12
+ task :db, :roles => :db do
13
+ mysql_run "CREATE DATABASE #{db_table}"
14
+ end
15
+
16
+ desc "Create database user"
17
+ task :user, :roles => :db do
18
+ mysql_run [
19
+ "CREATE USER '#{db_user}'@'localhost' IDENTIFIED BY '#{db_pass}'",
20
+ "GRANT ALL PRIVILEGES ON *.* TO '#{db_user}'@'localhost'"
21
+ ]
22
+ end
23
+ end
24
+
25
+ namespace :update do
26
+ desc 'Update mysql root password'
27
+ task :root_password, :roles => :db do
28
+ old_pass = ask "Current root password? (default: none)"
29
+ new_pass = ask "New root password? (default: none)"
30
+ sudo "mysqladmin -u root #{old_pass.empty? ? '' : "--password=#{old_pass} "}password #{new_pass}"
31
+ end
32
+ end
33
+
34
+ namespace :destroy do
35
+ desc "Destroy database and user"
36
+ task :default, :roles => :db do
37
+ mysql.destroy.db
38
+ mysql.destroy.user
39
+ end
40
+
41
+ desc "Destroy database"
42
+ task :db, :roles => :db do
43
+ mysql_run "DROP DATABASE #{db_table}"
44
+ end
45
+
46
+ desc "Destroy database user"
47
+ task :user, :roles => :db do
48
+ mysql_run [
49
+ "REVOKE ALL PRIVILEGES, GRANT OPTION FROM '#{db_user}'@'localhost'",
50
+ "DROP USER '#{db_user}'@'localhost'"
51
+ ]
52
+ end
53
+ end
54
+
55
+ desc "Updates my.cnf from the file in config/cookbook"
56
+ task :config, :roles => :db do
57
+ question = [
58
+ "This task updates your server's my.cnf (MySQL config) with the one in config/cookbook.",
59
+ "OK?"
60
+ ]
61
+ if yes(question)
62
+ upload_from_erb "#{mysql_dir}/my.cnf", binding, :chown => 'root', :chmod => '0644', :folder => 'mysql'
63
+ sudo "/etc/init.d/mysql restart"
64
+ end
65
+ end
66
+
67
+ namespace :backup do
68
+ desc "Backup database to local"
69
+ task :to_local, :roles => :db do
70
+ to_server
71
+ system "mkdir -p ~/db_backups/#{stage}/#{application}"
72
+ get "#{shared_path}/db_backups/#{backup_name}.bz2", File.expand_path("~/db_backups/#{stage}/#{application}/#{backup_name}.bz2")
73
+ end
74
+
75
+ desc "Backup database to remote"
76
+ task :to_server, :roles => :db do
77
+ run_each [
78
+ "mkdir -p #{shared_path}/db_backups",
79
+ "mysqldump --add-drop-table -u #{db_user} -p#{db_pass} #{db_table}_production | bzip2 -c > #{shared_path}/db_backups/#{backup_name}.bz2"
80
+ ]
81
+ end
82
+
83
+ desc "Upload local backup to remote"
84
+ task :local_to_server, :roles => :db do
85
+ from = File.expand_path("~/db_backups/#{stage}/#{application}/#{backup_name}.bz2")
86
+ if File.exists?(from)
87
+ run_each "mkdir -p #{shared_path}/db_backups"
88
+ upload from, "#{shared_path}/db_backups/#{backup_name}.bz2"
89
+ else
90
+ puts "Does not exist: #{from}"
91
+ end
92
+ end
93
+
94
+ desc "Restore remote database from backup"
95
+ task :restore, :roles => :db do
96
+ run_each "bunzip2 < #{shared_path}/db_backups/#{backup_name}.bz2 | mysql -u #{db_user} --password=#{db_pass} #{db_table}"
97
+ end
98
+
99
+ def backup_name
100
+ now = Time.now
101
+ [ now.year, now.month, now.day ].join('-') + '.sql'
102
+ end
103
+ end
104
+ end
105
+
106
+ end
@@ -0,0 +1,79 @@
1
+ Capistrano::Configuration.instance(:must_exist).load do
2
+
3
+ namespace :nginx do
4
+ desc "Restart nginx"
5
+ task :restart, :roles => :app do
6
+ deploy.nginx.stop
7
+ deploy.nginx.start
8
+ end
9
+
10
+ desc "Start nginx"
11
+ task :start, :roles => :app do
12
+ sudo "/etc/init.d/nginx start"
13
+ end
14
+
15
+ desc "Stop nginx"
16
+ task :stop, :roles => :app do
17
+ sudo "/etc/init.d/nginx stop"
18
+ end
19
+
20
+ namespace :config do
21
+ desc "Generate remote application config"
22
+ task :default, :roles => :app do
23
+ if auth_user
24
+ sudo_each [
25
+ "mkdir -p #{nginx_dir}/htpasswd",
26
+ "htpasswd -bc #{nginx_dir}/htpasswd/#{application}_#{stage} #{auth_user} #{auth_pass}"
27
+ ]
28
+ end
29
+ end
30
+
31
+ desc "Destroy all files created by config"
32
+ task :destroy, :roles => :app do
33
+ sudo_each "rm -f #{nginx_dir}/htpasswd/#{application}_#{stage}"
34
+ end
35
+
36
+ namespace :run_once do
37
+ desc "Generate remote system config (run once)"
38
+ task :default, :roles => :app do
39
+ question = [
40
+ "This task updates your server's nginx.conf with the one in config/cookbook.",
41
+ "OK?"
42
+ ]
43
+ if yes(question)
44
+ sudo_each [
45
+ "mkdir -p #{nginx_dir}/vhosts",
46
+ "chmod 0755 #{nginx_dir}/vhosts"
47
+ ]
48
+ upload_from_erb "#{nginx_dir}/nginx.conf", binding, :chown => 'root', :chmod => '0644', :folder => 'nginx'
49
+ end
50
+ end
51
+
52
+ desc "Destroy remote system config"
53
+ task :destroy, :roles => :app do
54
+ sudo_each "rm -f #{nginx_dir}/nginx.conf"
55
+ end
56
+ end
57
+
58
+ namespace :ssl do
59
+ desc "Generate SSL key"
60
+ task :default, :roles => :app do
61
+ # http://www.geotrust.com/quickssl/csr
62
+ question = [
63
+ "This task creates cert/key and cert/csr. Press enter for all optional SSL questions.",
64
+ "Use these files when buying an SSL cert.",
65
+ '',
66
+ "Place the purchased cert in cert/cert. Set :ssl_cert => true in deploy.rb.",
67
+ "OK?"
68
+ ]
69
+ if yes(question)
70
+ system 'mkdir -p cert'
71
+ system 'openssl genrsa -out cert/key 1024'
72
+ system 'openssl req -new -key cert/key -out cert/csr'
73
+ end
74
+ end
75
+ end
76
+ end
77
+ end
78
+
79
+ end
@@ -0,0 +1,17 @@
1
+ Capistrano::Configuration.instance(:must_exist).load do
2
+
3
+ namespace :php do
4
+ namespace :config do
5
+ desc "Generate remote application config"
6
+ task :default, :roles => :app do
7
+ php.config.nginx
8
+ end
9
+
10
+ desc "Generate remote Nginx vhost"
11
+ task :nginx, :roles => :app do
12
+ upload_from_erb "#{nginx_dir}/vhosts/#{application}_#{stage}.conf", binding, :folder => 'php', :name => 'nginx.vhost'
13
+ end
14
+ end
15
+ end
16
+
17
+ end
@@ -0,0 +1,65 @@
1
+ Capistrano::Configuration.instance(:must_exist).load do
2
+
3
+ namespace :rails do
4
+ namespace :config do
5
+ desc "Copies all files in cookbook/rails to shared config"
6
+ task :default, :roles => :app do
7
+ run "mkdir -p #{shared_path}/config"
8
+ Dir[File.expand_path('../config/rails/*', File.dirname(__FILE__))].each do |f|
9
+ upload_from_erb "#{shared_path}/config/#{File.basename(f, '.erb')}", binding, :folder => 'rails'
10
+ end
11
+ end
12
+
13
+ desc "Copies yml files in the shared config folder into our app config"
14
+ task :to_app, :roles => :app do
15
+ run "cp -Rf #{shared_path}/config/* #{release_path}/config"
16
+ end
17
+
18
+ desc "Configure asset_packager"
19
+ task :asset_packager do
20
+ run "source ~/.bash_profile && cd #{release_path} && rake RAILS_ENV=production asset:packager:build_all"
21
+ end
22
+
23
+ desc "Configure attachment_fu"
24
+ task :attachment_fu, :roles => :app do
25
+ run_each [
26
+ "mkdir -p #{shared_path}/media",
27
+ "ln -sf #{shared_path}/media #{release_path}/public/media"
28
+ ]
29
+ sudo_each [
30
+ "mkdir -p #{release_path}/tmp/attachment_fu",
31
+ "chown -R #{user} #{release_path}/tmp/attachment_fu"
32
+ ]
33
+ end
34
+
35
+ namespace :ultrasphinx do
36
+ desc "Configures ultrasphinx"
37
+ task :default, :roles => :app do
38
+ sudo "cd #{release_path} && rake RAILS_ENV=production ultrasphinx:configure"
39
+ end
40
+
41
+ desc "Stop ultrasphinx"
42
+ task :stop, :roles => :app do
43
+ sudo "cd #{release_path} && rake RAILS_ENV=production ultrasphinx:daemon:stop"
44
+ end
45
+
46
+ desc "Start ultrasphinx"
47
+ task :start, :roles => :app do
48
+ sudo "cd #{release_path} && rake RAILS_ENV=production ultrasphinx:daemon:start"
49
+ end
50
+
51
+ desc "Restart ultrasphinx"
52
+ task :restart, :roles => :app do
53
+ rails.config.ultrasphinx.stop
54
+ rails.config.ultrasphinx.start
55
+ end
56
+ end
57
+ end
58
+
59
+ desc "Intialize Git submodules"
60
+ task :setup_git, :roles => :app do
61
+ run "cd #{release_path}; git submodule init; git submodule update"
62
+ end
63
+ end
64
+
65
+ end
@@ -0,0 +1,64 @@
1
+ Capistrano::Configuration.instance(:must_exist).load do
2
+
3
+ namespace :ssh do
4
+ desc 'Generate ssh keys and upload to server'
5
+ task :setup do
6
+ ssh.create_keys
7
+ ssh.upload_keys
8
+ end
9
+
10
+ desc "Creates an rsa ssh key pair in your ~/.ssh folder"
11
+ task :create_keys do
12
+ question = [
13
+ "This task generates a rsa ssh key pair in your ~/.ssh folder.",
14
+ "OK?"
15
+ ]
16
+ system('ssh-keygen -t rsa') if yes(question)
17
+ end
18
+
19
+ desc "Creates an rsa ssh key pair in the server's ~/.ssh folder"
20
+ task :create_server_keys do
21
+ question = [
22
+ "This task generates a rsa ssh key pair in the server's ~/.ssh folder and displays the public key.",
23
+ "OK?"
24
+ ]
25
+ if yes(question)
26
+ usr = ask "Create ssh keys for which user? (default: #{user})", user
27
+ pass = ask "Enter a password for this key:"
28
+
29
+ sudo_each [
30
+ "ssh-keygen -t rsa -N '#{pass}' -q -f /home/#{usr}/.ssh/id_rsa",
31
+ "chmod 0700 /home/#{usr}/.ssh",
32
+ "chown -R #{usr} /home/#{usr}/.ssh"
33
+ ]
34
+ sudo_puts "tail -1 /home/#{usr}/.ssh/id_rsa.pub"
35
+ end
36
+ end
37
+
38
+ desc "Copies contents of ssh public keys into authorized_keys file"
39
+ task :upload_keys do
40
+ question = [
41
+ "This task copies all of your public keys in ~/.ssh to the server's authorized_keys.",
42
+ "OK?"
43
+ ]
44
+ if yes(question)
45
+ usr = ask "Upload ssh public keys to which user? (default: #{user})", user
46
+ keys = ask "Press enter to copy all public keys (~/.ssh/*.pub), or paste a key: ", get_ssh_keys
47
+
48
+ if k.empty?
49
+ ssh.setup if yes("No keys found. Generate ssh keys now?")
50
+ else
51
+ sudo_each [
52
+ "mkdir /home/#{usr}/.ssh",
53
+ "touch /home/#{usr}/.ssh/authorized_keys",
54
+ "echo \"#{keys}\" >> /home/#{usr}/.ssh/authorized_keys",
55
+ "chmod 0700 /home/#{usr}/.ssh",
56
+ "chmod 0600 /home/#{usr}/.ssh/authorized_keys",
57
+ "chown -R #{usr} /home/#{usr}/.ssh",
58
+ ]
59
+ end
60
+ end
61
+ end
62
+ end
63
+
64
+ end
@@ -0,0 +1,34 @@
1
+ Capistrano::Configuration.instance(:must_exist).load do
2
+
3
+ desc 'Set the target stage to staging'
4
+ task :staging do
5
+ set :stage, :staging
6
+ end
7
+
8
+ desc 'Set the target stage to test'
9
+ task :testing do
10
+ set :stage, :test
11
+ end
12
+
13
+ # None of this works in a namespace
14
+ desc 'Set up stage-dependent properties'
15
+ task :setup_stage do
16
+ set :base_dir, "#{cookbook[:base_dir]}/#{stage}"
17
+ set :deploy_to, "#{base_dir}/#{application}"
18
+
19
+ set :db_table, application + (stage == :staging ? "_#{stage}" : '')
20
+ set :mongrel_port, cookbook[:mongrel_port] + production_mongrels if stage == :staging
21
+
22
+ set :domain, cookbook[stage][:domain]
23
+ set :domains, (cookbook[stage][:other_domains] || []) + [ domain ]
24
+ set :branch, cookbook[stage][:branch] || 'master'
25
+ set :mongrels, cookbook[stage][:mongrels]
26
+ set :auth_user, cookbook[stage][:auth_user]
27
+ set :auth_pass, cookbook[stage][:auth_pass]
28
+
29
+ role :app, domain
30
+ role :web, domain
31
+ role :db, domain, :primary => true
32
+ end
33
+
34
+ end
@@ -0,0 +1,9 @@
1
+ export PS1='\e[01;30m\h \e[33m\u \e[01;34m\w\e[00m: '
2
+
3
+ alias free="free -m"
4
+
5
+ alias aptitude="sudo aptitude"
6
+ alias update="sudo aptitude update"
7
+ alias upgrade="sudo aptitude upgrade"
8
+ alias install="sudo aptitude install"
9
+ alias remove="sudo aptitude remove"
@@ -0,0 +1,47 @@
1
+ *filter
2
+
3
+
4
+ # Allows all loopback (lo0) traffic and drop all traffic to 127/8 that doesn't use lo0
5
+ -A INPUT -i lo -j ACCEPT
6
+ -A INPUT -i ! lo -d 127.0.0.0/8 -j REJECT
7
+
8
+
9
+ # Accepts all established inbound connections
10
+ -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
11
+
12
+
13
+ # Allows all outbound traffic
14
+ # You can modify this to only allow certain traffic
15
+ -A OUTPUT -j ACCEPT
16
+
17
+
18
+ # Allows HTTP and HTTPS connections from anywhere (the normal ports for websites)
19
+ -A INPUT -p tcp --dport 80 -j ACCEPT
20
+ -A INPUT -p tcp --dport 443 -j ACCEPT
21
+
22
+
23
+ # Allows IMAP
24
+ -A INPUT -p tcp --dport 143 -j ACCEPT
25
+
26
+
27
+ # Allows SSH connections
28
+ #
29
+ # THE -dport NUMBER IS THE SAME ONE YOU SET UP IN THE SSHD_CONFIG FILE
30
+ #
31
+ -A INPUT -p tcp -m state --state NEW --dport <%= ssh_port %> -j ACCEPT
32
+
33
+
34
+ # Allow ping
35
+ -A INPUT -p icmp -m icmp --icmp-type 8 -j ACCEPT
36
+
37
+
38
+ # log iptables denied calls
39
+ -A INPUT -m limit --limit 5/min -j LOG --log-prefix "iptables denied: " --log-level 7
40
+
41
+
42
+ # Reject all other inbound - default deny unless explicitly allowed policy
43
+ -A INPUT -j REJECT
44
+ -A FORWARD -j REJECT
45
+
46
+ COMMIT
47
+ # There MUST be a new line after this line!
@@ -0,0 +1 @@
1
+ en_US.UTF-8 UTF-8
@@ -0,0 +1,78 @@
1
+ # Package generated configuration file
2
+ # See the sshd(8) manpage for details
3
+
4
+ # What ports, IPs and protocols we listen for
5
+ Port <%= ssh_port %>
6
+ # Use these options to restrict which interfaces/protocols sshd will bind to
7
+ #ListenAddress ::
8
+ #ListenAddress 0.0.0.0
9
+ Protocol 2
10
+ # HostKeys for protocol version 2
11
+ HostKey /etc/ssh/ssh_host_rsa_key
12
+ HostKey /etc/ssh/ssh_host_dsa_key
13
+ #Privilege Separation is turned on for security
14
+ UsePrivilegeSeparation yes
15
+
16
+ # Lifetime and size of ephemeral version 1 server key
17
+ KeyRegenerationInterval 3600
18
+ ServerKeyBits 768
19
+
20
+ # Logging
21
+ SyslogFacility AUTH
22
+ LogLevel INFO
23
+
24
+ # Authentication:
25
+ LoginGraceTime 120
26
+ PermitRootLogin no
27
+ StrictModes yes
28
+
29
+ RSAAuthentication yes
30
+ PubkeyAuthentication yes
31
+ #AuthorizedKeysFile %h/.ssh/authorized_keys
32
+
33
+ # Don't read the user's ~/.rhosts and ~/.shosts files
34
+ IgnoreRhosts yes
35
+ # For this to work you will also need host keys in /etc/ssh_known_hosts
36
+ RhostsRSAAuthentication no
37
+ # similar for protocol version 2
38
+ HostbasedAuthentication no
39
+ # Uncomment if you don't trust ~/.ssh/known_hosts for RhostsRSAAuthentication
40
+ #IgnoreUserKnownHosts yes
41
+
42
+ # To enable empty passwords, change to yes (NOT RECOMMENDED)
43
+ PermitEmptyPasswords no
44
+
45
+ # Change to yes to enable challenge-response passwords (beware issues with
46
+ # some PAM modules and threads)
47
+ ChallengeResponseAuthentication no
48
+
49
+ # Change to no to disable tunnelled clear text passwords
50
+ #PasswordAuthentication yes
51
+
52
+ # Kerberos options
53
+ #KerberosAuthentication no
54
+ #KerberosGetAFSToken no
55
+ #KerberosOrLocalPasswd yes
56
+ #KerberosTicketCleanup yes
57
+
58
+ # GSSAPI options
59
+ #GSSAPIAuthentication no
60
+ #GSSAPICleanupCredentials yes
61
+
62
+ X11Forwarding no
63
+ X11DisplayOffset 10
64
+ PrintMotd no
65
+ PrintLastLog yes
66
+ TCPKeepAlive yes
67
+ #UseLogin no
68
+
69
+ #MaxStartups 10:30:60
70
+ #Banner /etc/issue.net
71
+
72
+ # Allow client to pass locale environment variables
73
+ AcceptEnv LANG LC_*
74
+
75
+ Subsystem sftp /usr/lib/openssh/sftp-server
76
+
77
+ UsePAM no
78
+ UseDNS no
@@ -0,0 +1,9 @@
1
+ <%= shared_path %>/log/*.log {
2
+ daily
3
+ missingok
4
+ rotate 7
5
+ compress
6
+ delaycompress
7
+ notifempty
8
+ copytruncate
9
+ }
@@ -0,0 +1,10 @@
1
+ ---
2
+ user: <%= user %>
3
+ group: <%= user %>
4
+ log_file: <%= deploy_to %>/shared/log/mongrel.log
5
+ cwd: <%= deploy_to %>/current
6
+ port: <%= mongrel_port %>
7
+ environment: production
8
+ pid_file: <%= deploy_to %>/shared/pids/mongrel.pid
9
+ address: 127.0.0.1
10
+ servers: <%= mongrels %>