Module: UCB::UnixEnvironment::ClassMethods

Defined in:
lib/ucb_unix_environment.rb

Instance Method Summary collapse

Instance Method Details

#apache_log_dirObject

Returns full path of the directory containing the apache logs.



86
87
88
# File 'lib/ucb_unix_environment.rb', line 86

def apache_log_dir
  "#{local_dir}/apache2/logs"
end

#apache_portsObject

Returns ports not used by Apache in standard webfarm configurations.



150
151
152
# File 'lib/ucb_unix_environment.rb', line 150

def apache_ports
  @apache_ports ||= [http_port, https_port]
end

#domain_nameObject



59
60
61
62
# File 'lib/ucb_unix_environment.rb', line 59

def domain_name
  return "" if win32?
  `domainname`.chomp.downcase
end

#gidObject

Returns the gid.



97
98
99
# File 'lib/ucb_unix_environment.rb', line 97

def gid
  id_info(:gid)
end

#groupObject

Returns the group.



102
103
104
# File 'lib/ucb_unix_environment.rb', line 102

def group
  id_info(:group)
end

#http_portObject Also known as: non_ssl_port

Returns the Apache http port



138
139
140
# File 'lib/ucb_unix_environment.rb', line 138

def http_port
  ports[0]
end

#https_portObject Also known as: ssl_port

Returns the Apache https port.



144
145
146
# File 'lib/ucb_unix_environment.rb', line 144

def https_port
  ports[1]
end

#id_info(symbol) ⇒ Object

:nodoc:



116
117
118
119
120
121
122
123
124
125
126
127
# File 'lib/ucb_unix_environment.rb', line 116

def id_info(symbol) #:nodoc:
  unless @id_info
    @id_info = {}
    unless win32?
       = ENV['LOGNAME']
      user = Etc.getpwnam()
      group = Etc.getgrnam()
      @id_info = {:uid => user.uid, :user => user.name, :gid => group.gid, :group => group.name }
    end
  end
  @id_info[symbol]
end

#local_dirObject

Returns the local directory of the individual for your account. i.e., not shared across webfarm instances.



72
73
74
# File 'lib/ucb_unix_environment.rb', line 72

def local_dir
  "/users/#{user}/local"
end

#machine_nameObject

Returns the machine name.



49
50
51
52
# File 'lib/ucb_unix_environment.rb', line 49

def machine_name
  return "" if win32?
  `uname -n`.chop
end

#mongrel_log_dirObject

Returns full path of the directory containing the mongrel logs.



77
78
79
# File 'lib/ucb_unix_environment.rb', line 77

def mongrel_log_dir
  "#{local_dir}/rails/log"
end

#mongrel_pid_dirObject



81
82
83
# File 'lib/ucb_unix_environment.rb', line 81

def mongrel_pid_dir
  "#{local_dir}/rails/#{user}/pid"
end

#mongrel_portsObject

Returns ports for mongrel processes.



160
161
162
# File 'lib/ucb_unix_environment.rb', line 160

def mongrel_ports
  @mongrel_ports ||= (ports - apache_ports)
end

#mongrel_ports=(port_array) ⇒ Object

Setter for mongrel_port_count.



155
156
157
# File 'lib/ucb_unix_environment.rb', line 155

def mongrel_ports=(port_array)
  @mongrel_ports = port_array
end

#portsObject

Returns an Array (of Integer) of ports.



133
134
135
# File 'lib/ucb_unix_environment.rb', line 133

def ports
  @ports ||= Array.new(6) { |i| (i*10000) + uid }
end

#shared_dirObject Also known as: home_dir

Returns the user account home directory. This is on shared storage across machines.



65
66
67
# File 'lib/ucb_unix_environment.rb', line 65

def shared_dir
  "/users/#{user}"
end

#uidObject

Returns the uid.



107
108
109
# File 'lib/ucb_unix_environment.rb', line 107

def uid
  id_info(:uid)
end

#unix_serviceObject



54
55
56
57
# File 'lib/ucb_unix_environment.rb', line 54

def unix_service
  return "" if win32?
  machine_name.split('-')
end

#userObject

Returns the user.



112
113
114
# File 'lib/ucb_unix_environment.rb', line 112

def user
  id_info(:user)
end

#webfarm_idObject

Returns the unique identifier of the account instance.



91
92
93
# File 'lib/ucb_unix_environment.rb', line 91

def webfarm_id
  uid - 10000
end

#win32?Boolean

Returns true if on Windows.

Returns:

  • (Boolean)


44
45
46
# File 'lib/ucb_unix_environment.rb', line 44

def win32?
  RUBY_PLATFORM =~ /win32/
end