Running 2 CherryPy instances on the same machine - cherrypy

I am running CherryPy as a webserver on a remote Linux machine. End users access a website over the internet which the CherryPy instance serves. So far, so good.
Now, I want to have a dev version of the site, running on the same machine but on a different port, so that I can develop and test without disturbing the prod website. I need to do development on the same machine because it contains a lot of data which would not be practical to move to a different machine.
The code for the dev instance is in a different directory, of course, so as I edit the dev code it does not trigger a reload for the prod instance or affect the prod instance in any way.
However, if I configure my dev instance to run on a different port than the prod instance and try to start up the dev instance, I get:
Traceback (most recent call last):
File "/usr/lib/python2.7/dist-packages/cherrypy/process/wspbus.py", line 197, in publish
output.append(listener(*args, **kwargs))
File "/usr/lib/python2.7/dist-packages/cherrypy/_cpserver.py", line 151, in start
ServerAdapter.start(self)
File "/usr/lib/python2.7/dist-packages/cherrypy/process/servers.py", line 167, in start
wait_for_free_port(*self.bind_addr)
File "/usr/lib/python2.7/dist-packages/cherrypy/process/servers.py", line 410, in wait_for_free_port
raise IOError("Port %r not free on %r" % (port, host))
IOError: Port 8080 not free on '127.0.0.1'
Neither the dev nor prod instance are running on port 8080. The prod instance is on SSL (443) and the dev instance I can put on an arbitrary port (let's suppose it's on 98765). I haven't specified 8080 anywhere in any config file. So I didn't expect there to be a port conflict, However, it appears that for one instance, CherryPy spawns 2 processes- I guess there is some sort of parent-child relationship- and one of the processes is somehow listening on localhost:8080. Because this happens for both instances I try to launch, the second one is unable to launch because there ends up being this conflict on 8080.
I have tried several things, such as turning off autoreloading and timeout monitoring, in the hopes that CherryPy would not launch the process associated with 8080, but no luck so far.
Thanks in advance for any help!

I had the same issue, to fix add this to each cherrypy
cherrypy.config.update({'server.socket_host': '127.0.0.1',
'server.socket_port': 9023
})

Related

Node.js / curl(7) failed to connect to localhost port 3000. How to fix it?

response from testing
code hello.js
i am trying to create a web service with node.js. Unfortunately after implementing the application hello.js i am only able to test successfully "node hello.js", but furthermore when i type in "curl http://localhost:3000" i am getting "curl: (7) Failed to connect to localhost port 3000: connection estavlishment rejected"
This also happens with other ports oder when i type 127.0.0.1 directly. I also disabled my firewall with ufw and allow 3000 with ufw.
I am working with VirtualBox for a uni project. I am running everything in the VM. The goal is to cluster with docker and i need the web server for loadbalancing in the end.
Thanks!
The issue here that you use same terminal for multiple processes. As soon as you start the server, it holds the terminal. It means when you press Ctrl + C (^c in terminal output), you stop the server.
In your case you should use two terminals. In the first one you start the server (and do nothing with this particular terminal), in second one you make the request. Or you can change second step and make request from browser (it will be GET request by default), Postman, Insomnia etc.

docker-searXNG: I cannot start a tor searXNG instance (Debian)

I am kinda new to docker and as for my first project I wanted to try and start a searXNG instance on tor. There have been many people who have accomplished that, yet I cannot figure out whats wrong.
I've installed tor, searxng-docker and docker-compose on my raspberry pi (it is running raspberry pi os lite), got the .onion hostname and put it in .env and then, I got the instance running. But when I checked the link, it gave me a 404.
Can anyone help? I would really appreciate that.
The output of sudo docker ps:
The .env file (I've hide my email:
Do you want your server to be only available on Tor as a hidden service?
This is not supported out of the box.
Here some information that should help:
Add http:// in front of your server name in .env: SEARXNG_HOSTNAME=http://gpfo...onion
In Caddyfile, add bind 127.0.0.1 just before line 10 (tls {$SEARXNG_TLS}).
In torrc, but sure to have HiddenServicePort 80 127.0.0.1:80 in addition to HiddenServiceDir.

Running Logux on Google Cloud Run doesn't find the running port

While trying to get Logux running in Cloud Run, I get this error:
Container failed to start. Failed to start and then listen on the port defined by the PORT environment variable.
Even though the server is running an the Dockerfile is exposing the correct port (which is mapped in Cloud run as well).
The Dockerfile is located here: https://github.com/knownasilya/battle-chess/blob/main/Dockerfile
Note that the server runs https and ws on port 31337.
As mentioned by the Cloud Run Troubleshooting docs, if we get the message:
Container failed to start. Failed to start and then listen on the port defined by the PORT environment variable.
And we know our code/container is working as expected, we should check that the port that that Cloud Run will be checking correlates with the one used in our app and like in this case, that the container listens on 0.0.0.0 (all the net interfaces)
As well this is mentioned in the Cloud Run Requirements doc:
The container must listen for requests on 0.0.0.0 on the port to which requests are sent. By default, requests are sent to 8080, but you can configure Cloud Run to send requests to the port of your choice. Cloud Run injects the PORT environment variable into the container. Inside Cloud Run container instances, the value of the PORT environment variable always reflects the port to which requests are sent. It defaults to 8080.

Run 2 Python3 `http.server` on the same machine, different ports

Situation: Need 2 ad-hoc Python3 http.server instances on the same computer.
Problem: The first server was started successfully on the command line
python3 -m http.server 8888
The second server was attempted with the following script:
import http.server
import socketserver as ss
os.chdir("/path/to/working/directory")
Handler = http.server.SimpleHTTPRequestHandler
with ss.TCPServer(("", 8000), Handler) as httpd:
try:
httpd.serve_forever()
except PermissionError:
print("Permission denied.")
The second server terminated with OSError: [Errno 98] Address already in use.
Question: How can I run two Python3 http.server on the same machine (listening on 0.0.0.0)?
Additional Information 1: I have checked, and there are no other services holding onto port 8888 (server 1's port), and 8000 (server 2's port).
Additional Information 2: I am not sure why, but if I reverse the two ports, both servers run as intended (i.e. server 1 runs on port 8000; server 2 runs on 8888). Any ideas why?

Running NodeJs application on port 80 of amazon linux

I am trying to get a NodeJs application to run on a Amazon Linux server using port 80. Currently when I run the app it is defaulting to port 1024. I understand that this is due to the fact that I have to be root to run on port 80 but given I am on a aws linux box I am not able to run that as root. I have been digging for awhile but I am coming up short on what I need to adjust to get this to run properly.
sudo bash will allow you to connect as root on your EC2 Amazon Linux instance.
I would question why do you want to run NodeJS on port 80, the best practice would have a load balancer in front of your instance to accept HTTPS calls and relay to whatever port nodejs will run on your instance, in a private subnet.
I would suggest to read this doc to learn how to do this : https://aws.amazon.com/getting-started/projects/deploy-nodejs-web-app/

Resources