Is it possible to create a systemd socket service that connects to a socket on startup?
The systemd.socket documentation (https://www.freedesktop.org/software/systemd/man/systemd.socket.html) contains no mention of it so I doubt it's possible, but it sure would be nice.
Specifically I want a service that has its stdout set to a connect()ed UNIX socket so I can opportunistically use sendmsg for extra data when connected to another service. I can do this myself or with arguments, but it would simplify my application if I didn't have to.
Yes I can!
I need to use StandardOut=file:/path/to/unix-socket
Which is documented in:
https://www.freedesktop.org/software/systemd/man/systemd.exec.html#
Related
I have the following problem:
I need to test connection to RabbitMQ Server which operates on AMQ Protocol, and i need to do it using CMD or something similar, so i can execute the command from script. I don't know if it's possible,the only thing that I found on internet was testing connection through HTTP, and it doesn't work for me.So shortly, I need cmd command that tests connection to RabbitMQ server which uses AMQP.
I hope that someone understands what is my problem, maybe i didn't described it good.
Thanks in advance.
I find out what the problem was, and it's kinda silly. You need to establish connection first, but it's kinda tricky to do on local machine. Simply said, you need to simulate communication between, in this case, two scripts. Then, it's easy to list the connections with command:
rabbitmqctl list_connections
I am trying to implement an app/thread that listens to an ipaddr:port on which another app/thread is already listening. I know I need to update both the apps to set SO_REUSEADDR in setsockopt(...) before bind() to avoid "Address Already in use" error when the 2nd app tries to bind().
The problem is that these apps(libs) are in an existing system that uses ZeroMQ on it's own. I cannot use linux socket lib directly. I have to use ZeroMQ sockets only.
Apparently zmq::setsockopt() does not understand SO_REUSEADDR as an option as its not defined in the zmq.h header. At least there is no ZMQ_SO_REUSEADDR
Or may be I am not using the right option.
Can someone help me with this issue. Does ZMQ socket support SO_REUSEADDR or not support at all, in which case how to go about this issue?
There's a couple things going on here.
SO_REUSEADDR is not going to help you. [see here].
SO_REUSEADDR will not allow you to share the same socket signature between two applications. So, if you are bound to a specific address:port in your first application and still using that address and port in that application, then you will not be able to bind to it in your second application. SO_REUSEADDR allows you to grab an address:port signature for a new application once an old application has given it up but it's still lingering, waiting for the buffer to clear.
SO_REUSEPORT is what you're looking for [see same link as above].
SO_REUSEPORT is intended to allow multiple applications to share the same address signature. This seems to be what you're looking for.
SO_REUSEPORT is not supported in ZMQ [see here].
You cannot bind to the same address:port in multiple applications on the same host in ZMQ. It's not supported as of June of last year.
... if you wish to just handle the case where another service is spinning down and a new service wishes to bind on the same address:port signature, you'll have to set ZMQ_LINGER to 0 on the original connection so that it won't hold the socket to clear the buffer.
I am trying to locate all my sockets logically and I am having a hard time understanding.
Say, for example that I want them in this directory: /var/run/<app>/
I should specify uWSGI this in a command line parameter
--socket </var/run/<app>/>
However in my uwsgi.ini I have this:
socket = 127.0.0.1:3031
In order to get the effect I want, should I be doing
socket = /var/run/uwsgi
I am just confused, because one is an IP and one is a directory.
As documented you can use either network or Unix domain sockets.
I want a method of finding out what process opened what port without the aid of an external application. I.e. no netstat or other tools like it.
You need to use the IP helper functions. More specifically GetExtendedTcpTable and GetExtendedUdpTable.
For example, for GetExtendedUdpTable, you can pass in MIB_UDPTABLE_OWNER_PID as the TableClass and you will be able to receive the PID of the process that issued the call to bind for the UDP endpoint.
I have a small TCP server that listens on a port. While debugging it's common for me to CTRL-C the server in order to kill the process.
On Windows I'm able to restart the service quickly and the socket can be rebound. On Linux I have to wait a few minutes before bind() returns with success
When bind() is failing it returns errno=98, address in use.
I'd like to better understand the differences in implementations. Windows sure is more friendly to the developer, but I kind of doubt Linux is doing the 'wrong thing'.
My best guess is Linux is waiting until all possible clients have detected the old socket is broken before allowing new sockets to be created. The only way it could do this is to wait for them to timeout
is there a way to change this behavior during development in Linux? I'm hoping to duplicate the way Windows does this
You want to use the SO_REUSEADDR option on the socket on Linux. The relevant manpage is socket(7). Here's an example of its usage. This question explains what happens.
Here's a duplicate of this answer.
On Linux, SO_REUSEADDR allows you to bind to an address unless an active connection is present. On Windows this is the default behaviour. On Windows, SO_REUSEADDR allows you to additionally bind multiple sockets to the same addresses. See here and here for more.