ucb_ist_unix 1.1.4

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,42 @@
1
+ = UCB::Webfarm Changelog
2
+
3
+ == Version 0.4.0, 2007-10-04
4
+
5
+ * Changed to RSpec from Test::Unit
6
+ * Tests run on developer desktop (Mac and PC) and webfarm
7
+ * Removed several methods that were required for testing
8
+ * Made webfarm-only methods raise error when not called from webfarm
9
+
10
+ == Version 0.3.4, 2007-08-21
11
+
12
+ * added #mongrel_logs_dir
13
+ * added #apache_logs_dir
14
+
15
+ == Version 0.3.3, 2007-08-08
16
+
17
+ * added development_migration_environment
18
+
19
+ == Version 0.3.2, 2007-07-18
20
+
21
+ * added #rails_migration_environment
22
+ * added qa/quality_assurance/quality_assurance_migration environments
23
+
24
+ == Version 0.3.1, 2007-07-17
25
+
26
+ * added #rails_environment
27
+
28
+ == Version 0.3.0, 2007-03-05
29
+
30
+ * added #first_mongrel_port
31
+ * added #home_dir
32
+ * added #local_home_dir
33
+ * added constants for rails environments
34
+
35
+ == Version 0.2.0, 2007-02-08
36
+
37
+ * made unit tests runnable on Windows/Unix desktops and Webfarm
38
+ * added "programmer" environment which is where programmer develops applications
39
+ * added #machine_name which returns name of webfarm instance logged on to
40
+ * added #all_machines which returns all machine names in the current instance
41
+
42
+ == Version 0.1.0, Initial release
@@ -0,0 +1,10 @@
1
+ CHANGELOG
2
+ Manifest
3
+ README
4
+ Rakefile
5
+ lib/ucb_calweb_pro.rb
6
+ lib/ucb_ist_unix.rb
7
+ lib/ucb_unix_environment.rb
8
+ lib/ucb_webfarm.rb
9
+ tasks/ucb_ist_unix.rake
10
+ version.yml
data/README ADDED
@@ -0,0 +1,7 @@
1
+ = UC Berkeley Webfarm
2
+
3
+ UCB::Webfarm gives Ruby programs access to webfarm settings:
4
+
5
+ - uid, user, gid, group
6
+ - environment (dev/qa/prod)
7
+ - port info
@@ -0,0 +1,19 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+ require 'echoe'
4
+ require 'hanna/rdoctask'
5
+
6
+ Echoe.new('ucb_ist_unix', '1.1.4') do |p|
7
+ p.description = "UCB Webfarm/Calweb-Pro environment utilities"
8
+ p.url = "http://ucbrb.rubyforge.org/ucb_ist_unix"
9
+ p.author = "Steven Hansen"
10
+ p.email = "runner@berkeley.edu"
11
+ p.ignore_pattern = ["svn_user.yml", "ucb_ist_unix.rake", "spec/**/**"]
12
+ p.project = "ucbrb"
13
+ p.rdoc_options = "-o doc --inline-source -T hanna lib/*.rb"
14
+ p.rdoc_pattern = ["README", "CHANGELOG", "lib/**/**"]
15
+ end
16
+
17
+ Dir["#{File.dirname(__FILE__)}/tasks/*.rake"].sort.each { |ext| load ext }
18
+
19
+
@@ -0,0 +1,15 @@
1
+
2
+ module UCB
3
+ class CalwebPro
4
+ include UCB::UnixEnvironment
5
+
6
+ def self.environment
7
+ 'prod'
8
+ end
9
+
10
+ def self.calweb_pro?
11
+ machine_name.split('-').first == 'calweb'
12
+ end
13
+
14
+ end
15
+ end
@@ -0,0 +1,6 @@
1
+ $:.unshift File.dirname(__FILE__)
2
+
3
+ require 'ucb_unix_environment'
4
+ require 'ucb_calweb_pro'
5
+ require 'ucb_webfarm'
6
+ require 'etc'
@@ -0,0 +1,166 @@
1
+
2
+ module UCB
3
+ # Module giving Ruby access to various attributes of the webfarm
4
+ # including environment (dev, qa, prod), user/group info and ports.
5
+ #
6
+ # `uname -n` #=> "webfarm-dev-01\n"
7
+ #
8
+ # UCB::Webfarm.machine_name #=> "webfarm-dev-01"
9
+ # UCB::Webfarm.machines #=> ["webfarm-dev-01", "webfarm-dev-02"]
10
+ #
11
+ # `id` #=> "uid=10099(a_user) gid=10099(a_group)\n"
12
+ #
13
+ # UCB::Webfarm.webfarm_id #=> 99
14
+ # UCB::Webfarm.uid #=> 10099
15
+ # UCB::Webfarm.user #=> "a_user"
16
+ # UCB::Webfarm.shared_dir #=> "/users/a_user"
17
+ # UCB::Webfarm.local_dir #=> "/users/a_user/local"
18
+ #
19
+ # UCB::Webfarm.http_port #=> 10099
20
+ # UCB::Webfarm.https_port #=> 20099
21
+ #
22
+ # UCB::Webfarm.mongrel_port_count #=> 4
23
+ # UCB::Webfarm.mongrel_ports #=> [30099, 40099, 50099, 60099]
24
+ #
25
+ module UnixEnvironment
26
+
27
+ def self.included(klass)
28
+ klass.extend(ClassMethods)
29
+ klass.extend(AbstractClassMethods)
30
+ end
31
+
32
+ module AbstractClassMethods
33
+ def environment
34
+ begin
35
+ super
36
+ rescue NoMethodError
37
+ raise NoMethodError, "Abstract method 'environment' not implemented."
38
+ end
39
+ end
40
+ end
41
+
42
+ module ClassMethods
43
+ # Returns +true+ if on Windows.
44
+ def win32?
45
+ RUBY_PLATFORM =~ /win32/
46
+ end
47
+
48
+ # Returns the machine name.
49
+ def machine_name
50
+ return "" if win32?
51
+ `uname -n`.chop
52
+ end
53
+
54
+ def unix_service
55
+ return "" if win32?
56
+ machine_name.split('-')
57
+ end
58
+
59
+ def domain_name
60
+ return "" if win32?
61
+ `domainname`.chomp.downcase
62
+ end
63
+
64
+ # Returns the user account home directory. This is on shared storage across machines.
65
+ def shared_dir
66
+ "/users/#{user}"
67
+ end
68
+ alias :home_dir :shared_dir
69
+
70
+ # Returns the local directory of the individual for your account.
71
+ # i.e., not shared across webfarm instances.
72
+ def local_dir
73
+ "/users/#{user}/local"
74
+ end
75
+
76
+ # Returns full path of the directory containing the mongrel logs.
77
+ def mongrel_log_dir
78
+ "#{local_dir}/rails/log"
79
+ end
80
+
81
+ def mongrel_pid_dir
82
+ "#{local_dir}/rails/#{user}/pid"
83
+ end
84
+
85
+ # Returns full path of the directory containing the apache logs.
86
+ def apache_log_dir
87
+ "#{local_dir}/apache2/logs"
88
+ end
89
+
90
+ # Returns the unique identifier of the account instance.
91
+ def webfarm_id
92
+ uid - 10000
93
+ end
94
+
95
+
96
+ # Returns the +gid+.
97
+ def gid
98
+ id_info(:gid)
99
+ end
100
+
101
+ # Returns the +group+.
102
+ def group
103
+ id_info(:group)
104
+ end
105
+
106
+ # Returns the +uid+.
107
+ def uid
108
+ id_info(:uid)
109
+ end
110
+
111
+ # Returns the +user+.
112
+ def user
113
+ id_info(:user)
114
+ end
115
+
116
+ def id_info(symbol) #:nodoc:
117
+ unless @id_info
118
+ @id_info = {}
119
+ unless win32?
120
+ login = ENV['LOGNAME']
121
+ user = Etc.getpwnam(login)
122
+ group = Etc.getgrnam(login)
123
+ @id_info = {:uid => user.uid, :user => user.name, :gid => group.gid, :group => group.name }
124
+ end
125
+ end
126
+ @id_info[symbol]
127
+ end
128
+
129
+
130
+ #### Ports #####
131
+
132
+ # Returns an +Array+ (of +Integer+) of ports.
133
+ def ports
134
+ @ports ||= Array.new(6) { |i| (i*10000) + uid }
135
+ end
136
+
137
+ # Returns the Apache http port
138
+ def http_port
139
+ ports[0]
140
+ end
141
+ alias :non_ssl_port :http_port
142
+
143
+ # Returns the Apache https port.
144
+ def https_port
145
+ ports[1]
146
+ end
147
+ alias :ssl_port :https_port
148
+
149
+ # Returns ports not used by Apache in standard webfarm configurations.
150
+ def apache_ports
151
+ @apache_ports ||= [http_port, https_port]
152
+ end
153
+
154
+ # Setter for mongrel_port_count.
155
+ def mongrel_ports=(port_array)
156
+ @mongrel_ports = port_array
157
+ end
158
+
159
+ # Returns ports for mongrel processes.
160
+ def mongrel_ports
161
+ @mongrel_ports ||= (ports - apache_ports)
162
+ end
163
+ end
164
+
165
+ end
166
+ end
@@ -0,0 +1,108 @@
1
+
2
+ module UCB #:nodoc:
3
+ # Module giving Ruby access to various attributes of the webfarm
4
+ # including environment (dev, qa, prod), user/group info and ports.
5
+ #
6
+ # require 'ucb_ist_unix'
7
+ #
8
+ # `domainname` #=> "dev\n"
9
+ #
10
+ # UCB::Webfarm.environment #=> "dev"
11
+ # UCB::Webfarm.dev_int? #=> true
12
+ # UCB::Webfarm.prod? #=> false
13
+ #
14
+ module Webfarm
15
+ include UCB::UnixEnvironment
16
+
17
+ # Webfarm Environments
18
+ DEV_INT_ENV = 'dev'
19
+ QA_ENV = 'qa'
20
+ PROD_ENV = 'prod'
21
+
22
+ # Rails Environments
23
+ RAILS_DEV_INTEGRATION_ENV = 'dev_integration'
24
+ RAILS_QUALITY_ASSURANCE_ENV = 'quality_assurance'
25
+ RAILS_PRODUCTION_ENV = 'production'
26
+
27
+ # Rails Migration Environments
28
+ RAILS_DEV_INTEGRATION_MIGRATION_ENV = 'dev_integration_migration'
29
+ RAILS_QUALITY_ASSURANCE_MIGRATION_ENV = 'quality_assurance_migration'
30
+ RAILS_PRODUCTION_MIGRATION_ENV = 'production_migration'
31
+
32
+
33
+ class << self
34
+ # Returns an +Array+ of the Webfarm (not Rails) environments.
35
+ def environments
36
+ @webfarm_environments ||= [DEV_INT_ENV, QA_ENV, PROD_ENV]
37
+ end
38
+ alias :webfarm_environments :environments
39
+
40
+ # Returns _webfarm_ environment.
41
+ def environment
42
+ webfarm_environments.include?(domain_name) ? domain_name : nil
43
+ end
44
+ alias :webfarm_environment :environment
45
+
46
+ def webfarm?
47
+ machine_name.split('-').first == 'webfarm'
48
+ end
49
+
50
+ # An +Array+ of all machine names for the environment.
51
+ def machines
52
+ return [] if win32?
53
+
54
+ if dev?
55
+ ['localhost']
56
+ elsif dev_int?
57
+ ['webfarm-dev-01', 'webfarm-dev-02']
58
+ elsif qa?
59
+ ['webfarm-qa-01', 'webfarm-qa-02']
60
+ elsif prod?
61
+ ['webfarm-prod-01', 'webfarm-prod-02', 'webfarm-prod-03', 'webfarm-prod-04']
62
+ else
63
+ raise(Exception, "Unrecognized Environment")
64
+ end
65
+ end
66
+
67
+ def dev?
68
+ environment.nil?
69
+ end
70
+
71
+ # Returns +true+ for dev webfarm instances
72
+ def dev_int?
73
+ environment == DEV_INT_ENV
74
+ end
75
+
76
+ # Returns +true+ for qa webfarm instances
77
+ def qa?
78
+ environment == QA_ENV
79
+ end
80
+
81
+ # Returns +true+ for prod webfarm instances
82
+ def prod?
83
+ environment == PROD_ENV
84
+ end
85
+
86
+ # Returns Rails environment corresponding to the Webfarm environment.
87
+ # Returns ENV_RAILS_DEVELOPMENT unless webfarm?
88
+ #
89
+ # Raises RuntimeError for unknown environment.
90
+ def rails_environment
91
+ return RAILS_DEV_INTEGRATION_ENV if dev_int?
92
+ return RAILS_QUALITY_ASSURANCE_ENV if qa?
93
+ return RAILS_PRODUCTION_ENV if prod?
94
+ raise "Unknown webfarm rails_environment '#{environment}'"
95
+ end
96
+
97
+ # Returns environment to use for migrations. Allows different
98
+ # credentials for migrations than for web app.
99
+ def rails_migration_environment
100
+ return RAILS_DEV_INTEGRATION_MIGRATION_ENV if dev_int?
101
+ return RAILS_QUALITY_ASSURANCE_MIGRATION_ENV if qa?
102
+ return RAILS_PRODUCTION_MIGRATION_ENV if prod?
103
+ raise "Unknown webfarm rails_migration_environment '#{environment}'"
104
+ end
105
+ end
106
+
107
+ end
108
+ end
@@ -0,0 +1,9 @@
1
+ require 'yaml'
2
+ require 'spec/rake/spectask'
3
+ require 'svn/rake/svntask'
4
+
5
+ svn = Rake::SVN::ProjectTask.new() do |s|
6
+ s.method = "svn+ssh"
7
+ s.project_url = "svn.berkeley.edu/svn/ist-svn/berkeley/projects/commons/ruby/ucb-webfarm"
8
+ s.username = YAML.load_file('svn_user.yml')['svn_username']
9
+ end
@@ -0,0 +1,34 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = %q{ucb_ist_unix}
5
+ s.version = "1.1.4"
6
+
7
+ s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8
+ s.authors = ["Steven Hansen"]
9
+ s.date = %q{2009-04-15}
10
+ s.description = %q{UCB Webfarm/Calweb-Pro environment utilities}
11
+ s.email = %q{runner@berkeley.edu}
12
+ s.extra_rdoc_files = ["CHANGELOG", "README", "lib/ucb_calweb_pro.rb", "lib/ucb_ist_unix.rb", "lib/ucb_unix_environment.rb", "lib/ucb_webfarm.rb"]
13
+ s.files = ["CHANGELOG", "Manifest", "README", "Rakefile", "lib/ucb_calweb_pro.rb", "lib/ucb_ist_unix.rb", "lib/ucb_unix_environment.rb", "lib/ucb_webfarm.rb", "tasks/ucb_ist_unix.rake", "version.yml", "ucb_ist_unix.gemspec"]
14
+ s.has_rdoc = true
15
+ s.homepage = %q{http://ucbrb.rubyforge.org/ucb_ist_unix}
16
+ s.rdoc_options = ["-o doc --inline-source -T hanna lib/*.rb"]
17
+ s.require_paths = ["lib"]
18
+ s.rubyforge_project = %q{ucbrb}
19
+ s.rubygems_version = %q{1.3.1}
20
+ s.summary = %q{UCB Webfarm/Calweb-Pro environment utilities}
21
+
22
+ if s.respond_to? :specification_version then
23
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
24
+ s.specification_version = 2
25
+
26
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
27
+ s.add_development_dependency(%q<echoe>, [">= 0"])
28
+ else
29
+ s.add_dependency(%q<echoe>, [">= 0"])
30
+ end
31
+ else
32
+ s.add_dependency(%q<echoe>, [">= 0"])
33
+ end
34
+ end
@@ -0,0 +1 @@
1
+ version: 'rel-1.1.4'
metadata ADDED
@@ -0,0 +1,77 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ucb_ist_unix
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.1.4
5
+ platform: ruby
6
+ authors:
7
+ - Steven Hansen
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-04-15 00:00:00 -07:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: echoe
17
+ type: :development
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: "0"
24
+ version:
25
+ description: UCB Webfarm/Calweb-Pro environment utilities
26
+ email: runner@berkeley.edu
27
+ executables: []
28
+
29
+ extensions: []
30
+
31
+ extra_rdoc_files:
32
+ - CHANGELOG
33
+ - README
34
+ - lib/ucb_calweb_pro.rb
35
+ - lib/ucb_ist_unix.rb
36
+ - lib/ucb_unix_environment.rb
37
+ - lib/ucb_webfarm.rb
38
+ files:
39
+ - CHANGELOG
40
+ - Manifest
41
+ - README
42
+ - Rakefile
43
+ - lib/ucb_calweb_pro.rb
44
+ - lib/ucb_ist_unix.rb
45
+ - lib/ucb_unix_environment.rb
46
+ - lib/ucb_webfarm.rb
47
+ - tasks/ucb_ist_unix.rake
48
+ - version.yml
49
+ - ucb_ist_unix.gemspec
50
+ has_rdoc: true
51
+ homepage: http://ucbrb.rubyforge.org/ucb_ist_unix
52
+ post_install_message:
53
+ rdoc_options:
54
+ - -o doc --inline-source -T hanna lib/*.rb
55
+ require_paths:
56
+ - lib
57
+ required_ruby_version: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: "0"
62
+ version:
63
+ required_rubygems_version: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - ">="
66
+ - !ruby/object:Gem::Version
67
+ version: "1.2"
68
+ version:
69
+ requirements: []
70
+
71
+ rubyforge_project: ucbrb
72
+ rubygems_version: 1.3.1
73
+ signing_key:
74
+ specification_version: 2
75
+ summary: UCB Webfarm/Calweb-Pro environment utilities
76
+ test_files: []
77
+