mmmultiworks 0.1.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.
data/README ADDED
@@ -0,0 +1,8 @@
1
+ == MosquitoMoleMultiworks
2
+
3
+ Based off of the Rails Machine Gem.
4
+
5
+ Doc coming soon.
6
+
7
+
8
+
data/Rakefile ADDED
@@ -0,0 +1,54 @@
1
+ require 'rake'
2
+ require 'rake/testtask'
3
+ require 'rake/clean'
4
+ require 'rake/gempackagetask'
5
+ require 'rake/rdoctask'
6
+ require 'tools/rakehelp'
7
+ require 'fileutils'
8
+ include FileUtils
9
+
10
+ setup_tests
11
+ setup_clean ["pkg", "lib/*.bundle", "*.gem", ".config"]
12
+
13
+ setup_rdoc ['README', 'LICENSE', 'COPYING', 'lib/**/*.rb', 'doc/**/*.rdoc']
14
+
15
+ desc "Does a full compile, test run"
16
+ task :default => [:test, :package]
17
+
18
+ version="0.1.0"
19
+ name="mmmultiworks"
20
+
21
+ setup_gem(name, version) do |spec|
22
+ spec.summary = "The Mosquito Mole Multiworks task library"
23
+ spec.description = spec.summary
24
+ spec.author="Matt Bauer"
25
+ spec.add_dependency('daemons', '>= 0.3.13.0')
26
+ spec.add_dependency('termios', '>= 0.3.13.0')
27
+ spec.add_dependency('capistrano', '>= 1.1.0')
28
+ spec.add_dependency('mongrel', '>= 0.3.13.0')
29
+ spec.add_dependency('mongrel_cluster', '>= 0.2')
30
+ spec.has_rdoc = false
31
+ spec.files += Dir.glob("bin/*")
32
+ spec.files += Dir.glob("resources/**/*")
33
+ spec.default_executable = "mmmultiworks"
34
+ spec.executables = ["mmmultiworks"]
35
+ end
36
+
37
+ task :install => [:test, :package] do
38
+ sh %{sudo gem install pkg/#{name}-#{version}.gem}
39
+ end
40
+
41
+ task :uninstall => [:clean] do
42
+ sh %{sudo gem uninstall #{name}}
43
+ end
44
+
45
+ desc "Publish the release files to RubyForge."
46
+ task :release => [ :package ] do
47
+ `rubyforge login`
48
+
49
+ for ext in %w( gem tgz )
50
+ release_command = "rubyforge add_release mmmultiworks #{name} 'REL #{version}' pkg/#{name}-#{version}.#{ext}"
51
+ puts release_command
52
+ system(release_command)
53
+ end
54
+ end
data/bin/mmmultiworks ADDED
@@ -0,0 +1,35 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ begin
4
+ require 'rubygems'
5
+ rescue LoadError
6
+ # no rubygems to load, so we fail silently
7
+ end
8
+
9
+ require 'optparse'
10
+
11
+ @options = {}
12
+ OptionParser.new do |opts|
13
+ opts.banner = "Usage: #{$0} [options] [args]"
14
+
15
+ opts.on("-A", "--apply-to DIRECTORY",
16
+ "Create a minimal set of scripts and recipes",
17
+ "for use with capistrano to configure servers."
18
+ ) { |value| @options[:apply_to] = value }
19
+ opts.on("-n", "--name APPLICATION_NAME",
20
+ "Name of application."
21
+ ) { |value| @options[:application] = value }
22
+ opts.on("-d", "--domain DOMAIN_NAME",
23
+ "Domain name for application."
24
+ ) { |value| @options[:domain] = value }
25
+
26
+ if ARGV.empty?
27
+ puts opts
28
+ exit
29
+ else
30
+ opts.parse!(ARGV)
31
+ end
32
+ end
33
+
34
+ require 'mmmultiworks/generators/loader'
35
+ Mmmultiworks::Generators::RailsLoader.load! @options
@@ -0,0 +1,20 @@
1
+ module Mmmultiworks
2
+ module Generators
3
+ class RailsLoader
4
+ def self.load!(options)
5
+ require "#{options[:apply_to]}/config/environment"
6
+ require "rails_generator"
7
+ require "rails_generator/scripts/generate"
8
+
9
+ Rails::Generator::Base.sources << Rails::Generator::PathSource.new(
10
+ :mmmultiworks, File.dirname(__FILE__))
11
+
12
+ args = ["mmmultiworks"]
13
+ args << (options[:application] || "Application")
14
+ args << (options[:domain] || "my.mmmultiworks.com")
15
+
16
+ Rails::Generator::Scripts::Generate.new.run(args)
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,12 @@
1
+ NAME
2
+ mmmultiworks - creates configuration and Capistrano tasks for server configuration.
3
+
4
+ SYNOPSIS
5
+ mmmultiworks [Application name]
6
+
7
+ DESCRIPTION
8
+ This generator creates rakefiles and deployment recipes.
9
+
10
+
11
+ EXAMPLE
12
+ ./script/generate mmmultiworks MyRockinApp
@@ -0,0 +1,23 @@
1
+ class MmmultiworksGenerator < Rails::Generator::NamedBase
2
+ attr_reader :application_name
3
+ attr_reader :domain_name
4
+
5
+ def initialize(runtime_args, runtime_options = {})
6
+ super
7
+ @application_name = self.file_name
8
+ @domain_name = @args[0]
9
+ end
10
+
11
+ def manifest
12
+ record do |m|
13
+ m.directory "config"
14
+ m.template "deploy.rb", File.join("config", "deploy.rb")
15
+ end
16
+ end
17
+
18
+ protected
19
+
20
+ def banner
21
+ "Usage: #{$0} mmmultiworks ApplicationName DomainName"
22
+ end
23
+ end
@@ -0,0 +1,76 @@
1
+ require 'mmmultiworks/recipes'
2
+
3
+ # This defines a deployment "recipe" that you can feed to capistrano
4
+ # (http://manuals.rubyonrails.com/read/book/17). It allows you to automate
5
+ # (among other things) the deployment of your application.
6
+
7
+ # =============================================================================
8
+ # REQUIRED VARIABLES
9
+ # =============================================================================
10
+ # You must always specify the application and repository for every recipe. The
11
+ # repository must be the URL of the repository you want this recipe to
12
+ # correspond to. The deploy_to path must be the path on each machine that will
13
+ # form the root of the application path.
14
+
15
+ set :application, "<%= singular_name %>"
16
+ set :deploy_to, "/u/apps/#{application}"
17
+ set :domain, "<%= domain_name %>"
18
+
19
+ set :user, "deploy"
20
+ set :repository, "svn+ssh://#{user}@#{domain}#{deploy_to}/repos/trunk"
21
+ set :rails_env, "production"
22
+
23
+ # Automatically symlink these directories from curent/public to shared/public.
24
+ # set :app_symlinks, %w{photo, document, asset}
25
+
26
+ # =============================================================================
27
+ # ROLES
28
+ # =============================================================================
29
+ # You can define any number of roles, each of which contains any number of
30
+ # machines. Roles might include such things as :web, or :app, or :db, defining
31
+ # what the purpose of each machine is. You can also specify options that can
32
+ # be used to single out a specific subset of boxes in a particular role, like
33
+ # :primary => true.
34
+
35
+ role :web, domain
36
+ role :app, domain
37
+ role :db, domain, :primary => true
38
+ role :scm, domain
39
+
40
+ # =============================================================================
41
+ # APACHE OPTIONS
42
+ # =============================================================================
43
+ # set :apache_server_name, domain
44
+ # set :apache_server_aliases, %w{alias1 alias2}
45
+ # set :apache_default_vhost, true # force use of apache_default_vhost_config
46
+ # set :apache_default_vhost_conf, "/u/apache2/conf/default.conf"
47
+ # set :apache_conf, "/u/apache2/conf/apps/#{application}.conf"
48
+ # set :apache_ctl, "/usr/local/apache2/bin/apachectl -d /u/apache2 -k"
49
+ # set :apache_proxy_port, 8000
50
+ # set :apache_proxy_servers, 2
51
+ # set :apache_proxy_address, "127.0.0.1"
52
+ # set :apache_ssl_enabled, false
53
+ # set :apache_ssl_ip, "127.0.0.1"
54
+ # set :apache_ssl_forward_all, false
55
+
56
+ # =============================================================================
57
+ # MONGREL OPTIONS
58
+ # =============================================================================
59
+ # set :mongrel_servers, apache_proxy_servers
60
+ # set :mongrel_port, apache_proxy_port
61
+ # set :mongrel_address, apache_proxy_address
62
+ # set :mongrel_environment, "production"
63
+ # set :mongrel_config, "/u/mongrel_cluster/#{application}.conf"
64
+ # set :mongrel_user, user
65
+ # set :mongrel_group, group
66
+
67
+ # =============================================================================
68
+ # MYSQL OPTIONS
69
+ # =============================================================================
70
+
71
+
72
+ # =============================================================================
73
+ # SSH OPTIONS
74
+ # =============================================================================
75
+ # ssh_options[:keys] = %w(/path/to/my/key /path/to/another/key)
76
+ # ssh_options[:port] = 25
@@ -0,0 +1,120 @@
1
+ require 'mmmultiworks/recipes/svn'
2
+ require 'mmmultiworks/recipes/mysql'
3
+ require 'mmmultiworks/recipes/apache'
4
+ require 'mmmultiworks/recipes/mongrel'
5
+
6
+ Capistrano.configuration(:must_exist).load do
7
+ set :app_symlinks, nil
8
+
9
+ desc "Setup servers."
10
+ task :setup_server do
11
+ setup
12
+ setup_db
13
+ setup_app
14
+ setup_symlinks
15
+ setup_web
16
+ end
17
+
18
+ def override_sudo(want = false)
19
+ old_use_sudo = use_sudo
20
+ set :use_sudo, want
21
+ yield
22
+ set :use_sudo, old_use_sudo
23
+ end
24
+
25
+ desc "Setup application server."
26
+ task :setup_app, :roles => :app do
27
+ set :mongrel_environment, rails_env
28
+ set :mongrel_port, apache_proxy_port
29
+ set :mongrel_servers, apache_proxy_servers
30
+ override_sudo { configure_mongrel_cluster }
31
+ # add entry to syslog.conf
32
+ # add entry to newsyslog.conf
33
+ end
34
+
35
+ desc "Restart application server."
36
+ task :restart_app, :roles => :app do
37
+ override_sudo { restart_mongrel_cluster }
38
+ end
39
+
40
+ desc "Start application server."
41
+ task :start_app, :roles => :app do
42
+ override_sudo { start_mongrel_cluster }
43
+ end
44
+
45
+ desc "Stop application server."
46
+ task :stop_app, :roles => :app do
47
+ override_sudo { stop_mongrel_cluster }
48
+ end
49
+
50
+ desc "Setup web server."
51
+ task :setup_web, :roles => :web do
52
+ set :apache_server_name, domain unless apache_server_name
53
+ configure_apache
54
+ end
55
+
56
+ desc "Restart web server."
57
+ task :restart_web, :roles => :web do
58
+ restart_apache
59
+ end
60
+
61
+ desc "Reload web server configuration."
62
+ task :reload_web, :roles => :web do
63
+ reload_apache
64
+ end
65
+
66
+ desc "Start web server."
67
+ task :start_web, :roles => :web do
68
+ start_apache
69
+ end
70
+
71
+ desc "Stop web server."
72
+ task :stop_web, :roles => :web do
73
+ stop_apache
74
+ end
75
+
76
+ desc "Setup database server."
77
+ task :setup_db, :roles => :db, :only => { :primary => true } do
78
+ setup_mysql
79
+ end
80
+
81
+ desc "Setup source control server."
82
+ task :setup_scm, :roles => :scm do
83
+ setup_svn
84
+ import_svn
85
+ end
86
+
87
+ desc "Setup public symlink directories"
88
+ task :setup_symlinks, :roles => [:app, :web] do
89
+ if app_symlinks
90
+ app_symlinks.each { |link| run "mkdir -p #{shared_path}/public/#{link}" }
91
+ end
92
+ end
93
+
94
+ desc "Link up any public directories."
95
+ task :symlink_public, :roles => [:app, :web] do
96
+ if app_symlinks
97
+ app_symlinks.each { |link| run "ln -nfs #{shared_path}/public/#{link} #{current_path}/public/#{link}" }
98
+ end
99
+ end
100
+
101
+ desc <<-DESC
102
+ Restart the processes on the application server by calling restart_app.
103
+ DESC
104
+ task :restart, :roles => :app do
105
+ restart_app
106
+ end
107
+
108
+ desc <<-DESC
109
+ Start the processes on the application server by calling start_app.
110
+ DESC
111
+ task :spinner, :roles => :app do
112
+ start_app
113
+ end
114
+
115
+ desc "Creates additional symlinks."
116
+ task :after_symlink, :roles => [:app, :web] do
117
+ symlink_public
118
+ end
119
+
120
+ end
@@ -0,0 +1,70 @@
1
+ Capistrano.configuration(:must_exist).load do
2
+
3
+ set :apache_server_name, nil
4
+ set :apache_conf, nil
5
+ set :apache_default_vhost, false
6
+ set :apache_default_vhost_conf, nil
7
+ set :apache_ctl, "/usr/local/apache2/bin/apachectl -d /u/apache2 -k"
8
+ set :apache_server_aliases, []
9
+ set :apache_proxy_port, 8000
10
+ set :apache_proxy_servers, 2
11
+ set :apache_proxy_address, "127.0.0.1"
12
+ set :apache_ssl_enabled, false
13
+ set :apache_ssl_ip, nil
14
+ set :apache_ssl_forward_all, false
15
+
16
+ desc "Configure Apache. This uses the :use_sudo
17
+ variable to determine whether to use sudo or not. By default, :use_sudo is
18
+ set to true."
19
+ task :configure_apache, :roles => :web do
20
+ set_apache_conf
21
+
22
+ server_aliases = []
23
+ server_aliases << "www.#{apache_server_name}"
24
+ server_aliases.concat apache_server_aliases
25
+ set :apache_server_aliases_array, server_aliases
26
+
27
+ file = File.join(File.dirname(__FILE__), "templates", "httpd.conf")
28
+ buffer = render :template => File.read(file)
29
+
30
+ if apache_ssl_enabled
31
+ file = File.join(File.dirname(__FILE__), "templates", "httpd-ssl.conf")
32
+ ssl_buffer = render :template => File.read(file)
33
+ buffer += ssl_buffer
34
+ end
35
+
36
+ run "mkdir -p #{shared_path}"
37
+ put buffer, "#{shared_path}/httpd.conf"
38
+ send(run_method, "cp #{shared_path}/httpd.conf #{apache_conf}")
39
+ delete "#{shared_path}/httpd.conf"
40
+ end
41
+
42
+ desc "Start Apache "
43
+ task :start_apache, :roles => :web do
44
+ send(run_method, "#{apache_ctl} start")
45
+ end
46
+
47
+ desc "Restart Apache "
48
+ task :restart_apache, :roles => :web do
49
+ send(run_method, "#{apache_ctl} restart")
50
+ end
51
+
52
+ desc "Stop Apache "
53
+ task :stop_apache, :roles => :web do
54
+ send(run_method, "#{apache_ctl} stop")
55
+ end
56
+
57
+ desc "Reload Apache "
58
+ task :reload_apache, :roles => :web do
59
+ send(run_method, "#{apache_ctl} reload")
60
+ end
61
+
62
+ def set_apache_conf
63
+ if apache_default_vhost
64
+ set :apache_conf, "/u/apache2/conf/default.conf" unless apache_default_vhost_conf
65
+ else
66
+ set :apache_conf, "/u/apache2/conf/apps/#{application}.conf" unless apache_conf
67
+ end
68
+ end
69
+
70
+ end
@@ -0,0 +1,5 @@
1
+ require 'mongrel_cluster/recipes'
2
+
3
+ def set_mongrel_conf
4
+ set :mongrel_conf, "/u/mongrel_cluster/#{application}.conf" unless mongrel_conf
5
+ end
@@ -0,0 +1,58 @@
1
+ require 'yaml'
2
+ require 'capistrano'
3
+ require 'capistrano/cli'
4
+
5
+ module MySQLMethods
6
+
7
+ def execute(sql, user)
8
+ run "mysql --user=#{user} -p --execute=\"#{sql}\"" do |channel, stream, data|
9
+ handle_mysql_password(user, channel, stream, data)
10
+ end
11
+ end
12
+
13
+ private
14
+ def handle_mysql_password(user, channel, stream, data)
15
+ logger.info data, "[database on #{channel[:host]} asked for password]"
16
+ if data =~ /^Enter password:/
17
+ pass = Capistrano::CLI.password_prompt "Enter database password for '#{user}':"
18
+ channel.send_data "#{pass}\n"
19
+ end
20
+ end
21
+ end
22
+
23
+ Capistrano.plugin :mysql, MySQLMethods
24
+
25
+ Capistrano.configuration(:must_exist).load do
26
+
27
+ set :mysql_admin, nil
28
+
29
+ desc "Execute MySQL statements using --execute option. Set the 'sql' variable."
30
+ task :execute_mysql, :roles => :db, :only => { :primary => true } do
31
+ set_mysql_admin
32
+ mysql.execute sql, mysql_admin
33
+ end
34
+
35
+ desc "Create MySQL database and user based on config/database.yml"
36
+ task :setup_mysql, :roles => :db, :only => { :primary => true } do
37
+ # on_rollback {}
38
+
39
+ set_mysql_admin
40
+ read_config
41
+
42
+ sql = "CREATE DATABASE #{db_name};"
43
+ sql += "GRANT ALL PRIVILEGES ON #{db_name}.* TO #{db_user}@localhost IDENTIFIED BY '#{db_password}';"
44
+ mysql.execute sql, mysql_admin
45
+ end
46
+
47
+ def read_config
48
+ db_config = YAML.load_file('config/database.yml')
49
+ set :db_user, db_config[rails_env]["username"]
50
+ set :db_password, db_config[rails_env]["password"]
51
+ set :db_name, db_config[rails_env]["database"]
52
+ end
53
+
54
+ def set_mysql_admin
55
+ set :mysql_admin, user unless mysql_admin
56
+ end
57
+
58
+ end