First Cut of TNetstring Control Port
- From:
- Zed A. Shaw
- Date:
- 2011-04-20 @ 08:23
Just did a big commit to trunk that has a working control port and m2sh
that uses tnetstrings to do everything. The format has changed for the
tnetstrings, but accessing the control port is now much easier from all
languages.
I'll do another pass on it tomorrow to root out bugs and clean up the
display, but right now it works like this:
m2sh control -every
m2 [main]> help
name help
stop stop the server (SIGINT)
reload reload the server
help this command
control_stop stop control port
kill kill a connection
status status, what=['net'|'tasks']
terminate terminate the server (SIGTERM)
time the server's time
uuid the server's uuid
What's going on is mongrel2 returns only dictionaries with one of two
formats:
{'error': MSG, 'code': CODE} for errors
{'headers': ['h1','h2',...], rows=[[val1,val2],[val1,val2]]}
When m2sh sees the first kind it'll print the error message.
When it sees the second it does a generic "dump the table". This new
table format is easier to work with and more efficient since the column
names aren't repeated over and over. It cuts the size of messages by
quite a bit.
Commands are sent in a consistent format of:
["name", {'arg': 'val'}]
Even if there's no arguments you always send the dict. Here's an
example of getting the status of tasks:
m2 [main]> status what=tasks
id system name state status
1 false SERVER read wait idle
2 false control read wait running
3 false idle
4 false Handler_task read wait idle
5 false Handler_task read wait idle
6 false Handler_task read wait idle
7 true fdtask yield ready
8 false HTTP write wait idle
And here's killing a socket that isn't there:
m2 [main]> kill id=0
ERROR: Socket not connected.
The m2sh parser is pretty limited so don't put spaces between the
arg=val when you send it or it'll think that's a string.
It should be trivial now to add a library to the mongrel2 python library
that lets you directly manipulate mongrel2 servers, and should make
automation much better.
Try this out and report back to me bugs and problems.
--
Zed A. Shaw
http://zedshaw.com/