centostrano 0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (121) hide show
  1. data/CHANGELOG +215 -0
  2. data/COPYING +19 -0
  3. data/LICENSE +339 -0
  4. data/README +166 -0
  5. data/THANKS +5 -0
  6. data/bin/centify +137 -0
  7. data/docs/ANNOUNCE.deprec2 +47 -0
  8. data/docs/README.install +88 -0
  9. data/docs/README.nagios +28 -0
  10. data/docs/README.rails +20 -0
  11. data/docs/README.svn +31 -0
  12. data/docs/ROADMAP.txt +74 -0
  13. data/docs/deprec-1.x/deprec-1.x.quickstart +50 -0
  14. data/docs/deprec-1.x/notes.txt +12 -0
  15. data/docs/deprec_banner.gif +0 -0
  16. data/lib/centostrano.rb +9 -0
  17. data/lib/deprec/capistrano_extensions.rb +391 -0
  18. data/lib/deprec/centostrano.rb +46 -0
  19. data/lib/deprec/recipes/apache.rb +188 -0
  20. data/lib/deprec/recipes/canonical.rb +57 -0
  21. data/lib/deprec/recipes/deprec.rb +188 -0
  22. data/lib/deprec/recipes/deprecated.rb +71 -0
  23. data/lib/deprec/recipes/example.rb +115 -0
  24. data/lib/deprec/recipes/git.rb +106 -0
  25. data/lib/deprec/recipes/gitosis.rb +134 -0
  26. data/lib/deprec/recipes/logrotate.rb +54 -0
  27. data/lib/deprec/recipes/memcache.rb +53 -0
  28. data/lib/deprec/recipes/merb.rb +57 -0
  29. data/lib/deprec/recipes/mongrel.rb +220 -0
  30. data/lib/deprec/recipes/monit.rb +139 -0
  31. data/lib/deprec/recipes/mysql.rb +147 -0
  32. data/lib/deprec/recipes/nginx.rb +172 -0
  33. data/lib/deprec/recipes/postgresql.rb +132 -0
  34. data/lib/deprec/recipes/rails.rb +297 -0
  35. data/lib/deprec/recipes/ruby.rb +71 -0
  36. data/lib/deprec/recipes/sphinx.rb +89 -0
  37. data/lib/deprec/recipes/ssh.rb +93 -0
  38. data/lib/deprec/recipes/svn.rb +167 -0
  39. data/lib/deprec/recipes/users.rb +90 -0
  40. data/lib/deprec/recipes.rb +33 -0
  41. data/lib/deprec/templates/aoe/aoe-init +55 -0
  42. data/lib/deprec/templates/aoe/fence_aoemask +351 -0
  43. data/lib/deprec/templates/apache/httpd-vhost-app.conf.erb +144 -0
  44. data/lib/deprec/templates/apache/httpd.conf +465 -0
  45. data/lib/deprec/templates/apache/index.html.erb +37 -0
  46. data/lib/deprec/templates/apache/master.css +72 -0
  47. data/lib/deprec/templates/centos/repository.erb +6 -0
  48. data/lib/deprec/templates/coraid/aoe-init +55 -0
  49. data/lib/deprec/templates/deprec/caprc.erb +14 -0
  50. data/lib/deprec/templates/heartbeat/authkeys.erb +2 -0
  51. data/lib/deprec/templates/heartbeat/ha.cf.erb +15 -0
  52. data/lib/deprec/templates/heartbeat/haresources.erb +1 -0
  53. data/lib/deprec/templates/logrotate/logrotate.conf.erb +32 -0
  54. data/lib/deprec/templates/mongrel/logrotate.conf.erb +11 -0
  55. data/lib/deprec/templates/mongrel/logrotate.erb +0 -0
  56. data/lib/deprec/templates/mongrel/mongrel_cluster-init-script +54 -0
  57. data/lib/deprec/templates/mongrel/mongrel_cluster.logrotate.d +14 -0
  58. data/lib/deprec/templates/mongrel/mongrel_cluster.yml.erb +10 -0
  59. data/lib/deprec/templates/mongrel/monit.conf.erb +17 -0
  60. data/lib/deprec/templates/monit/monit-init-script +104 -0
  61. data/lib/deprec/templates/monit/monitrc.erb +227 -0
  62. data/lib/deprec/templates/monit/nothing +0 -0
  63. data/lib/deprec/templates/mysql/create_databases.sql +20 -0
  64. data/lib/deprec/templates/mysql/database.yml.prod +6 -0
  65. data/lib/deprec/templates/mysql/database.yml.stage +6 -0
  66. data/lib/deprec/templates/mysql/my.cnf.erb +140 -0
  67. data/lib/deprec/templates/mysql/sphinx.conf.prod +542 -0
  68. data/lib/deprec/templates/mysql/sphinx.conf.stage +542 -0
  69. data/lib/deprec/templates/nagios/cgi.cfg.erb +321 -0
  70. data/lib/deprec/templates/nagios/commands.cfg.erb +240 -0
  71. data/lib/deprec/templates/nagios/contacts.cfg.erb +57 -0
  72. data/lib/deprec/templates/nagios/hosts.cfg.erb +143 -0
  73. data/lib/deprec/templates/nagios/htpasswd.users +1 -0
  74. data/lib/deprec/templates/nagios/localhost.cfg.erb +157 -0
  75. data/lib/deprec/templates/nagios/nagios.cfg.erb +1274 -0
  76. data/lib/deprec/templates/nagios/nagios_apache_vhost.conf.erb +45 -0
  77. data/lib/deprec/templates/nagios/nrpe.cfg.erb +210 -0
  78. data/lib/deprec/templates/nagios/nrpe.xinetd.erb +16 -0
  79. data/lib/deprec/templates/nagios/resource.cfg.erb +34 -0
  80. data/lib/deprec/templates/nagios/services.cfg.erb +79 -0
  81. data/lib/deprec/templates/nagios/templates.cfg.erb +9 -0
  82. data/lib/deprec/templates/nagios/timeperiods.cfg.erb +94 -0
  83. data/lib/deprec/templates/network/hostname.erb +1 -0
  84. data/lib/deprec/templates/network/hosts.erb +2 -0
  85. data/lib/deprec/templates/network/interfaces.erb +22 -0
  86. data/lib/deprec/templates/nginx/logrotate.conf.erb +13 -0
  87. data/lib/deprec/templates/nginx/logrotate.erb +0 -0
  88. data/lib/deprec/templates/nginx/mime.types.erb +70 -0
  89. data/lib/deprec/templates/nginx/nginx-init-script +109 -0
  90. data/lib/deprec/templates/nginx/nginx.conf.erb +120 -0
  91. data/lib/deprec/templates/nginx/nginx.logrotate.d +12 -0
  92. data/lib/deprec/templates/nginx/nothing.conf +1 -0
  93. data/lib/deprec/templates/nginx/rails_nginx_vhost.conf.erb +41 -0
  94. data/lib/deprec/templates/ntp/ntp.conf.erb +42 -0
  95. data/lib/deprec/templates/postfix/aliases.erb +3 -0
  96. data/lib/deprec/templates/postfix/dynamicmaps.cf.erb +8 -0
  97. data/lib/deprec/templates/postfix/main.cf.erb +41 -0
  98. data/lib/deprec/templates/postfix/master.cf.erb +77 -0
  99. data/lib/deprec/templates/postgresql/pg_hba.conf.erb +76 -0
  100. data/lib/deprec/templates/sphinx/monit.conf.erb +5 -0
  101. data/lib/deprec/templates/ssh/ssh_config.erb +50 -0
  102. data/lib/deprec/templates/ssh/sshd_config.erb +78 -0
  103. data/lib/deprec/templates/subversion/svn.apache.vhost.erb +43 -0
  104. data/lib/deprec/templates/trac/apache_vhost.conf.erb +24 -0
  105. data/lib/deprec/templates/trac/trac.ini.erb +106 -0
  106. data/lib/deprec/templates/trac/trac_deprec.png +0 -0
  107. data/lib/deprec/templates/trac/tracd-init.erb +43 -0
  108. data/lib/deprec/templates/xen/15-disable-hwclock +40 -0
  109. data/lib/deprec/templates/xen/network-bridge-wrapper +3 -0
  110. data/lib/deprec/templates/xen/xen-tools.conf.erb +220 -0
  111. data/lib/deprec/templates/xen/xend-config.sxp.erb +195 -0
  112. data/lib/deprec/templates/xen/xend-init.erb +69 -0
  113. data/lib/deprec/templates/xen/xendomains.erb +137 -0
  114. data/lib/deprec/templates/xen/xm.tmpl.erb +85 -0
  115. data/lib/deprec_cmd_completion.sh +26 -0
  116. data/lib/vmbuilder_plugins/all.rb +20 -0
  117. data/lib/vmbuilder_plugins/apt.rb +93 -0
  118. data/lib/vmbuilder_plugins/emerge.rb +76 -0
  119. data/lib/vmbuilder_plugins/gem.rb +90 -0
  120. data/lib/vmbuilder_plugins/std.rb +203 -0
  121. metadata +207 -0
@@ -0,0 +1,147 @@
1
+ # Copyright 2006-2008 by Mike Bailey. All rights reserved.
2
+ Capistrano::Configuration.instance(:must_exist).load do
3
+ namespace :centos do
4
+ namespace :mysql do
5
+
6
+ # Installation
7
+
8
+ desc "Install mysql"
9
+ task :install, :roles => :db do
10
+ install_deps
11
+ symlink_mysql_sockfile # XXX still needed?
12
+ end
13
+
14
+ # Install dependencies for Mysql
15
+ task :install_deps, :roles => :db do
16
+ apt.install( {:base => %w(mysql mysql-server mysql-devel)}, :stable )
17
+ end
18
+
19
+ desc "Create Database"
20
+ task :create_db, :roles => :db do
21
+ read_config
22
+ sql = "CREATE DATABASE #{db_name}; GRANT ALL PRIVILEGES ON #{db_name}.* TO #{db_user}@localhost IDENTIFIED BY '#{db_password}';"
23
+ execute(sql, db_user)
24
+ end
25
+
26
+ task :symlink_mysql_sockfile, :roles => :db do
27
+ # rails puts "socket: /tmp/mysql.sock" into config/database.yml
28
+ # this is not the location for our ubuntu's mysql socket file
29
+ # so we create this link to make deployment using rails defaults simpler
30
+ sudo "ln -sf /var/lib/mysql/mysql.sock /tmp/mysql.sock"
31
+ end
32
+
33
+ # Configuration
34
+
35
+ SYSTEM_CONFIG_FILES[:mysql] = [
36
+
37
+ {:template => "my.cnf.erb",
38
+ :path => '/etc/mysql/my.cnf',
39
+ :mode => 0644,
40
+ :owner => 'root:root'}
41
+ ]
42
+
43
+ desc "Create DB according to production settings in database.yml"
44
+ task :setup_db do
45
+ top.centos.mysql.activate
46
+ top.centos.mysql.start
47
+ top.centos.mysql.create_db
48
+ end
49
+
50
+ desc "Generate configuration file(s) for mysql from template(s)"
51
+ task :config_gen do
52
+ SYSTEM_CONFIG_FILES[:mysql].each do |file|
53
+ deprec2.render_template(:mysql, file)
54
+ end
55
+ end
56
+
57
+ desc "Push trac config files to server"
58
+ task :config, :roles => :db do
59
+ deprec2.push_configs(:mysql, SYSTEM_CONFIG_FILES[:mysql])
60
+ end
61
+
62
+ task :activate, :roles => :db do
63
+ send(run_method, "/sbin/chkconfig --add mysqld")
64
+ send(run_method, "/sbin/chkconfig mysqld on")
65
+ end
66
+
67
+ task :deactivate, :roles => :db do
68
+ send(run_method, "/sbin/chkconfig --del mysqld")
69
+ end
70
+
71
+ # Control
72
+
73
+ desc "Start Mysql"
74
+ task :start, :roles => :db do
75
+ send(run_method, "/etc/init.d/mysqld start")
76
+ end
77
+
78
+ desc "Stop Mysql"
79
+ task :stop, :roles => :db do
80
+ send(run_method, "/etc/init.d/mysqld stop")
81
+ end
82
+
83
+ desc "Restart Mysql"
84
+ task :restart, :roles => :db do
85
+ send(run_method, "/etc/init.d/mysqld restart")
86
+ end
87
+
88
+ desc "Reload Mysql"
89
+ task :reload, :roles => :db do
90
+ send(run_method, "/etc/init.d/mysqld reload")
91
+ end
92
+
93
+
94
+ task :backup, :roles => :db do
95
+ end
96
+
97
+ task :restore, :roles => :db do
98
+ end
99
+
100
+ end
101
+ end
102
+
103
+ # Imported from Rails Machine gem (Copyright (c) 2006 Bradley Taylor, bradley@railsmachine.com)
104
+
105
+ def execute(sql, user)
106
+ run "mysql --user=root --execute=\"#{sql}\"" do |channel, stream, data|
107
+ handle_mysql_password(user, channel, stream, data)
108
+ end
109
+ end
110
+
111
+ def handle_mysql_password(user, channel, stream, data)
112
+ logger.info data, "[database on #{channel[:host]} asked for password]"
113
+ if data =~ /^Enter password:/
114
+ pass = Capistrano::CLI.password_prompt "Enter database password for '#{user}':"
115
+ channel.send_data "#{pass}\n"
116
+ end
117
+ end
118
+
119
+ end
120
+
121
+ #
122
+ # Setup replication
123
+ #
124
+
125
+ # setup user for repl
126
+ # GRANT REPLICATION SLAVE ON *.* TO 'repl'@'%.yourdomain.com' IDENTIFIED BY 'slavepass';
127
+
128
+ # get current position of binlog
129
+ # mysql> FLUSH TABLES WITH READ LOCK;
130
+ # Query OK, 0 rows affected (0.00 sec)
131
+ #
132
+ # mysql> SHOW MASTER STATUS;
133
+ # +------------------+----------+--------------+------------------+
134
+ # | File | Position | Binlog_Do_DB | Binlog_Ignore_DB |
135
+ # +------------------+----------+--------------+------------------+
136
+ # | mysql-bin.000012 | 296 | | |
137
+ # +------------------+----------+--------------+------------------+
138
+ # 1 row in set (0.00 sec)
139
+ #
140
+ # # get current data
141
+ # mysqldump --all-databases --master-data >dbdump.db
142
+ #
143
+ # UNLOCK TABLES;
144
+
145
+
146
+ # Replication Features and Issues
147
+ # http://dev.mysql.com/doc/refman/5.0/en/replication-features.html
@@ -0,0 +1,172 @@
1
+ # Copyright 2006-2008 by Mike Bailey. All rights reserved.
2
+ Capistrano::Configuration.instance(:must_exist).load do
3
+ namespace :centos do
4
+ namespace :nginx do
5
+
6
+ set :nginx_server_name, nil
7
+ set :nginx_user, 'nginx'
8
+ set :nginx_group, 'nginx'
9
+ set :nginx_vhost_dir, '/usr/local/nginx/conf/vhosts'
10
+ set :nginx_client_max_body_size, '50M'
11
+
12
+ SRC_PACKAGES[:nginx] = {
13
+ :filename => 'nginx-0.6.31.tar.gz',
14
+ :md5sum => "824bcc25bbd5b636f182237b69227bd2 nginx-0.6.31.tar.gz",
15
+ :dir => 'nginx-0.6.31',
16
+ :url => "http://sysoev.ru/nginx/nginx-0.6.31.tar.gz",
17
+ :unpack => "tar zxf nginx-0.6.31.tar.gz;",
18
+ :configure => %w(
19
+ ./configure
20
+ --sbin-path=/usr/local/sbin
21
+ --with-http_ssl_module
22
+ ;
23
+ ).reject{|arg| arg.match '#'}.join(' '),
24
+ :make => 'make;',
25
+ :install => 'make install;',
26
+ :version => 'c0.6.31',
27
+ :release => '1'
28
+ }
29
+
30
+ desc "Install nginx"
31
+ task :install do
32
+ install_deps
33
+ deprec2.download_src(SRC_PACKAGES[:nginx], src_dir)
34
+ yum.install_from_src(SRC_PACKAGES[:nginx], src_dir)
35
+ #install_start_stop_daemon
36
+ create_nginx_user
37
+ sudo "test -d /usr/local/nginx/logs || (sudo mkdir /usr/local/nginx/logs)"# && sudo chown nobody:nobody /usr/local/nginx/logs)"
38
+ # install_index_page # XXX not done yet
39
+ SYSTEM_CONFIG_FILES[:nginx].each do |file|
40
+ deprec2.render_template(:nginx, file.merge(:remote => true))
41
+ end
42
+ activate
43
+ end
44
+
45
+ # install dependencies for nginx
46
+ task :install_deps do
47
+ #apt.install( {:base => %w(libpcre3 libpcre3-dev libpcrecpp0 libssl-dev zlib1g-dev)}, :stable )
48
+ apt.install( {:base => %w(pcre* openssl openssl-devel zlib-devel)}, :stable )
49
+ # do we need libgcrypt11-dev?
50
+ end
51
+
52
+ task :create_nginx_user do
53
+ deprec2.groupadd(nginx_group)
54
+ deprec2.useradd(nginx_user, :group => nginx_group, :homedir => false)
55
+ end
56
+
57
+ task :rename_index_page, :roles => :web do
58
+ index_file = '/usr/local/nginx/html/index.html'
59
+ sudo "test -f #{index_file} && sudo mv #{index_file} #{index_file}.orig || exit 0"
60
+ end
61
+
62
+ SYSTEM_CONFIG_FILES[:nginx] = [
63
+
64
+ {:template => 'nginx-init-script',
65
+ :path => '/etc/init.d/nginx',
66
+ :mode => 0755,
67
+ :owner => 'root:root'},
68
+
69
+ {:template => 'nginx.conf.erb',
70
+ :path => "/usr/local/nginx/conf/nginx.conf",
71
+ :mode => 0644,
72
+ :owner => 'root:root'},
73
+
74
+ {:template => 'mime.types.erb',
75
+ :path => "/usr/local/nginx/conf/mime.types",
76
+ :mode => 0644,
77
+ :owner => 'root:root'},
78
+
79
+ {:template => 'nothing.conf',
80
+ :path => "/usr/local/nginx/conf/vhosts/nothing.conf",
81
+ :mode => 0644,
82
+ :owner => 'root:root'}
83
+ ]
84
+
85
+ desc <<-DESC
86
+ Generate nginx config from template. Note that this does not
87
+ push the config to the server, it merely generates required
88
+ configuration files. These should be kept under source control.
89
+ The can be pushed to the server with the :config task.
90
+ DESC
91
+ task :config_gen do
92
+ SYSTEM_CONFIG_FILES[:nginx].each do |file|
93
+ deprec2.render_template(:nginx, file)
94
+ end
95
+ end
96
+
97
+ desc "Push nginx config files to server"
98
+ task :config, :roles => :web do
99
+ deprec2.push_configs(:nginx, SYSTEM_CONFIG_FILES[:nginx])
100
+ end
101
+
102
+ # desc "install start_stop_daemon"
103
+ #task :install_start_stop_daemon, :roles => :web do
104
+ #commands = <<-DESC
105
+ #sh -c 'cd /usr/local/src;
106
+ #wget http://developer.axis.com/download/distribution/apps-sys-utils-start-stop-daemon-IR1_9_18-1.tar.gz;
107
+ #tar zxvf apps-sys-utils-start-stop-daemon-IR1_9_18-1.tar.gz;
108
+ #cd /usr/local/src/apps/sys-utils/start-stop-daemon-IR1_9_18-1/;
109
+ #gcc start-stop-daemon.c -o start-stop-daemon;
110
+ #cp start-stop-daemon /usr/sbin;'
111
+ #DESC
112
+ #send(run_method, commands)
113
+ #end
114
+
115
+ desc <<-DESC
116
+ Activate nginx start scripts on server.
117
+ Setup server to start nginx on boot.
118
+ DESC
119
+ task :activate do
120
+ activate_system
121
+ end
122
+
123
+ task :activate_system do
124
+ send(run_method, "/sbin/chkconfig --add nginx")
125
+ send(run_method, "/sbin/chkconfig --level 345 nginx on")
126
+ end
127
+
128
+ desc <<-DESC
129
+ Dectivate nginx start scripts on server.
130
+ Setup server to start nginx on boot.
131
+ DESC
132
+ task :deactivate do
133
+ send(run_method, "/sbin/chkconfig --del nginx")
134
+ end
135
+
136
+
137
+ # Control
138
+
139
+ desc "Start Nginx"
140
+ task :start, :roles => :web do
141
+ send(run_method, "/etc/init.d/nginx start")
142
+ end
143
+
144
+ desc "Stop Nginx"
145
+ task :stop, :roles => :web do
146
+ send(run_method, "/etc/init.d/nginx stop")
147
+ end
148
+
149
+ desc "Restart Nginx"
150
+ task :restart, :roles => :web do
151
+ # So that restart will work even if nginx is not running
152
+ # we call stop and ignore the return code. We then start it.
153
+ send(run_method, "/etc/init.d/nginx stop; exit 0")
154
+ send(run_method, "/etc/init.d/nginx start")
155
+ end
156
+
157
+ desc "Reload Nginx"
158
+ task :reload, :roles => :web do
159
+ send(run_method, "/etc/init.d/nginx reload")
160
+ end
161
+
162
+ task :backup, :roles => :web do
163
+ # there's nothing to backup for nginx
164
+ end
165
+
166
+ task :restore, :roles => :web do
167
+ # there's nothing to store for nginx
168
+ end
169
+
170
+ end
171
+ end
172
+ end
@@ -0,0 +1,132 @@
1
+ # Copyright 2006-2008 by Saulius Grigaitis. All rights reserved.
2
+ Capistrano::Configuration.instance(:must_exist).load do
3
+ namespace :centos do
4
+ namespace :postgresql do
5
+
6
+ # Installation
7
+ desc "Install postgresql"
8
+ task :install, :roles => :db do
9
+ install_deps
10
+ #that's hack to initialize database (this should be replaced with initdb or so)
11
+ start
12
+ config_gen
13
+ config
14
+ restart
15
+ end
16
+
17
+ # Install dependencies for PostgreSQL
18
+ task :install_deps, :roles => :db do
19
+ apt.install( {:base => %w(postgresql postgresql-server postgresql-devel)}, :stable )
20
+ gem2.install "ruby-pg"
21
+ gem2.install "postgres"
22
+ end
23
+
24
+ desc "Create Database"
25
+ task :create_db, :roles => :db do
26
+ read_config
27
+ createuser(db_user, db_password)
28
+ createdb(db_name, db_user)
29
+ end
30
+
31
+ desc "Create DB according to production settings in database.yml"
32
+ task :setup_db do
33
+ top.centos.postgresql.activate
34
+ top.centos.postgresql.start
35
+ top.centos.postgresql.create_db
36
+ end
37
+
38
+
39
+ # Configuration
40
+
41
+ SYSTEM_CONFIG_FILES[:postgresql] = [
42
+
43
+ {:template => "pg_hba.conf.erb",
44
+ :path => '/var/lib/pgsql/data/pg_hba.conf',
45
+ :mode => 0644,
46
+ :owner => 'root:root'}
47
+ ]
48
+
49
+ desc "Generate configuration file(s) for postgresql from template(s)"
50
+ task :config_gen do
51
+ SYSTEM_CONFIG_FILES[:postgresql].each do |file|
52
+ deprec2.render_template(:postgresql, file)
53
+ end
54
+ end
55
+
56
+ desc "Push postgresql config files to server"
57
+ task :config, :roles => :db do
58
+ deprec2.push_configs(:postgresql, SYSTEM_CONFIG_FILES[:postgresql])
59
+ end
60
+
61
+ task :activate, :roles => :db do
62
+ send(run_method, "/sbin/chkconfig --add postgresql")
63
+ send(run_method, "/sbin/chkconfig postgresql on")
64
+ end
65
+
66
+ task :deactivate, :roles => :db do
67
+ send(run_method, "/sbin/chkconfig --del postgresql")
68
+ end
69
+
70
+ # Control
71
+
72
+ desc "Start PostgreSQL"
73
+ task :start, :roles => :db do
74
+ send(run_method, "/etc/init.d/postgresql start")
75
+ end
76
+
77
+ desc "Stop PostgreSQL"
78
+ task :stop, :roles => :db do
79
+ send(run_method, "/etc/init.d/postgresql stop")
80
+ end
81
+
82
+ desc "Restart PostgreSQL"
83
+ task :restart, :roles => :db do
84
+ send(run_method, "/etc/init.d/postgresql restart")
85
+ end
86
+
87
+ desc "Reload PostgreSQL"
88
+ task :reload, :roles => :db do
89
+ send(run_method, "/etc/init.d/postgresql reload")
90
+ end
91
+
92
+ task :backup, :roles => :db do
93
+ end
94
+
95
+ task :restore, :roles => :db do
96
+ end
97
+
98
+ end
99
+ end
100
+
101
+ # Imported from Rails Machine gem (Copyright (c) 2006 Bradley Taylor, bradley@railsmachine.com)
102
+
103
+ def createdb(db, user)
104
+ sudo "su - postgres -c \'createdb -O #{user} #{db}\'"
105
+ end
106
+
107
+ def createuser(user, password)
108
+ cmd = "su - postgres -c \'createuser -P -D -A -E #{user}\'"
109
+ sudo cmd do |channel, stream, data|
110
+ if data =~ /^Enter password for new/
111
+ channel.send_data "#{password}\n"
112
+ end
113
+ if data =~ /^Enter it again:/
114
+ channel.send_data "#{password}\n"
115
+ end
116
+ if data =~ /^Shall the new role be allowed to create more new roles?/
117
+ channel.send_data "n\n"
118
+ end
119
+ end
120
+ end
121
+
122
+ def command(sql, database)
123
+ run "psql --command=\"#{sql}\" #{database}"
124
+ end
125
+
126
+ def read_config
127
+ db_config = YAML.load_file('config/database.yml')
128
+ set :db_user, db_config[rails_env]["username"]
129
+ set :db_password, db_config[rails_env]["password"]
130
+ set :db_name, db_config[rails_env]["database"]
131
+ end
132
+ end