how do two processors communicate by a socket file - supervisord

I'm using Supervisord daemon, and I found the supervisorctl client to communicate with the daemon by the socket file:
[unix_http_server]
file=/var/tmp/supervisor.sock
I'm curious that, how do they communicate by the socket file?
For example supervisorCtl will communicate with supervisorD with the sock file /var/tmp/supervisor.sock

Related

How can I check a socket from a webserver?

Im doing a challenge (CTF style) and everyting we got is an IP.
Scanning that IP only one port is open.
If I connect to that IP and port using netcat, I got a kind of "dance" doing in CMD, with a message at the end that says "Check socket 12345".
I need to understand again what truly a socket is because im not getting anywhere trying to connect to that socket.
Its possible to connect to a socket from a specific port? or I only can make a connection from a open port and there the web servers redirect my connection automatically to a socket?
You can use netcat nc and its -p option to set the source port.
Netcat man page say:
-p port
local port number (port numbers can be individual or ranges: lo-hi [inclusive])
Try "nc -p 12345 dest_IP dest_port"

Bi-directional communication using sockets via ssh tunnel

I have a server host (S) and a bunch of clients (C1, C2, C3, ...). I would like to open connection between S and C1, C2, C3 respectively for bi-directional communication. Ideally using sockets. SSH for authorisation purposes is preferred.
Ideally:
Client C1 creates SSH reverse tunnel to S, forwarding C1's port so it is accessible on S as it's own port.
Client program running on C1 creates a socket and binds to forwarded port.
Server program running on S creates a socket and binds to forwarded port.
Client and server can exchange data.
Is something like that possible? I tried coding up a draft using Python but to no avail:
Firstly, I run on C1: ssh -N -R 9999:localhost:15432 root#example.com - OK
Secondly, on server I run:
import socket
serversocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
serversocket.bind(('localhost', 9999))
serversocket.listen(5)
while True:
connection, address = serversocket.accept()
buf = connection.recv(64)
if len(buf) > 0:
print buf
break
Thirdly, on client I run:
import socket
clientsocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
clientsocket.connect(('localhost', 15432))
clientsocket.send('hello')
But I'm getting socket.error: [Errno 111] Connection refused on client. Also if I set up tunnel first and then launch server program, I'm getting [Errno 98] Address already in use. It only works when I first start the program, then set up a tunnel.
If aforementioned concept does not make sense, what would you suggest to create sort of synchronisation tool so any client listens for queries from the server and can respond with data? (preferrably in Python).
Thanks in advance.
-N doesn't do what you seem to think it does: it's intended for the ssh-destination to be able to connect back to the originator. But that would make the originating side the server.
It sounds like you should be using -L to simply create a connection from the client through the ssh tunnel to the server.
To demonstrate: I have a local server named 'bree'. On that machine, I execute (this could also be your python server listening on port 9999):
nc -l 9999
Now on my client machine, I execute this in one window (or could put it in the background):
ssh -N -L 9999:bree:9999 bree
This says: listen on the local (client) machine to port 9999, and when a connection to it is made, forward the request through the tunnel, and connect to port 9999 on bree.
Now, in a second window on the client machine, I execute:
nc localhost 9999
The two nc instances are connected.

Installing Software, How to Find Unix Socket

I'm in the process of installing a program called Moodle onto our server. During the installation process it asked for the Database port and Unix socket for the PostgreSQL database.
I found the database port with a sql command but I don't know how to find the Unix socket.
I'm vaguely familiar with the concept from my Unix classes but I don't know too much about this.
Please help!
The location for the unix domain socket will be configured in the postgresl.conf file.
eg:
unix_socket_directories = '/run/postgresql'
The name of the socket will be the same as the TCP port number, same config file.
eg:
port = 5432
So, here the socket is at /run/postgresql/5432

Find Memcache port number when started with homebrew as a service

I installed homebrew and then memcache through it and started it as a service.I am unable to find on which port it is running though.When I do a ps -ef|grep memcached it does not give me any results.But it is definately running because I could see it listening to socket when I do memcached -vv.
Could anybody help? How can I find out the port number on which it is running?
Homebrew does not specify a port; memcached's default port is 11211. You can use lsof -i to see what processes have open sockets on OS X.

Using multiple terminals on a remote machine using a single SSH connection

I'm running a process on a remote server through SSH on a certain port. The process is basically a TCP server waiting (listening) for a connection. So as long as it is running I cannot use the terminal as it is a blocking application.
I want to run another application (a TCP client) through the same instance of SSH connection to connect to that TCP server. I used screen to detach the first process (TCP Server) and connect to the server but then I could not see the output of the TCP server application.
Is there a way to emulate two terminals on a remote machine using SSH?
So I found a solution to this problem. Basically below is a link that explains how can I achieve exactly what I needed. That is, opening multiple terminals using a single SSH connection.
http://idnotfound.wordpress.com/2008/01/14/multiple-terminals-in-a-single-ssh-session/
In short we can use the following procedure:
$ ssh -X mylogin#remotemachine gnome-terminal
Password: ...
[Ctrl+Z]
$ bg
$ exit
Press Ctrl+Shift+N to open a new terminal.
EDIT: Or just use screen. Sigh..