slingshot 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,545 @@
1
+ # This library file includes tasks for setting up a Slingshot server.
2
+ #
3
+ # TODO:
4
+ # * use rails pids dir construct (relinks and change mongrel config)
5
+ #
6
+
7
+ Capistrano.configuration(:must_exist).load do
8
+
9
+ set :src_home, "/usr/local/src"
10
+
11
+ set :apache2, "httpd-2.2.4"
12
+ set :apache2_url, "http://www.apache.org/dist/httpd/#{apache2}.tar.gz"
13
+ set :readline_lib, "readline-5.1"
14
+ set :readline_lib_url, "ftp://ftp.gnu.org/gnu/readline/#{readline_lib}.tar.gz"
15
+ set :ruby, "ruby-1.8.5-p2"
16
+ set :ruby_url, "http://ftp.ruby-lang.org/pub/ruby/1.8/#{ruby}.tar.gz"
17
+ set :ruby_gems, "rubygems-0.9.2"
18
+ set :ruby_gems_url, "http://rubyforge.iasi.roedu.net/files/rubygems/#{ruby_gems}.tgz"
19
+
20
+ desc "The Slingshot Setup Script"
21
+ task :slingshot_setup do
22
+ edit_host_files
23
+ yum_update_system
24
+ add_users
25
+ install_apache2
26
+ install_ruby_and_rubygems
27
+ install_gems
28
+ create_startup_files_and_entries
29
+ setup_apache2_start_script
30
+ set_timezone_and_ntpdate
31
+ end
32
+
33
+ desc "Edit the host files with correct server names"
34
+ task :edit_host_files do
35
+
36
+ # backup file first
37
+ run "cp /etc/hosts ~/hosts.backup"
38
+
39
+ etc_hosts_file = render :template => <<-EOF
40
+ # Do not remove the following line, or various programs
41
+ # that require network functionality will fail.
42
+ 127.0.0.1 localhost.localdomain localhost
43
+ #{server_ip} #{server_fqdn} #{server_fqdn.split('.').first}
44
+ EOF
45
+
46
+ put etc_hosts_file, "/etc/hosts"
47
+
48
+ run "cp /etc/sysconfig/network ~/network.backup"
49
+ etc_sysconfig_network = render :template => <<-EOF
50
+ NETWORKING=yes
51
+ HOSTNAME=#{server_fqdn}
52
+ EOF
53
+ put etc_sysconfig_network, "/etc/sysconfig/network"
54
+ end
55
+
56
+ desc "Use yum to update the system"
57
+ task :yum_update_system do
58
+
59
+ # this fails on a large update, just needs to be run again
60
+ begin
61
+ run "yum -y update"
62
+ rescue
63
+ retry
64
+ end
65
+
66
+ run "yum -y install curl lynx gcc mysql mysql-server mysql-devel postfix subversion mod_dav_svn monit rdiff-backup zlib zlib-devel openssl openssl-devel ImageMagick ImageMagick-devel ntp"
67
+ end
68
+
69
+ desc "Add default users"
70
+ task :add_users do
71
+ run "useradd -m -G users,wheel -s /bin/bash #{deploy_username}"
72
+ run "echo #{deploy_password} | passwd deploy --stdin"
73
+
74
+ # make the wheel group be able to use sudo with password
75
+ run "echo '%wheel ALL=(ALL) ALL' >> /etc/sudoers"
76
+ end
77
+
78
+ desc "Install Apache 2.2.x from source"
79
+ task :install_apache2 do
80
+ run "cd #{src_home} && wget #{apache2_url}"
81
+ run "cd #{src_home} && tar xzvf #{apache2}.tar.gz"
82
+ run "cd #{src_home}/#{apache2} && ./configure --prefix=/usr/local/apache2 --enable-deflate --enable-proxy --enable-proxy-html --enable-proxy-balancer --enable-rewrite --enable-cache --enable-mem-cache --enable-ssl --enable-headers"
83
+ run "cd #{src_home}/#{apache2} && make"
84
+ run "cd #{src_home}/#{apache2} && make install"
85
+ run "cd #{src_home}/#{apache2} && install -b support/apachectl /etc/init.d/apache2"
86
+ end
87
+
88
+ desc "Install Ruby, RubyGems and depdendencies (readline)"
89
+ task :install_ruby_and_rubygems do
90
+ run "cd #{src_home} && wget #{readline_lib_url}"
91
+ run "cd #{src_home} && tar xzvf #{readline_lib}.tar.gz"
92
+ run "cd #{src_home}/#{readline_lib} && ./configure --prefix=/usr/local"
93
+ run "cd #{src_home}/#{readline_lib} && make"
94
+ run "cd #{src_home}/#{readline_lib} && make install"
95
+
96
+ run "cd #{src_home} && wget #{ruby_url}"
97
+ run "cd #{src_home} && tar xzvf #{ruby}.tar.gz"
98
+ # not necessary to patch anymore
99
+ # run "wget http://ftp.ruby-lang.org/pub/ruby/1.8/ruby-1.8.5-cgi-dos-1.patch"
100
+ # run "patch -p0 < ruby-1.8.5-cgi-dos-1.patch"
101
+ run "cd #{src_home}/#{ruby} && ./configure --prefix=/usr/local --enable-pthread --with-readline-dir=/usr/local"
102
+ run "cd #{src_home}/#{ruby} && make"
103
+ run "cd #{src_home}/#{ruby} && make install"
104
+ run "cd #{src_home}/#{ruby} && make install-doc"
105
+
106
+ run "cd #{src_home} && wget #{ruby_gems_url}"
107
+ run "cd #{src_home} && tar xzvf #{ruby_gems}.tgz"
108
+ run "cd #{src_home}/#{ruby_gems} && /usr/local/bin/ruby setup.rb"
109
+ end
110
+
111
+ desc "Install gems"
112
+ task :install_gems do
113
+
114
+ # this sometimes fails on first attempt, just retry
115
+ begin
116
+ gem.install 'rails'
117
+ rescue
118
+ retry
119
+ end
120
+
121
+ # sudo gem install mysql --version 2.7 -- --with-mysql-config
122
+ gem.select 'mysql', :version => '2.7', :platform => 'ruby', :extra_params => '-- --with-mysql-config'
123
+
124
+ # sudo gem install mongrel --version 1.0.1
125
+ gem.select 'mongrel', :version => '1.0.1', :platform => 'ruby'
126
+
127
+ gem.install 'mongrel_cluster'
128
+
129
+ gem.install 'net-ssh capistrano termios rmagick RedCloth BlueCloth'
130
+ end
131
+
132
+ desc "Create directories, links, startup files"
133
+ task :create_startup_files_and_entries do
134
+ run "ln -s /usr/local/lib/ruby/gems/1.8/gems/mongrel_cluster-0.2.1/resources/mongrel_cluster /etc/init.d/mongrel_cluster"
135
+ run "chmod +x /etc/init.d/mongrel_cluster"
136
+ run "/sbin/chkconfig --level 345 mongrel_cluster on"
137
+
138
+ run "mkdir -p /etc/rails"
139
+ run "chown deploy -R /etc/rails"
140
+ # run "chgrp deploy -R /etc/rails"
141
+
142
+ run "echo \"\" >> /usr/local/apache2/conf/httpd.conf"
143
+ run "echo \"# Added by Slingshot Install script\" >> /usr/local/apache2/conf/httpd.conf"
144
+ run "echo \"Include /etc/rails/*.conf\" >> /usr/local/apache2/conf/httpd.conf"
145
+ run "echo \"NameVirtualHost *:80\" >> /usr/local/apache2/conf/httpd.conf"
146
+
147
+ run "/etc/init.d/mysqld start"
148
+ run "/sbin/chkconfig mysqld on"
149
+
150
+ # sendmail
151
+ run "/etc/init.d/sendmail start"
152
+ run "/sbin/chkconfig sendmail on"
153
+ end
154
+
155
+ desc "Setup timezone and ntpdate"
156
+ task :set_timezone_and_ntpdate do
157
+ run "cp /usr/share/zoneinfo/#{server_timezone} /etc/localtime"
158
+ run "/usr/sbin/ntpdate 0.pool.ntp.org"
159
+ end
160
+
161
+ desc "Setup Apache2 start script"
162
+ task :setup_apache2_start_script do
163
+
164
+ apache2_start_script = render :template => <<-EOF
165
+ #!/bin/bash
166
+ #
167
+ # apache2 Startup script for the Apache HTTP Server
168
+ #
169
+ # chkconfig: - 85 15
170
+ # description: Apache is a World Wide Web server. It is used to serve \
171
+ # HTML files and CGI.
172
+ # processname: apache2
173
+ # config: /usr/local/apache2/conf/apache2.conf
174
+ # config: /etc/sysconfig/apache2
175
+ # pidfile: /var/run/apache2.pid
176
+
177
+ # Source function library.
178
+ . /etc/rc.d/init.d/functions
179
+
180
+ if [ -f /etc/sysconfig/httpd ]; then
181
+ . /etc/sysconfig/httpd
182
+ fi
183
+
184
+ # Start httpd in the C locale by default.
185
+ HTTPD_LANG=${HTTPD_LANG-"C"}
186
+
187
+ # This will prevent initlog from swallowing up a pass-phrase prompt if
188
+ # mod_ssl needs a pass-phrase from the user.
189
+ INITLOG_ARGS=""
190
+
191
+ # Set HTTPD=/usr/sbin/httpd.worker in /etc/sysconfig/httpd to use a server
192
+ # with the thread-based "worker" MPM; BE WARNED that some modules may not
193
+ # work correctly with a thread-based MPM; notably PHP will refuse to start.
194
+
195
+ # Path to the apachectl script, server binary, and short-form for messages.
196
+ apachectl=/usr/local/apache2/bin/apachectl
197
+ apache2=${HTTPD-/usr/local/apache2/bin/apache2}
198
+ prog=apache2
199
+ pidfile=${PIDFILE-/var/run/apache2.pid}
200
+ lockfile=${LOCKFILE-/var/lock/subsys/apache2}
201
+ RETVAL=0
202
+
203
+ # check for 1.3 configuration
204
+ check13 () {
205
+ CONFFILE=/etc/httpd/conf/httpd.conf
206
+ GONE="(ServerType|BindAddress|Port|AddModule|ClearModuleList|"
207
+ GONE="${GONE}AgentLog|RefererLog|RefererIgnore|FancyIndexing|"
208
+ GONE="${GONE}AccessConfig|ResourceConfig)"
209
+ if LANG=C grep -Eiq "^[[:space:]]*($GONE)" $CONFFILE; then
210
+ echo
211
+ echo 1>&2 " Apache 1.3 configuration directives found"
212
+ echo 1>&2 " please read /usr/share/doc/httpd-2.0.52/migration.html"
213
+ failure "Apache 1.3 config directives test"
214
+ echo
215
+ exit 1
216
+ fi
217
+ }
218
+
219
+ # The semantics of these two functions differ from the way apachectl does
220
+ # things -- attempting to start while running is a failure, and shutdown
221
+ # when not running is also a failure. So we just do it the way init scripts
222
+ # are expected to behave here.
223
+ start() {
224
+ echo -n $"Starting $prog: "
225
+ check13 || exit 1
226
+ LANG=$HTTPD_LANG daemon $apache2 $OPTIONS
227
+ RETVAL=$?
228
+ echo
229
+ [ $RETVAL = 0 ] && touch ${lockfile}
230
+ return $RETVAL
231
+ }
232
+ stop() {
233
+ echo -n $"Stopping $prog: "
234
+ killproc $apache2
235
+ RETVAL=$?
236
+ echo
237
+ [ $RETVAL = 0 ] && rm -f ${lockfile} ${pidfile}
238
+ }
239
+ reload() {
240
+ echo -n $"Reloading $prog: "
241
+ if ! LANG=$HTTPD_LANG $apache2 $OPTIONS -t >&/dev/null; then
242
+ RETVAL=$?
243
+ echo $"not reloading due to configuration syntax error"
244
+ failure $"not reloading $apache2 due to configuration syntax error"
245
+ else
246
+ killproc $apache2 -HUP
247
+ RETVAL=$?
248
+ fi
249
+ echo
250
+ }
251
+
252
+ # See how we were called.
253
+ case "$1" in
254
+ start)
255
+ start
256
+ ;;
257
+ stop)
258
+ stop
259
+ ;;
260
+ status)
261
+ status $apache2
262
+ RETVAL=$?
263
+ ;;
264
+ restart)
265
+ stop
266
+ start
267
+ ;;
268
+ condrestart)
269
+ if [ -f ${pidfile} ] ; then
270
+ stop
271
+ start
272
+ fi
273
+ ;;
274
+ reload)
275
+ reload
276
+ ;;
277
+ graceful|help|configtest|fullstatus)
278
+ $apachectl $@
279
+ RETVAL=$?
280
+ ;;
281
+ *)
282
+ echo $"Usage: $prog {start|stop|restart|condrestart|reload|status|fullstatus|graceful|help|configtest}"
283
+ exit 1
284
+ esac
285
+
286
+ exit $RETVAL
287
+ EOF
288
+
289
+ # rename/link httpd binary apache2 for redhat ES / CentOS to behave
290
+ run "ln -s /usr/local/apache2/bin/httpd /usr/local/apache2/bin/apache2"
291
+ # run "curl -Os #{apache2_start_script}"
292
+ # run "cp #{File.basename(apache2_start_script)} /etc/init.d/apache2"
293
+ put apache2_start_script, "/etc/init.d/apache2"
294
+ run "chmod +x /etc/init.d/apache2"
295
+ run "/etc/init.d/apache2 start"
296
+ run "/sbin/chkconfig apache2 on"
297
+ end
298
+
299
+ desc "Setup monit daemon monitoring"
300
+ task :setup_monit do
301
+
302
+ monit_configuration = render :template => <<-EOF
303
+ # This monit configuration was generated dynamically
304
+ #
305
+ EOF
306
+
307
+ (0..mongrel_servers-1).each do |server|
308
+ monit_configuration +=<<-EOF
309
+ check process mongrel-#{mongrel_start_port + server} with pidfile #{deploy_to}/current/log/mongrel.#{mongrel_start_port + server}.pid
310
+ group mongrel
311
+ start program = "/usr/local/bin/ruby /usr/local/bin/mongrel_rails start -d -e production -p #{mongrel_start_port + server} -a 127.0.0.1 -l #{deploy_to}/current/log/mongrel.log -P #{deploy_to}/shared/log/mongrel.#{mongrel_start_port + server}.pid -c #{deploy_to}/current"
312
+ stop program = "/usr/local/bin/ruby /usr/local/bin/mongrel_rails stop -P #{deploy_to}/shared/log/mongrel.#{mongrel_start_port + server}.pid"
313
+ if totalmem > 100.0 MB for 5 cycles then restart
314
+ if failed port #{mongrel_start_port + server} protocol http with timeout 30 seconds then restart
315
+
316
+ EOF
317
+ end
318
+
319
+ put monit_configuration, "/etc/monit.d/rails.conf"
320
+
321
+ end
322
+
323
+ desc "Setup Apache Configuration"
324
+ task :apache_configuration_setup do
325
+
326
+ # generate web server configuration (apache specific)
327
+ apache2_rails_conf = <<-EOF
328
+ <VirtualHost *:80>
329
+ Include /etc/rails/#{application}.common
330
+
331
+ ErrorLog #{path_to_web_server}logs/#{application}_errors_log
332
+ CustomLog #{path_to_web_server}logs/#{application}_log combined
333
+ </VirtualHost>
334
+ EOF
335
+
336
+
337
+ if configure_ssl
338
+ apache2_rails_conf +=<<-EOF
339
+ Listen 443
340
+ <VirtualHost _default_:443>
341
+ Include /etc/rails/#{application}.common
342
+
343
+ RequestHeader set X_FORWARDED_PROTO 'https'
344
+
345
+ SSLEngine on
346
+ SSLCipherSuite ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP:+eNULL
347
+
348
+ # Server Certificate and CA:
349
+ SSLCertificateFile #{path_to_web_server}conf/ssl/#{ssl_certificate_file}
350
+ SSLCertificateKeyFile #{path_to_web_server}conf/ssl/#{ssl_certificate_key_file}
351
+ SSLCACertificateFile #{path_to_web_server}conf/ssl/#{ssl_ca_certificate_file}
352
+
353
+ <IfModule setenvif_module>
354
+ BrowserMatch ".*MSIE.*" \
355
+ nokeepalive ssl-unclean-shutdown \
356
+ downgrade-1.0 force-response-1.0
357
+ </IfModule>
358
+ </VirtualHost>
359
+ EOF
360
+ end
361
+
362
+ apache2_rails_conf +=<<-EOF
363
+ <Proxy balancer://#{application}_mongrel_cluster>
364
+ EOF
365
+
366
+ # builds the following as an example with start port 8000 and servers = 3:
367
+ # <Proxy balancer://mongrel_cluster>
368
+ # BalancerMember http://127.0.0.1:8000
369
+ # BalancerMember http://127.0.0.1:8001
370
+ # BalancerMember http://127.0.0.1:8002
371
+ # </Proxy>
372
+ (0..mongrel_servers-1).each { |server|
373
+ apache2_rails_conf += " BalancerMember http://127.0.0.1:#{mongrel_start_port + server}\n"
374
+ }
375
+
376
+ apache2_rails_conf +=<<-EOF
377
+ </Proxy>
378
+
379
+ Listen #{mongrel_start_port + 81}
380
+ <VirtualHost *:#{mongrel_start_port + 81}>
381
+ <Location />
382
+ SetHandler balancer-manager
383
+ Deny from all
384
+ Allow from localhost
385
+ </Location>
386
+ </VirtualHost>
387
+ EOF
388
+
389
+ apache2_rails_configuration = render :template => apache2_rails_conf
390
+
391
+ apache2_rails_common = render :template => <<-EOF
392
+ ServerName #{server_name}
393
+ ServerAlias www.#{server_name}
394
+ DocumentRoot #{deploy_to}/current/public
395
+
396
+ <Directory "#{deploy_to}/current/public">
397
+ Options FollowSymLinks
398
+ AllowOverride None
399
+ Order allow,deny
400
+ Allow from all
401
+ </Directory>
402
+
403
+ RewriteEngine On
404
+
405
+ # Uncomment for rewrite debugging
406
+ #RewriteLog logs/#{application}_rewrite_log
407
+ #RewriteLogLevel 9
408
+
409
+ # Check for maintenance file and redirect all requests
410
+ RewriteCond %{DOCUMENT_ROOT}/system/maintenance.html -f
411
+ RewriteCond %{SCRIPT_FILENAME} !maintenance.html
412
+ RewriteRule ^.*$ /system/maintenance.html [L]
413
+
414
+ # Rewrite index to check for static
415
+ RewriteRule ^/$ /index.html [QSA]
416
+
417
+ # Rewrite to check for Rails cached page
418
+ RewriteRule ^([^.]+)$ $1.html [QSA]
419
+
420
+ # Redirect all non-static requests to cluster
421
+ RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME} !-f
422
+ RewriteRule ^/(.*)$ balancer://#{application}_mongrel_cluster%{REQUEST_URI} [P,QSA,L]
423
+
424
+ # Deflate
425
+ AddOutputFilterByType DEFLATE text/html text/plain text/xml application/xml application/xhtml+xml text/javascript text/css
426
+ BrowserMatch ^Mozilla/4 gzip-only-text/html
427
+ BrowserMatch ^Mozilla/4.0[678] no-gzip
428
+ BrowserMatch \\bMSIE !no-gzip !gzip-only-text/html
429
+
430
+ # Uncomment for deflate debugging
431
+ #DeflateFilterNote Input input_info
432
+ #DeflateFilterNote Output output_info
433
+ #DeflateFilterNote Ratio ratio_info
434
+ #LogFormat '"%r" %{output_info}n/%{input_info}n (%{ratio_info}n%%)' deflate
435
+ #CustomLog logs/#{application}_deflate_log deflate
436
+
437
+ EOF
438
+
439
+ put apache2_rails_configuration, "#{deploy_to}/#{shared_dir}/system/#{application}.conf"
440
+ put apache2_rails_common, "#{deploy_to}/#{shared_dir}/system/#{application}.common"
441
+
442
+ # if apache is setup to read /etc/rails/*.conf these will get read as configuration files
443
+ # see prerequisites above for more info
444
+ sudo "ln -nfs #{deploy_to}/#{shared_dir}/system/#{application}.conf /etc/rails/#{application}.conf"
445
+ sudo "ln -nfs #{deploy_to}/#{shared_dir}/system/#{application}.common /etc/rails/#{application}.common"
446
+
447
+ end
448
+
449
+ desc "Apache Redirects for ensuring www.servername.com answers"
450
+ task :apache_redirects_setup do
451
+
452
+ if redirect_www_requests
453
+ redirect_apache2_rails_conf = <<-EOF
454
+ <VirtualHost *:80>
455
+ ServerName #{domain_name}
456
+ ServerAlias www.#{domain_name}
457
+ ServerAdmin support@#{domain_name}
458
+ RedirectPermanent / "http://www.#{domain_name}/"
459
+ </VirtualHost>
460
+
461
+ EOF
462
+
463
+ redirect_apache2_rails_configuration = render :template => redirect_apache2_rails_conf
464
+
465
+ put redirect_apache2_rails_configuration, "#{deploy_to}/#{shared_dir}/system/redirects.conf"
466
+
467
+ # since apache is setup to read /etc/rails/*.conf these will get read as configuration files
468
+ sudo "ln -nfs #{deploy_to}/#{shared_dir}/system/redirects.conf /etc/rails/redirects.conf"
469
+ end
470
+ end
471
+
472
+ desc "Setup crontab Configuration"
473
+ task :crontab_configuration_setup do
474
+
475
+ if overwrite_crontab
476
+
477
+ # setup crontab file
478
+ crontab_file = render :template => <<-EOF
479
+ # WARNING: this file has been automatically setup by the Capistrano script
480
+ # Please make changes there and rerun setup, not here, as they will be overwritten....
481
+ #
482
+ # Global variables
483
+ SHELL=/bin/bash
484
+ PATH=/sbin:/bin:/usr/sbin:/usr/bin
485
+ MAILTO=#{crontab_email}
486
+ HOME=/
487
+
488
+ # check scripts in cron.hourly, cron.daily, cron.weekly and cron.monthly
489
+ # minute hour dom month dow user cmd
490
+ 01 * * * * root run-parts /etc/cron.hourly
491
+ 02 4 * * * root run-parts /etc/cron.daily
492
+ 22 4 * * 0 root run-parts /etc/cron.weekly
493
+ 42 4 1 * * root run-parts /etc/cron.monthly
494
+
495
+ # this task will run every 15 minutes:
496
+ # */15 * * * * root /usr/local/bin/ruby #{deploy_to}/current/script/runner -e production 'Class.method(example)'
497
+ # this task will run every hour:
498
+ # * */1 * * * root /usr/local/bin/ruby #{deploy_to}/current/script/runner -e production 'Class.method(example)'
499
+ # this task will run at 4:00 am every day:
500
+ # 00 4 * * * root /usr/local/bin/ruby #{deploy_to}/current/script/runner -e production 'Class.method(example)'
501
+
502
+ # BACKUP tasks - to supress all output use: cd #{deploy_to}/current && rake s3:backup >/dev/null 2>&1
503
+ # every day at 3:00am:
504
+ 00 3 * * * root cd #{deploy_to}/current && /usr/local/bin/rake RAILS_ENV=production s3:backup INCREMENT=daily >> #{deploy_to}/shared/log/backup.log && /usr/local/bin/rake RAILS_ENV=production s3:manage:clean_up KEEP=7 INCREMENT=daily >> #{deploy_to}/shared/log/backup.log
505
+ # every sunday at 3:22am:
506
+ 22 3 * * 0 root cd #{deploy_to}/current && /usr/local/bin/rake RAILS_ENV=production s3:backup INCREMENT=weekly >> #{deploy_to}/shared/log/backup.log && /usr/local/bin/rake RAILS_ENV=production s3:manage:clean_up KEEP=5 INCREMENT=weekly >> #{deploy_to}/shared/log/backup.log
507
+ # every 1st of month at 3:42am:
508
+ 42 3 1 * * root cd #{deploy_to}/current && /usr/local/bin/rake RAILS_ENV=production s3:backup INCREMENT=monthly >> #{deploy_to}/shared/log/backup.log && /usr/local/bin/rake RAILS_ENV=production s3:manage:clean_up KEEP=12 INCREMENT=monthly >> #{deploy_to}/shared/log/backup.log
509
+ # every year on dec 31 at 4:00am:
510
+ 00 4 31 12 * root cd #{deploy_to}/current && /usr/local/bin/rake RAILS_ENV=production s3:backup INCREMENT=yearly >> #{deploy_to}/shared/log/backup.log && /usr/local/bin/rake RAILS_ENV=production s3:manage:clean_up KEEP=1 INCREMENT=yearly >> #{deploy_to}/shared/log/backup.log
511
+
512
+ # resync time at 2:59am:
513
+ 59 2 * * * root /usr/sbin/ntpdate 0.pool.ntp.org
514
+
515
+ EOF
516
+
517
+ put crontab_file, "#{deploy_to}/#{shared_dir}/system/crontab"
518
+
519
+ # deploy it by copying over one that exists
520
+ sudo "cp #{deploy_to}/#{shared_dir}/system/crontab /etc/crontab"
521
+
522
+ end
523
+
524
+ end
525
+
526
+ # =============================================================================
527
+ # MANUAL SETUP TASKS (WARNING: SEMI-DESTRUCTIVE TASKS)
528
+ # =============================================================================
529
+
530
+ desc "Setup mysql databases and permissions"
531
+ task :mysql_setup, :roles => [:db] do
532
+ mysql_setup_file = render :template => <<-EOF
533
+ CREATE DATABASE #{application}_development;
534
+ CREATE DATABASE #{application}_test;
535
+ CREATE DATABASE #{application}_production;
536
+ GRANT ALL PRIVILEGES ON #{application}_development.* TO '#{database_username}'@'localhost' IDENTIFIED BY '#{database_password}';
537
+ GRANT ALL PRIVILEGES ON #{application}_test.* TO '#{database_username}'@'localhost' IDENTIFIED BY '#{database_password}';
538
+ GRANT ALL PRIVILEGES ON #{application}_production.* TO '#{database_username}'@'localhost' IDENTIFIED BY '#{database_password}';
539
+ FLUSH PRIVILEGES;
540
+ EOF
541
+ put mysql_setup_file, "#{deploy_to}/#{shared_dir}/system/mysql_setup_file.sql"
542
+ run "mysql -u root < #{deploy_to}/#{shared_dir}/system/mysql_setup_file.sql"
543
+ end
544
+
545
+ end # end capistrano extensions
@@ -0,0 +1,9 @@
1
+ module Slingshot #:nodoc:
2
+ module VERSION #:nodoc:
3
+ MAJOR = 1
4
+ MINOR = 0
5
+ TINY = 0
6
+
7
+ STRING = [MAJOR, MINOR, TINY].join('.')
8
+ end
9
+ end
data/lib/slingshot.rb ADDED
@@ -0,0 +1,10 @@
1
+ require 'slingshot/version'
2
+
3
+ # main recipes
4
+ require 'slingshot/recipes'
5
+
6
+ # server setup recipes
7
+ require 'slingshot/server_setup'
8
+
9
+ # plugins, extensions, etc.
10
+ require 'slingshot/gem_cap_plugin'
data/scripts/txt2html ADDED
@@ -0,0 +1,67 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rubygems'
4
+ require 'redcloth'
5
+ require 'syntax/convertors/html'
6
+ require 'erb'
7
+ require File.dirname(__FILE__) + '/../lib/slingshot/version.rb'
8
+
9
+ version = Slingshot::VERSION::STRING
10
+ download = 'http://rubyforge.org/projects/slingshot'
11
+
12
+ class Fixnum
13
+ def ordinal
14
+ # teens
15
+ return 'th' if (10..19).include?(self % 100)
16
+ # others
17
+ case self % 10
18
+ when 1: return 'st'
19
+ when 2: return 'nd'
20
+ when 3: return 'rd'
21
+ else return 'th'
22
+ end
23
+ end
24
+ end
25
+
26
+ class Time
27
+ def pretty
28
+ return "#{mday}#{mday.ordinal} #{strftime('%B')} #{year}"
29
+ end
30
+ end
31
+
32
+ def convert_syntax(syntax, source)
33
+ return Syntax::Convertors::HTML.for_syntax(syntax).convert(source).gsub(%r!^<pre>|</pre>$!,'')
34
+ end
35
+
36
+ if ARGV.length >= 1
37
+ src, template = ARGV
38
+ template ||= File.dirname(__FILE__) + '/../website/template.rhtml'
39
+
40
+ else
41
+ puts("Usage: #{File.split($0).last} source.txt [template.rhtml] > output.html")
42
+ exit!
43
+ end
44
+
45
+ template = ERB.new(File.open(template).read)
46
+
47
+ title = nil
48
+ body = nil
49
+ File.open(src) do |fsrc|
50
+ title_text = fsrc.readline
51
+ body_text = fsrc.read
52
+ syntax_items = []
53
+ body_text.gsub!(%r!<(pre|code)[^>]*?syntax=['"]([^'"]+)[^>]*>(.*?)</>!m){
54
+ ident = syntax_items.length
55
+ element, syntax, source = $1, $2, $3
56
+ syntax_items << "<#{element} class='syntax'>#{convert_syntax(syntax, source)}</#{element}>"
57
+ "syntax-temp-#{ident}"
58
+ }
59
+ title = RedCloth.new(title_text).to_html.gsub(%r!<.*?>!,'').strip
60
+ body = RedCloth.new(body_text).to_html
61
+ body.gsub!(%r!(?:<pre><code>)?syntax-temp-(d+)(?:</code></pre>)?!){ syntax_items[$1.to_i] }
62
+ end
63
+ stat = File.stat(src)
64
+ created = stat.ctime
65
+ modified = stat.mtime
66
+
67
+ $stdout << template.result(binding)