ScholarNexus-ec2onrails 0.9.10

Sign up to get free protection for your applications and to get access to all the features.
Files changed (168) hide show
  1. data/CHANGELOG +180 -0
  2. data/COPYING +339 -0
  3. data/Manifest +167 -0
  4. data/README.textile +211 -0
  5. data/Rakefile +37 -0
  6. data/TODO +104 -0
  7. data/ec2onrails.gemspec +42 -0
  8. data/examples/Capfile +3 -0
  9. data/examples/deploy.rb +107 -0
  10. data/examples/s3.yml +9 -0
  11. data/lib/ec2onrails/capistrano_utils.rb +43 -0
  12. data/lib/ec2onrails/recipes/db.rb +359 -0
  13. data/lib/ec2onrails/recipes/deploy.rb +30 -0
  14. data/lib/ec2onrails/recipes/server.rb +489 -0
  15. data/lib/ec2onrails/recipes.rb +141 -0
  16. data/lib/ec2onrails/version.rb +31 -0
  17. data/lib/ec2onrails.rb +20 -0
  18. data/server/build-ec2onrails.sh +44 -0
  19. data/server/files/etc/aliases +5 -0
  20. data/server/files/etc/aliases.db +0 -0
  21. data/server/files/etc/apache2/apache2.conf +295 -0
  22. data/server/files/etc/apache2/conf.d/app.proxy_cluster.conf +7 -0
  23. data/server/files/etc/apache2/conf.d/app.proxy_frontend.conf +10 -0
  24. data/server/files/etc/apache2/mods-available/proxy.conf +18 -0
  25. data/server/files/etc/apache2/sites-available/app.common +61 -0
  26. data/server/files/etc/apache2/sites-available/app.custom +0 -0
  27. data/server/files/etc/apache2/sites-available/default +14 -0
  28. data/server/files/etc/apache2/sites-available/default-ssl +19 -0
  29. data/server/files/etc/cron.d/ec2onrails +21 -0
  30. data/server/files/etc/cron.daily/app +24 -0
  31. data/server/files/etc/cron.daily/logrotate_post +19 -0
  32. data/server/files/etc/cron.hourly/app +24 -0
  33. data/server/files/etc/cron.monthly/app +24 -0
  34. data/server/files/etc/cron.weekly/app +24 -0
  35. data/server/files/etc/denyhosts.conf +628 -0
  36. data/server/files/etc/dpkg/dpkg.cfg +13 -0
  37. data/server/files/etc/ec2onrails/README +32 -0
  38. data/server/files/etc/ec2onrails/balancer_members +6 -0
  39. data/server/files/etc/ec2onrails/roles.yml +5 -0
  40. data/server/files/etc/environment +2 -0
  41. data/server/files/etc/god/app.god +40 -0
  42. data/server/files/etc/god/db.god +17 -0
  43. data/server/files/etc/god/dkim_filter.god +20 -0
  44. data/server/files/etc/god/examples/have_god_daemonize.god +18 -0
  45. data/server/files/etc/god/master.conf +35 -0
  46. data/server/files/etc/god/memcache.god +15 -0
  47. data/server/files/etc/god/notifications.god +14 -0
  48. data/server/files/etc/god/system.god +34 -0
  49. data/server/files/etc/god/web.god +38 -0
  50. data/server/files/etc/init.d/ec2-every-startup +29 -0
  51. data/server/files/etc/init.d/ec2-first-startup +36 -0
  52. data/server/files/etc/init.d/god +42 -0
  53. data/server/files/etc/init.d/nginx +78 -0
  54. data/server/files/etc/init.d/set_roles +3 -0
  55. data/server/files/etc/logrotate.d/apache2 +16 -0
  56. data/server/files/etc/logrotate.d/mongrel +11 -0
  57. data/server/files/etc/logrotate.d/nginx +11 -0
  58. data/server/files/etc/memcached.conf +47 -0
  59. data/server/files/etc/mongrel_cluster/app.yml +9 -0
  60. data/server/files/etc/motd.tail +13 -0
  61. data/server/files/etc/mysql/my.cnf +152 -0
  62. data/server/files/etc/nginx/nginx.conf +305 -0
  63. data/server/files/etc/postfix/main.cf +4 -0
  64. data/server/files/etc/rcS.d/S91ec2-first-startup +1 -0
  65. data/server/files/etc/rcS.d/S92ec2-every-startup +1 -0
  66. data/server/files/etc/rcS.d/S99set_roles +1 -0
  67. data/server/files/etc/ssh/sshd_config +94 -0
  68. data/server/files/etc/sudoers +1 -0
  69. data/server/files/etc/sudoers.full_access +26 -0
  70. data/server/files/etc/sudoers.restricted_access +28 -0
  71. data/server/files/etc/syslog.conf +69 -0
  72. data/server/files/usr/bin/god +26 -0
  73. data/server/files/usr/local/ec2onrails/COPYING +339 -0
  74. data/server/files/usr/local/ec2onrails/bin/archive_file.rb +44 -0
  75. data/server/files/usr/local/ec2onrails/bin/backup_app_db.rb +159 -0
  76. data/server/files/usr/local/ec2onrails/bin/ec2_meta_data.rb +80 -0
  77. data/server/files/usr/local/ec2onrails/bin/exec_runner +76 -0
  78. data/server/files/usr/local/ec2onrails/bin/init_services.rb +71 -0
  79. data/server/files/usr/local/ec2onrails/bin/optimize_mysql.rb +348 -0
  80. data/server/files/usr/local/ec2onrails/bin/rails_env +34 -0
  81. data/server/files/usr/local/ec2onrails/bin/rebundle.sh +70 -0
  82. data/server/files/usr/local/ec2onrails/bin/restore_app_db.rb +58 -0
  83. data/server/files/usr/local/ec2onrails/bin/set_rails_env +40 -0
  84. data/server/files/usr/local/ec2onrails/bin/set_roles.rb +87 -0
  85. data/server/files/usr/local/ec2onrails/bin/setup_web_proxy.rb +113 -0
  86. data/server/files/usr/local/ec2onrails/bin/update_hostname +40 -0
  87. data/server/files/usr/local/ec2onrails/config +30 -0
  88. data/server/files/usr/local/ec2onrails/lib/aws_helper.rb +76 -0
  89. data/server/files/usr/local/ec2onrails/lib/god_helper.rb +129 -0
  90. data/server/files/usr/local/ec2onrails/lib/god_patch.rb +43 -0
  91. data/server/files/usr/local/ec2onrails/lib/mysql_helper.rb +101 -0
  92. data/server/files/usr/local/ec2onrails/lib/roles_helper.rb +151 -0
  93. data/server/files/usr/local/ec2onrails/lib/s3_helper.rb +99 -0
  94. data/server/files/usr/local/ec2onrails/lib/utils.rb +16 -0
  95. data/server/files/usr/local/ec2onrails/lib/vendor/ini.rb +268 -0
  96. data/server/files/usr/local/ec2onrails/startup-scripts/every-startup/get-hostname.sh +23 -0
  97. data/server/files/usr/local/ec2onrails/startup-scripts/first-startup/README +5 -0
  98. data/server/files/usr/local/ec2onrails/startup-scripts/first-startup/create-dirs.sh +39 -0
  99. data/server/files/usr/local/ec2onrails/startup-scripts/first-startup/generate-default-web-cert-and-key.sh +49 -0
  100. data/server/files/usr/local/ec2onrails/startup-scripts/first-startup/misc.sh +27 -0
  101. data/server/files/usr/local/ec2onrails/startup-scripts/first-startup/prepare-mysql-data-dir.sh +24 -0
  102. data/server/files/usr/local/ec2onrails/startup-scripts/first-startup/setup-credentials.sh +29 -0
  103. data/server/files/usr/local/ec2onrails/startup-scripts/first-startup/setup-file-permissions.sh +30 -0
  104. data/server/rakefile.rb +249 -0
  105. data/setup.rb +1585 -0
  106. data/test/autobench.conf +60 -0
  107. data/test/spec/lib/s3_helper_spec.rb +134 -0
  108. data/test/spec/lib/s3_old.yml +3 -0
  109. data/test/spec/test_files/test1 +0 -0
  110. data/test/spec/test_files/test2 +0 -0
  111. data/test/test_app/Capfile +3 -0
  112. data/test/test_app/README +182 -0
  113. data/test/test_app/Rakefile +10 -0
  114. data/test/test_app/app/controllers/application.rb +7 -0
  115. data/test/test_app/app/controllers/db_fast_controller.rb +6 -0
  116. data/test/test_app/app/controllers/fast_controller.rb +5 -0
  117. data/test/test_app/app/controllers/slow_controller.rb +6 -0
  118. data/test/test_app/app/controllers/very_slow_controller.rb +6 -0
  119. data/test/test_app/app/helpers/application_helper.rb +3 -0
  120. data/test/test_app/app/helpers/db_fast_helper.rb +2 -0
  121. data/test/test_app/app/helpers/fast_helper.rb +2 -0
  122. data/test/test_app/app/helpers/slow_helper.rb +2 -0
  123. data/test/test_app/app/helpers/very_slow_helper.rb +2 -0
  124. data/test/test_app/config/boot.rb +109 -0
  125. data/test/test_app/config/database.yml +19 -0
  126. data/test/test_app/config/deploy.rb +21 -0
  127. data/test/test_app/config/environment.rb +60 -0
  128. data/test/test_app/config/environments/development.rb +21 -0
  129. data/test/test_app/config/environments/production.rb +18 -0
  130. data/test/test_app/config/environments/test.rb +19 -0
  131. data/test/test_app/config/routes.rb +27 -0
  132. data/test/test_app/db/schema.rb +7 -0
  133. data/test/test_app/doc/README_FOR_APP +2 -0
  134. data/test/test_app/public/404.html +30 -0
  135. data/test/test_app/public/500.html +30 -0
  136. data/test/test_app/public/dispatch.cgi +10 -0
  137. data/test/test_app/public/dispatch.fcgi +24 -0
  138. data/test/test_app/public/dispatch.rb +10 -0
  139. data/test/test_app/public/favicon.ico +0 -0
  140. data/test/test_app/public/images/rails.png +0 -0
  141. data/test/test_app/public/javascripts/application.js +2 -0
  142. data/test/test_app/public/javascripts/controls.js +963 -0
  143. data/test/test_app/public/javascripts/dragdrop.js +972 -0
  144. data/test/test_app/public/javascripts/effects.js +1120 -0
  145. data/test/test_app/public/javascripts/prototype.js +4225 -0
  146. data/test/test_app/public/robots.txt +1 -0
  147. data/test/test_app/script/about +3 -0
  148. data/test/test_app/script/breakpointer +3 -0
  149. data/test/test_app/script/console +3 -0
  150. data/test/test_app/script/destroy +3 -0
  151. data/test/test_app/script/generate +3 -0
  152. data/test/test_app/script/performance/benchmarker +3 -0
  153. data/test/test_app/script/performance/profiler +3 -0
  154. data/test/test_app/script/performance/request +3 -0
  155. data/test/test_app/script/plugin +3 -0
  156. data/test/test_app/script/process/inspector +3 -0
  157. data/test/test_app/script/process/reaper +3 -0
  158. data/test/test_app/script/process/spawner +3 -0
  159. data/test/test_app/script/runner +3 -0
  160. data/test/test_app/script/server +3 -0
  161. data/test/test_app/test/functional/db_fast_controller_test.rb +18 -0
  162. data/test/test_app/test/functional/fast_controller_test.rb +18 -0
  163. data/test/test_app/test/functional/slow_controller_test.rb +18 -0
  164. data/test/test_app/test/functional/very_slow_controller_test.rb +18 -0
  165. data/test/test_app/test/test_helper.rb +28 -0
  166. data/test/test_ec2onrails.rb +11 -0
  167. data/test/test_helper.rb +2 -0
  168. metadata +277 -0
@@ -0,0 +1,24 @@
1
+ #!/bin/sh
2
+
3
+ # This file is part of EC2 on Rails.
4
+ # http://rubyforge.org/projects/ec2onrails/
5
+ #
6
+ # Copyright 2007 Paul Dowman, http://pauldowman.com/
7
+ #
8
+ # EC2 on Rails is free software; you can redistribute it and/or modify
9
+ # it under the terms of the GNU General Public License as published by
10
+ # the Free Software Foundation; either version 2 of the License, or
11
+ # (at your option) any later version.
12
+ #
13
+ # EC2 on Rails is distributed in the hope that it will be useful,
14
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
+ # GNU General Public License for more details.
17
+ #
18
+ # You should have received a copy of the GNU General Public License
19
+ # along with this program. If not, see <http://www.gnu.org/licenses/>.
20
+
21
+
22
+ mkdir -p /mnt/mysql_data/tmp
23
+ chown -R mysql:mysql /mnt/mysql_data/
24
+ cp -rp /var/lib/mysql/mysql /mnt/mysql_data/
@@ -0,0 +1,29 @@
1
+ #!/bin/sh
2
+
3
+ # This file is part of EC2 on Rails.
4
+ # http://rubyforge.org/projects/ec2onrails/
5
+ #
6
+ # Copyright 2007 Paul Dowman, http://pauldowman.com/
7
+ #
8
+ # EC2 on Rails is free software; you can redistribute it and/or modify
9
+ # it under the terms of the GNU General Public License as published by
10
+ # the Free Software Foundation; either version 2 of the License, or
11
+ # (at your option) any later version.
12
+ #
13
+ # EC2 on Rails is distributed in the hope that it will be useful,
14
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
+ # GNU General Public License for more details.
17
+ #
18
+ # You should have received a copy of the GNU General Public License
19
+ # along with this program. If not, see <http://www.gnu.org/licenses/>.
20
+ #
21
+ # This file helps spread the root key so we can log in/deploy using the
22
+ # app user instead of root, but with the same ec2 key
23
+
24
+ #make sure we have the credentials
25
+ /etc/init.d/ec2-get-credentials
26
+
27
+ mkdir -p -m 700 /home/app/.ssh
28
+ cp /root/.ssh/authorized_keys /home/app/.ssh
29
+ chown -R app:app /home/app/.ssh
@@ -0,0 +1,30 @@
1
+ #!/bin/sh
2
+
3
+ # This file is part of EC2 on Rails.
4
+ # http://rubyforge.org/projects/ec2onrails/
5
+ #
6
+ # Copyright 2007 Paul Dowman, http://pauldowman.com/
7
+ #
8
+ # EC2 on Rails is free software; you can redistribute it and/or modify
9
+ # it under the terms of the GNU General Public License as published by
10
+ # the Free Software Foundation; either version 2 of the License, or
11
+ # (at your option) any later version.
12
+ #
13
+ # EC2 on Rails is distributed in the hope that it will be useful,
14
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
+ # GNU General Public License for more details.
17
+ #
18
+ # You should have received a copy of the GNU General Public License
19
+ # along with this program. If not, see <http://www.gnu.org/licenses/>.
20
+ #
21
+ # Some of the files will need to have additional permissions than the
22
+ # default settings, especially as the main app and deploy do not run
23
+ # under the user 'root' but instead under the user 'app'
24
+ #
25
+
26
+
27
+ chmod 777 /tmp
28
+
29
+ #make sure the god files hav the correct permissions set
30
+ chmod 700 -R /etc/god
@@ -0,0 +1,249 @@
1
+ # This file is part of EC2 on Rails.
2
+ # http://rubyforge.org/projects/ec2onrails/
3
+ #
4
+ # Copyright 2007 Paul Dowman, http://pauldowman.com/
5
+ #
6
+ # EC2 on Rails is free software; you can redistribute it and/or modify
7
+ # it under the terms of the GNU General Public License as published by
8
+ # the Free Software Foundation; either version 2 of the License, or
9
+ # (at your option) any later version.
10
+ #
11
+ # EC2 on Rails 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
14
+ # GNU General Public License for more details.
15
+ #
16
+ # You should have received a copy of the GNU General Public License
17
+ # along with this program. If not, see <http://www.gnu.org/licenses/>.
18
+
19
+
20
+ # This script is meant to be run by build-ec2onrails.sh, which is run by
21
+ # Eric Hammond's Ubuntu build script: http://alestic.com/
22
+ # e.g.:
23
+ # bash /mnt/ec2ubuntu-build-ami --script /mnt/ec2onrails/server/build-ec2onrails.sh ...
24
+
25
+
26
+
27
+ require "rake/clean"
28
+ require 'yaml'
29
+ require 'erb'
30
+ require "#{File.dirname(__FILE__)}/../lib/ec2onrails/version"
31
+
32
+ if `whoami`.strip != 'root'
33
+ raise "Sorry, this buildfile must be run as root."
34
+ end
35
+
36
+ # package notes:
37
+ # * aptitude: much better package installation system, especially around
38
+ # upgrades and package dependencies
39
+ # * gcc: libraries needed to compile c/c++ files from source
40
+ # * libmysqlclient-dev : provide mysqlclient-dev libs, needed for DataObject gems
41
+ # * nano/vim/less: simle file editors and viewer
42
+ # * git-core: because we are all using git now, aren't we?
43
+ # * xfsprogs: help with freezing and resizing of persistent volumes
44
+ #
45
+
46
+ @packages = %w(
47
+ adduser
48
+ apache2
49
+ aptitude
50
+ bison
51
+ ca-certificates
52
+ cron
53
+ curl
54
+ flex
55
+ gcc
56
+ git-core
57
+ irb
58
+ less
59
+ libdbm-ruby
60
+ libgdbm-ruby
61
+ libmysql-ruby
62
+ libopenssl-ruby
63
+ libreadline-ruby
64
+ libruby
65
+ libssl-dev
66
+ libyaml-ruby
67
+ libzlib-ruby
68
+ logrotate
69
+ make
70
+ mailx
71
+ memcached
72
+ mysql-client
73
+ mysql-server
74
+ nano
75
+ openssh-server
76
+ postfix
77
+ rdoc
78
+ ri
79
+ rsync
80
+ ruby
81
+ ruby1.8-dev
82
+ subversion
83
+ sysstat
84
+ unzip
85
+ vim
86
+ wget
87
+ xfsprogs
88
+ )
89
+
90
+ # HACK: some packages just fail with apt-get but work fine
91
+ # with aptitude. These generally are virtual packages
92
+ @aptitude_packages = %w(
93
+ libmysqlclient-dev
94
+ )
95
+
96
+ # NOTE: the amazon-ec2 gem is now at github, maintained by
97
+ # grempe-amazon-ec2. Will move back to regular amazon-ec2
98
+ # gem if/when he cuts a new release with volume and snapshot
99
+ # support included
100
+ @rubygems = [
101
+ "grempe-amazon-ec2",
102
+ "aws-s3",
103
+ "god",
104
+ "RubyInline",
105
+ "memcache-client",
106
+ "mongrel",
107
+ "mongrel_cluster",
108
+ "optiflag",
109
+ "rails",
110
+ "rails -v '~> 2.2.2'",
111
+ "rails -v '~> 2.1.2'",
112
+ "rails -v '~> 2.0.5'",
113
+ "rails -v '~> 1.2.6'",
114
+ "rake"
115
+ ]
116
+
117
+ @build_root = "/mnt/build"
118
+ @fs_dir = "#{@build_root}/ubuntu"
119
+
120
+ @version = [Ec2onrails::VERSION::STRING]
121
+
122
+ task :default => :configure
123
+
124
+ desc "Removes all build files"
125
+ task :clean_all do |t|
126
+ rm_rf @build_root
127
+ end
128
+
129
+ desc "Use apt-get to install required packages inside the image's filesystem"
130
+ task :install_packages do |t|
131
+ unless_completed(t) do
132
+ ENV['DEBIAN_FRONTEND'] = 'noninteractive'
133
+ ENV['LANG'] = ''
134
+ run_chroot "apt-get install -y #{@packages.join(' ')}"
135
+ run_chroot "apt-get clean"
136
+
137
+ #lets run the aptitude-only packages
138
+ run_chroot "aptitude install -y #{@aptitude_packages.join(' ')}"
139
+ run_chroot "aptitude clean"
140
+ end
141
+ end
142
+
143
+ desc "Install required ruby gems inside the image's filesystem"
144
+ task :install_gems => [:install_packages] do |t|
145
+ unless_completed(t) do
146
+ run_chroot "sh -c 'cd /tmp && wget -q http://rubyforge.org/frs/download.php/45905/rubygems-1.3.1.tgz && tar zxf rubygems-1.3.1.tgz'"
147
+ run_chroot "sh -c 'cd /tmp/rubygems-1.3.1 && ruby setup.rb'"
148
+ run_chroot "ln -sf /usr/bin/gem1.8 /usr/bin/gem"
149
+ #NOTE: this will update to rubygems 1.3 and beyond...
150
+ # this was broken in rubygems 1.1 and 1.2, but it looks like they fixed it
151
+ run_chroot "gem update --system --no-rdoc --no-ri"
152
+ run_chroot "gem update --no-rdoc --no-ri"
153
+ run_chroot "gem sources -a http://gems.github.com"
154
+ # run_chroot "cp /root/.gemrc /home/app" # so the app user also has access to gems.github.com
155
+ @rubygems.each do |g|
156
+ run_chroot "gem install #{g} --no-rdoc --no-ri"
157
+ end
158
+ end
159
+ end
160
+
161
+ desc "Configure the image"
162
+ task :configure => [:install_gems] do |t|
163
+ unless_completed(t) do
164
+ sh("cp -r files/* #{@fs_dir}")
165
+ replace("#{@fs_dir}/etc/motd.tail", /!!VERSION!!/, "Version #{@version}")
166
+
167
+ run_chroot "/usr/sbin/adduser --gecos ',,,' --disabled-password app"
168
+
169
+ run "echo '. /usr/local/ec2onrails/config' >> #{@fs_dir}/root/.bashrc"
170
+ run "echo '. /usr/local/ec2onrails/config' >> #{@fs_dir}/home/app/.bashrc"
171
+
172
+ %w(mysql auth.log daemon.log kern.log mail.err mail.info mail.log mail.warn syslog user.log).each do |f|
173
+ rm_rf "#{@fs_dir}/var/log/#{f}"
174
+ run_chroot "ln -sf /mnt/log/#{f} /var/log/#{f}"
175
+ end
176
+
177
+ run "touch #{@fs_dir}/ec2onrails-first-boot"
178
+
179
+ # TODO find out the most correct solution here, there seems to be a bug in
180
+ # both feisty and gutsy where the dhcp daemon runs as dhcp but the dir
181
+ # that it tries to write to is owned by root and not writable by others.
182
+ # *** Do we still need this? The problem was constant messages in the syslog
183
+ # after the first DHCP lease expired (after 12 hours or so).
184
+ # We can probably assume Eric's base image does the right thing.
185
+ run_chroot "chown -R dhcp /var/lib/dhcp3"
186
+
187
+ #make sure that god is setup to reboot at startup
188
+ run_chroot "update-rc.d god defaults 98"
189
+ end
190
+ end
191
+
192
+ desc "This task is for deploying the contents of /files to a running server image to test config file changes without rebuilding."
193
+ task :deploy_files do |t|
194
+ raise "need 'key' and 'host' env vars defined" unless ENV['key'] && ENV['host']
195
+ run "rsync -rlvzcCp --rsh='ssh -l root -i #{ENV['key']}' files/ #{ENV['host']}:/"
196
+ end
197
+
198
+ ##################
199
+
200
+ # Execute a given block and touch a stampfile. The block won't be run if the stampfile exists.
201
+ def unless_completed(task, &proc)
202
+ stampfile = "#{@build_root}/#{task.name}.completed"
203
+ unless File.exists?(stampfile)
204
+ yield
205
+ touch stampfile
206
+ end
207
+ end
208
+
209
+ def run_chroot(command, ignore_error = false)
210
+ run "chroot '#{@fs_dir}' #{command}", ignore_error
211
+ end
212
+
213
+ def run(command, ignore_error = false)
214
+ puts "*** #{command}"
215
+ result = system command
216
+ raise("error: #{$?}") unless result || ignore_error
217
+ end
218
+
219
+ # def mount(type, mount_point)
220
+ # unless mounted?(mount_point)
221
+ # puts
222
+ # puts "********** Mounting #{type} on #{mount_point}..."
223
+ # puts
224
+ # run "mount -t #{type} none #{mount_point}"
225
+ # end
226
+ # end
227
+ #
228
+ # def mounted?(mount_point)
229
+ # mount_point_regex = mount_point.gsub(/\//, "\\/")
230
+ # `mount`.select {|line| line.match(/#{mount_point_regex}/) }.any?
231
+ # end
232
+
233
+ def replace_line(file, newline, linenum)
234
+ contents = File.open(file, 'r').readlines
235
+ contents[linenum - 1] = newline
236
+ File.open(file, 'w') do |f|
237
+ contents.each {|line| f << line}
238
+ end
239
+ end
240
+
241
+ def replace(file, pattern, text)
242
+ contents = File.open(file, 'r').readlines
243
+ contents.each do |line|
244
+ line.gsub!(pattern, text)
245
+ end
246
+ File.open(file, 'w') do |f|
247
+ contents.each {|line| f << line}
248
+ end
249
+ end