unixsurfer / haproxytool

A tool to interact with HAProxy via stats socket
Apache License 2.0
85 stars 8 forks source link

Add support for specifying a single socket file on the command line. #1

Closed sophomeric closed 8 years ago

sophomeric commented 8 years ago
My use case is that the socket_dir method scans a directory and errors out if it can't read any of the sockets, whether they are haproxy related sockets or not.
unixsurfer commented 8 years ago

I think you get an error because HAProxy class calls connected_socket in https://github.com/unixsurfer/haproxyadmin/blob/master/haproxyadmin/haproxy.py#L112 and that function raises exceptions https://github.com/unixsurfer/haproxyadmin/blob/872e22ba1496e6026742948db40aa33fb58cb391/haproxyadmin/utils.py#L162 which are not catched. Can I have the exact error you get?

I believe the real issue is in haproxyadmin lib which doesn't catch the exceptions. I am believe the right approach here would be to make HAProxy class to scan the dir set in socket_dir and exclude files that aren't valid HAProxy stats socket files.

This doesn't mean we should not add the -F argument in haproxytool.

What do you think?

sophomeric commented 8 years ago

Sure, that sounds better.

$ ./test/bin/haproxytool server -D /tmp -s No permissions are granted to access socket file /tmp/mongodb-27017.sock $ ll /tmp/mongodb-27017.sock srwx------ 1 mongodb nogroup 0 Jan 27 14:07 /tmp/mongodb-27017.sock=

And in this case this is expected and fine. The haproxy socket is also in /tmp for me and without being able to either ignore that socket(s) it can't access or specify a socket to use, I can't use the tool.

unixsurfer commented 8 years ago

OK, I propose to reject this PR and 1) fix HAProxy class to ignore invalid HProxy stats files when it scans a directory 2) Add -F in haproxytool without a default value and it will be mutually exclusive with -D, so a user can only one of them.

Do you agree ?

sophomeric commented 8 years ago

Sounds perfect.

unixsurfer commented 8 years ago

Setting a single socket file is available in 0.5.0 version. You should consider using haproxyadmin 0.2.1 version as it addresses the initial issue you reported.

sophomeric commented 8 years ago

I updated both and they work as advertised. Thanks!