Class: Baykit::BayServer::Docker::Cgi::CgiDocker

Inherits:
Base::ClubBase
  • Object
show all
Includes:
Agent, Agent::Multiplexer, Bcf, Baykit::BayServer::Docker, Baykit::BayServer::Docker::Cgi, Rudders, Taxi, Tours, Util
Defined in:
lib/baykit/bayserver/docker/cgi/cgi_docker.rb

Direct Known Subclasses

PhpCgiDocker

Constant Summary collapse

DEFAULT_TIMEOUT_SEC =
0

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeCgiDocker

Returns a new instance of CgiDocker.



43
44
45
46
47
48
49
50
51
52
# File 'lib/baykit/bayserver/docker/cgi/cgi_docker.rb', line 43

def initialize()
  super
  @interpreter = nil
  @script_base = nil
  @doc_root = nil
  @timeout_sec = CgiDocker::DEFAULT_TIMEOUT_SEC
  @max_processes = -1
  @process_count = 0
  @wait_count = 0
end

Instance Attribute Details

#doc_rootObject (readonly)

Returns the value of attribute doc_root.



36
37
38
# File 'lib/baykit/bayserver/docker/cgi/cgi_docker.rb', line 36

def doc_root
  @doc_root
end

#interpreterObject (readonly)

Returns the value of attribute interpreter.



34
35
36
# File 'lib/baykit/bayserver/docker/cgi/cgi_docker.rb', line 34

def interpreter
  @interpreter
end

#max_processesObject (readonly)

Returns the value of attribute max_processes.



38
39
40
# File 'lib/baykit/bayserver/docker/cgi/cgi_docker.rb', line 38

def max_processes
  @max_processes
end

#process_countObject (readonly)

Returns the value of attribute process_count.



39
40
41
# File 'lib/baykit/bayserver/docker/cgi/cgi_docker.rb', line 39

def process_count
  @process_count
end

#script_baseObject (readonly)

Returns the value of attribute script_base.



35
36
37
# File 'lib/baykit/bayserver/docker/cgi/cgi_docker.rb', line 35

def script_base
  @script_base
end

#timeout_secObject (readonly)

Returns the value of attribute timeout_sec.



37
38
39
# File 'lib/baykit/bayserver/docker/cgi/cgi_docker.rb', line 37

def timeout_sec
  @timeout_sec
end

#wait_countObject (readonly)

Returns the value of attribute wait_count.



40
41
42
# File 'lib/baykit/bayserver/docker/cgi/cgi_docker.rb', line 40

def wait_count
  @wait_count
end

Instance Method Details

#add_process_countObject



155
156
157
158
159
160
161
162
163
164
# File 'lib/baykit/bayserver/docker/cgi/cgi_docker.rb', line 155

def add_process_count
  if @max_processes <= 0 || @process_count < @max_processes
    @process_count += 1
    BayLog.debug("%s Process count: %d", self, @process_count)
    return true
  end

  @wait_count += 1
  return false
end

#arrive(tur) ⇒ Object

Implements Club



94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
# File 'lib/baykit/bayserver/docker/cgi/cgi_docker.rb', line 94

def arrive(tur)

  if tur.req.uri.include?("..")
    raise HttpException.new(HttpStatus::FORBIDDEN, tur.req.uri)
    return
  end

  base = script_base
  if base == nil
    base = tur.town.location()
  end

  if StringUtil.empty?(base)
    raise HttpException.new(HttpStatus::INTERNAL_SERVER_ERROR, "%s scriptBase of cgi docker or location of town is not specified.", tur.town)
  end

  root = doc_root
  if root == nil
    root = tur.town.location()
  end

  if StringUtil.empty?(root)
    raise HttpException.new(HttpStatus::INTERNAL_SERVER_ERROR, "$s docRoot of cgi docker or location of town is not specified.", tur.town)
  end

  env = CgiUtil.get_env_hash(tur.town.name, root, base, tur)
  if BayServer.harbor.trace_header
    env.keys.each do |name|
      value = env[name]
      BayLog.info("%s cgi: env: %s=%s", tur, name, value)
    end
  end

  file_name = env[CgiUtil::SCRIPT_FILENAME]
  if !File.file?(file_name)
    raise HttpException.new(HttpStatus::NOT_FOUND, file_name)
  end

  handler = CgiReqContentHandler.new(self, tur, env)
  tur.req.set_content_handler(handler)
  handler.req_start_tour()
end

#create_command(env) ⇒ Object



137
138
139
140
141
142
143
144
145
# File 'lib/baykit/bayserver/docker/cgi/cgi_docker.rb', line 137

def create_command(env)
  script = env[CgiUtil::SCRIPT_FILENAME]
  if @interpreter == nil
    command = script
  else
    command = @interpreter + " " + script
  end
  command
end

#get_wait_countObject

Other methods



151
152
153
# File 'lib/baykit/bayserver/docker/cgi/cgi_docker.rb', line 151

def get_wait_count
  @wait_count
end

#init(elm, parent) ⇒ Object

Implements Docker



58
59
60
# File 'lib/baykit/bayserver/docker/cgi/cgi_docker.rb', line 58

def init(elm, parent)
  super
end

#init_key_val(kv) ⇒ Object

Implements DockerBase



67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/baykit/bayserver/docker/cgi/cgi_docker.rb', line 67

def init_key_val(kv)
  case kv.key.downcase
  when "interpreter"
    @interpreter = kv.value

  when "scriptbase"
    @script_base = kv.value

  when "docroot"
    @doc_root = kv.value

  when "timeout"
    @timeout_sec = kv.value.to_i

  when "maxprocesses"
    @max_processes = kv.value.to_i

  else
    return super
  end
  return true
end

#sub_process_countObject



166
167
168
# File 'lib/baykit/bayserver/docker/cgi/cgi_docker.rb', line 166

def sub_process_count
  @process_count -= 1
end

#sub_wait_countObject



170
171
172
# File 'lib/baykit/bayserver/docker/cgi/cgi_docker.rb', line 170

def sub_wait_count
  @wait_count -= 1
end