Class: Mongrel2::Control

Inherits:
Object
  • Object
show all
Extended by:
Loggability
Defined in:
lib/mongrel2/control.rb

Overview

An interface to the Mongrel2 control port.

References

(mongrel2.org/static/book-finalch4.html#x6-390003.8)

Constant Summary collapse

DEFAULT_PORT =

The default zmq connection spec to use when talking to a mongrel2 server

'ipc://run/control'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(port = DEFAULT_PORT) ⇒ Control

Create a new control port object using the current configuration.



29
30
31
32
33
34
# File 'lib/mongrel2/control.rb', line 29

def initialize( port=DEFAULT_PORT )
  check_port( port )
  @socket = CZTop::Socket::REQ.new
  @socket.options.linger = 0
  @socket.connect( port.to_s )
end

Instance Attribute Details

#socketObject (readonly)

The control port ZMQ::REQ socket



42
43
44
# File 'lib/mongrel2/control.rb', line 42

def socket
  @socket
end

Instance Method Details

#closeObject

Close the control port connection.



161
162
163
# File 'lib/mongrel2/control.rb', line 161

def close
  self.socket.close
end

#conn_statusObject

Returns an Array of Hashes, one for each connection to the server.

Example:

[
  {:id=>9, :fd=>27, :type=>1, :last_ping=>0, :last_read=>0, :last_write=>0,
   :bytes_read=>319, :bytes_written=>1065}
]


134
135
136
# File 'lib/mongrel2/control.rb', line 134

def conn_status
  self.request( :status, :what => 'net' )
end

#control_stopObject

Shuts down the control port permanently in case you want to keep it from being accessed for some reason.



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

def control_stop
  self.request( :control_stop )
end

#helpObject

Return an Array of Hashes, one for each command the server supports.

Example:

[
  {:name=>"stop", :help=>"stop the server (SIGINT)"},
  {:name=>"reload", :help=>"reload the server"},
  {:name=>"help", :help=>"this command"},
  {:name=>"control_stop", :help=>"stop control port"},
  {:name=>"kill", :help=>"kill a connection"},
  {:name=>"status", :help=>"status, what=['net'|'tasks']"},
  {:name=>"terminate", :help=>"terminate the server (SIGTERM)"},
  {:name=>"time", :help=>"the server's time"},
  {:name=>"uuid", :help=>"the server's uuid"},
  {:name=>"info", :help=>"information about this server"}
]


82
83
84
# File 'lib/mongrel2/control.rb', line 82

def help
  self.request( :help )
end

#infoObject

Return information about the server.

Example:

[{:port=>7337,
  :bind_addr=>"0.0.0.0",
  :uuid=>"28F6DCCF-28EB-48A4-A5B0-ED71D224FAE0",
  :chroot=>"/var/www",
  :access_log=>"/var/www/logs/admin-access.log",
  :error_log=>"/logs/admin-error.log",
  :pid_file=>"./run/admin.pid",
  :default_hostname=>"localhost"}]


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

def info
  self.request( :info )
end

#kill(conn_id) ⇒ Object

Does a forced close on the socket that is at the specified conn_id.



148
149
150
# File 'lib/mongrel2/control.rb', line 148

def kill( conn_id )
  self.request( :kill, :id => conn_id )
end

#reloadObject Also known as: restart

Reloads the server using a SIGHUP. Returns a hash with a ‘:msg’ key that describes what happened on success.



54
55
56
# File 'lib/mongrel2/control.rb', line 54

def reload
  self.request( :reload )
end

#stopObject

Stops the server using a SIGINT. Returns a hash with a ‘:msg’ key that describes what happened on success.



47
48
49
# File 'lib/mongrel2/control.rb', line 47

def stop
  self.request( :stop )
end

#tasklistObject

Returns an Array of Hashes, one for each currently running task.

Example:

[
  {:id=>1, :system=>false, :name=>"SERVER", :state=>"read fd", :status=>"idle"},
  {:id=>2, :system=>false, :name=>"Handler_task", :state=>"read handler", :status=>"idle"},
  {:id=>3, :system=>false, :name=>"control", :state=>"read handler", :status=>"running"},
  {:id=>4, :system=>false, :name=>"ticker", :state=>"", :status=>"idle"},
  {:id=>5, :system=>true, :name=>"fdtask", :state=>"yield", :status=>"ready"}
]


122
123
124
# File 'lib/mongrel2/control.rb', line 122

def tasklist
  self.request( :status, :what => 'tasks' )
end

#terminateObject

Terminates the server with SIGTERM. Returns a hash with a ‘:msg’ key that describes what happened on success.



62
63
64
# File 'lib/mongrel2/control.rb', line 62

def terminate
  self.request( :terminate )
end

#timeObject

Returns the server’s time as a Time object.



140
141
142
143
144
# File 'lib/mongrel2/control.rb', line 140

def time
  response = self.request( :time )
  return nil if response.empty?
  return Time.at( response.first[:time].to_i )
end

#uuidObject

Returns the server’s UUID as a String.

Example:

[{:uuid=>"28F6DCCF-28EB-48A4-A5B0-ED71D224FAE0"}]


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

def uuid
  self.request( :uuid )
end