Cannot kill python program on port 8000 causing Tryton server socket.error - sockets

I have been getting more deeply involved in python for scientific computing (as a hobby) over the last 2 years and as I also have a medical degree, I really, really want to get a copy of GNU Health running on my new Kubuntu 15.10 OS so I can learn how it all works and play around with it! I followed the instructions to install it on this page: https://en.wikibooks.org/wiki/GNU_Health/Installation
I got pretty much to the end but when I try to launch the tryton server with ./trytond I get this error message:
[Thu Oct 29 10:25:02 2015] INFO:trytond.server:using /home/gnuhealth/gnuhealth/tryton/server/config/trytond.conf as configuration file
[Thu Oct 29 10:25:02 2015] INFO:trytond.server:initialising distributed objects services
Traceback (most recent call last):
File "./trytond", line 80, in <module>
trytond.server.TrytonServer(options).run()
File "/home/gnuhealth/gnuhealth/tryton/server/trytond-3.4.6/trytond/server.py", line 71, in run
self.start_servers()
File "/home/gnuhealth/gnuhealth/tryton/server/trytond-3.4.6/trytond/server.py", line 178, in start_servers
self.jsonrpcd.append(JSONRPCDaemon(hostname, port, ssl))
File "/home/gnuhealth/gnuhealth/tryton/server/trytond-3.4.6/trytond/protocols/jsonrpc.py", line 382, in __init__
self.server = server_class((interface, port), handler_class, 0)
File "/home/gnuhealth/gnuhealth/tryton/server/trytond-3.4.6/trytond/protocols/jsonrpc.py", line 317, in __init__
bind_and_activate)
File "/usr/lib/python2.7/SocketServer.py", line 420, in __init__
self.server_bind()
File "/home/gnuhealth/gnuhealth/tryton/server/trytond-3.4.6/trytond/protocols/jsonrpc.py", line 346, in server_bind
SimpleJSONRPCServer.server_bind(self)
File "/usr/lib/python2.7/SocketServer.py", line 434, in server_bind
self.socket.bind(self.server_address)
File "/usr/lib/python2.7/socket.py", line 228, in meth
return getattr(self._sock,name)(*args)
socket.error: [Errno 98] Address already in use
On further investigation with sudo netstat -pant | grep 8000 I get
tcp 0 0 127.0.0.1:8000 0.0.0.0:* LISTEN 2516/python
I have tried to kill this python program running on port 8000 every different way I could find but it keeps coming back with a new number in front i.e.
tcp 0 0 127.0.0.1:8000 0.0.0.0:* LISTEN 916/python
I kill it then...
tcp 0 0 127.0.0.1:8000 0.0.0.0:* LISTEN some_other_number etc../python
Can someone please explain what is going on with this python program keeping on restarting and how I fix this one little problem getting in the way of me starting the server!?

I was looking at the install instructions you mentioned.
Look at this section:
Activate Network Devices for the JSON-RPC Protocol
The Tryton GNU Health server listens to localhost at port 8000, not allowing direct connections from other workstations.
editconf
You can edit the parameter listen in the [jsonrpc] section , to activate the network device so workstations in your net can connect. For example, the following block
[jsonrpc]
listen = *:8000
will allow to connect to the server in the different devices of your system.
Check if you can change the value of the port and see if it works.
Use a port number that is unused. Use this command to check whether the port number is available. It has to be greater than 1024.
netstat -nlp | grep <self-chosen-hopefully-unused-port-number>
Hope this helps.

Related

Adafruit minimqtt on Pi Pico H with Wiznet RP2040 ethernet hat "RuntimeError: Failed to establish connection."

I'm trying to use the adafruit minimqtt library on a Pi Pico H, running circuitpython. I've been following this guide
I'm using a mosquito broker on my windows 10 laptop and connecting directly through an ethernet cable to the Wiznet hat, as in the tutorial. The code I'm using is copied directly from the example with the following changes:
changed the IP address on line 22 to that of my windows machine
uncommneted lines 68 and 70, and commented out line 73 to avoid using DHCP (someone else on the github has noted that the dhcp doesn't work). Also deleted the extra space in line 70
I get the following error:
Traceback (most recent call last):
File "<stdin>", line 84, in <module>
File "/lib/adafruit_minimqtt/adafruit_minimqtt.py", line 441, in connect
File "/lib/adafruit_minimqtt/adafruit_minimqtt.py", line 266, in _get_connect_socket
File "/lib/adafruit_wiznet5k/adafruit_wiznet5k_socket.py", line 246, in connect
File "/lib/adafruit_wiznet5k/adafruit_wiznet5k.py", line 570, in socket_connect
RuntimeError: Failed to establish connection.
I've looked through each of the scripts referenced and can't find any obvious errors (I'm not an expert in this so there might be something I've missed). I can't find anyone who's experienced this same error code, any help here would be appreciated.
I've tried running the first half of the code (up to line 68), and then pinging the pico from my laptop. I've also pinged my laptop from the board. Both were successful, so I don't think it's a hardware issue.
I've double checked that my broker is not in local mode. My .conf file contains
listener 1883
allow_anonymous true
and when I run mosquitto I get
C:\Users\me1xmtx\mosquitto>mosquitto -c rem.conf -v
1676306316: mosquitto version 2.0.15 starting
1676306316: Config loaded from rem.conf.
1676306316: Opening ipv6 listen socket on port 1883.
1676306316: Opening ipv4 listen socket on port 1883.
1676306316: mosquitto version 2.0.15 running
TCP (and UDP just in case) ports 1883 are open on the windows laptop

PyMongo AutoReconnect: timed out

I work in an Azure environment. I have a VM that runs a Django application (Open edX) and a Mongo server on another VM instance (Ubuntu 16.04). Whenever I try to load anything in the application (where the data is fetched from the Mongo server), I would get an error like this one:
Feb 23 12:49:43 xxxxx [service_variant=lms][mongodb_proxy][env:sandbox] ERROR [xxxxx 13875] [mongodb_proxy.py:55] - Attempt 0
Traceback (most recent call last):
File "/edx/app/edxapp/venvs/edxapp/local/lib/python2.7/site-packages/mongodb_proxy.py", line 53, in wrapper
return func(*args, **kwargs)
File "/edx/app/edxapp/edx-platform/common/lib/xmodule/xmodule/contentstore/mongo.py", line 135, in find
with self.fs.get(content_id) as fp:
File "/edx/app/edxapp/venvs/edxapp/local/lib/python2.7/site-packages/gridfs/__init__.py", line 159, in get
return GridOut(self.__collection, file_id)
File "/edx/app/edxapp/venvs/edxapp/local/lib/python2.7/site-packages/gridfs/grid_file.py", line 406, in __init__
self._ensure_file()
File "/edx/app/edxapp/venvs/edxapp/local/lib/python2.7/site-packages/gridfs/grid_file.py", line 429, in _ensure_file
self._file = self.__files.find_one({"_id": self.__file_id})
File "/edx/app/edxapp/venvs/edxapp/local/lib/python2.7/site-packages/pymongo/collection.py", line 1084, in find_one
for result in cursor.limit(-1):
File "/edx/app/edxapp/venvs/edxapp/local/lib/python2.7/site-packages/pymongo/cursor.py", line 1149, in next
if len(self.__data) or self._refresh():
File "/edx/app/edxapp/venvs/edxapp/local/lib/python2.7/site-packages/pymongo/cursor.py", line 1081, in _refresh
self.__codec_options.uuid_representation))
File "/edx/app/edxapp/venvs/edxapp/local/lib/python2.7/site-packages/pymongo/cursor.py", line 996, in __send_message
res = client._send_message_with_response(message, **kwargs)
File "/edx/app/edxapp/venvs/edxapp/local/lib/python2.7/site-packages/pymongo/mongo_client.py", line 1366, in _send_message_with_response
raise AutoReconnect(str(e))
AutoReconnect: timed out
First I thought it was because my Mongo server lived in an instance outside of the Django application's virtual network. I created a new Mongo server on an instance inside the same virtual network and would still get these issues. Mind you, I receive the data eventually but I feel like I wouldn't get timed out errors if the connection is normal.
If it helps, here's the Ansible playbook that I used to create the Mongo server: https://github.com/edx/configuration/tree/master/playbooks/roles/mongo_3_2
Also I have tailed the Mongo log file and this is the only line that would appear at the same time I would get the timed out error on the application server:
2018-02-23T12:49:20.890+0000 [conn5] authenticate db: edxapp { authenticate: 1, user: "user", nonce: "xxx", key: "xxx" }
mongostat and mongotop don't show anything out of the ordinary. Also here's the htop output:
I don't know what else to look for or how to fix this issue.
I forgot to change the Mongo server IP's in the Django application settings to point to the new private IP address inside the virtual network instead of the public IP. After I've changed that it don't get that issue anymore.
If you are reading this, make sure you change the private IP to a static one in Azure, if you are using that IP address in the Djagno application settings.

GSM Shield with Raspberry Pi Port Open

I have connected a-gsm shield http://itbrainpower.net/a-gsm/downloadables/a-gsm-series-presentation-v1.01.pdf with Raspberry Pi 3.
I have imported and attempted to execute power on code http://itbrainpower.net/a-gsm/RaspberryPI-gsm-shield-library-powerOnOff-demo-code-a-gsm. However, I am getting the following error message:
sudo ./poweronoff.py
Traceback (most recent call last):
File "./poweronoff.py", line 66, in <module>
agsm.open()
File "/usr/lib/python2.7/dist-packages/serial/serialposix.py", line 271, in open
raise SerialException("Port is already open.")
serial.serialutil.SerialException: Port is already open.
I assume I need to open a different port. If that is the solution, how do I do it. If that is not the solution, what do I need to do to satisfy this error message?
Follow directions in this post https://www.raspberrypi.org/forums/viewtopic.php?uid=195125&f=28&t=165897&start=0.
Basically, "enable_uart=1" should be the last line in '/boot/config.txt' for serial port operations. Reboot the RPi3 and everything should work.

Jupyterhub on Google compute engine

I'm trying to set up a Jupyterhub instance to serve IPython notebooks on a Google Compute Engine. However, when running jupyterhub i am faced with an error regarding sockets:
[E 2015-08-31 10:27:55.617 JupyterHub app:1097]
Traceback (most recent call last):
File "/home/esten/anaconda3/envs/py3k/lib/python3.3/site- packages/jupyterhub/app.py", line 1095, in launch_instance_async
yield self.start()
File "/home/esten/anaconda3/envs/py3k/lib/python3.3/site-packages/jupyterhub/app.py", line 1027, in start
self.http_server.listen(self.hub_port, address=self.hub_ip)
File "/home/esten/anaconda3/envs/py3k/lib/python3.3/site-packages/tornado/tcpserver.py", line 126, in listen
sockets = bind_sockets(port, address=address)
File "/home/esten/anaconda3/envs/py3k/lib/python3.3/site-packages/tornado/netutil.py", line 187, in bind_sockets
sock.bind(sockaddr)
OSError: [Errno 99] Cannot assign requested address
The address/port assigned by the config file is localhost/8081, and binding a socket like below works perfectly fine
import socket
s = socket.socket()
s.bind(("localhost", 8081))
Does jupyterhub look somewhere else for the information or is something done differently when binding the socket through my own code?
This seems to be a problem with GCE not supporting ipv6.
I found this link explaining that enabling ipv6 solved the issue on another machine.
Running using --ip solved the issue:
jupyter notebook --ip="*"

Cherrypy Daemon shutdown fails

I've followed the Cherrypy daemon webapp skeleton Deploying CherryPy (daemon) which is great. But I've got a shutdown problem.
The server in question is using port 8082. When the shutdown comes from the init.d script it hits the webapp-cherryd equivalent and then throws errors.
XXX#mgmtdebian7:/etc/init.d# ./XXX stop
[11/Jul/2014:09:39:25] ENGINE Listening for SIGHUP.
[11/Jul/2014:09:39:25] ENGINE Listening for SIGTERM.
[11/Jul/2014:09:39:25] ENGINE Listening for SIGUSR1.
[11/Jul/2014:09:39:25] ENGINE Bus STARTING
[11/Jul/2014:09:39:25] ENGINE Started monitor thread 'Autoreloader'.
[11/Jul/2014:09:39:25] ENGINE Started monitor thread '_TimeoutMonitor'.
[11/Jul/2014:09:39:30] ENGINE Error in 'start' listener <bound method Server.start of <cherrypy._cpserver.Server object at 0xe60e10>>
Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/CherryPy-3.2.4-py2.7.egg/cherrypy/process/wspbus.py", line 197, in publish
output.append(listener(*args, **kwargs))
File "/usr/local/lib/python2.7/dist-packages/CherryPy-3.2.4-py2.7.egg/cherrypy/_cpserver.py", line 151, in start
ServerAdapter.start(self)
File "/usr/local/lib/python2.7/dist-packages/CherryPy-3.2.4-py2.7.egg/cherrypy/process/servers.py", line 168, in start
wait_for_free_port(*self.bind_addr)
File "/usr/local/lib/python2.7/dist-packages/CherryPy-3.2.4-py2.7.egg/cherrypy/process/servers.py", line 412, 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'
[11/Jul/2014:09:39:30] ENGINE Shutting down due to error in start listener:
Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/CherryPy-3.2.4-py2.7.egg/cherrypy/process/wspbus.py", line 235, in start
self.publish('start')
File "/usr/local/lib/python2.7/dist-packages/CherryPy-3.2.4-py2.7.egg/cherrypy/process/wspbus.py", line 215, in publish
raise exc
ChannelFailures: IOError("Port 8080 not free on '127.0.0.1'",)
[11/Jul/2014:09:39:30] ENGINE Bus STOPPING
[11/Jul/2014:09:39:30] ENGINE HTTP Server cherrypy._cpwsgi_server.CPWSGIServer(('127.0.0.1', 8080)) already shut down
[11/Jul/2014:09:39:30] ENGINE Stopped thread '_TimeoutMonitor'.
[11/Jul/2014:09:39:30] ENGINE Stopped thread 'Autoreloader'.
[11/Jul/2014:09:39:30] ENGINE Bus STOPPED
[11/Jul/2014:09:39:30] ENGINE Bus EXITING
[11/Jul/2014:09:39:30] ENGINE Bus EXITED
XXX#mgmtdebian7:/etc/init.d#
From the surfing I've done thus far I've believe that the service is trying to restart in response to the SIGHUP signal and that it's picking up a default port of 8080 (which isn't & shouldn't be free) and therefore failing.
This leaves the service running - not what's wanted..
BTW my config that sets the port to 8082 is inside the module I load - rather than in a config file.
Thanks for any pointers in anticipation.
As the log clearly states CherryPy is attempting to start on 127.0.0.1:8080 and fails after 5 seconds. So you actually have a start up fail and likely it is because in my config that sets the port to 8082 is inside the module I load - rather than in a config file you don't set the port correctly and CherryPy uses default 8080.
Also I'd like to note that you shouldn't use Autoreloader in production. The cherrypy-webapp-skeleton init.d script sets production CherryPy environment which has Autoreloader off.
So when you do
cherrypy.tree.graph(app, "/")
you are by default creating a server instance on localhost:8080, but it doesnt actually get started until you call cherrypy.engine.start().
You are probably doing something like this
E.g. :
cherrypy.tree.graft(app, "/") # registers a server on localhost:8080
server = cherrypy._cpserver.Server() # registers a second server...
server.socket_host="0.0.0.0" # ..on 0.0.0.0 ...
server.socket_port = 5002 # ..with port 5002
server.thread_pool = 10
server.subscribe()
cherrypy.engine.start() #starts two server instances
cherrypy.engine.block()
will cause cherry py to start two server instances, one on localhost:8080, and another on 5002.
The answer is to instead do:
cherrypy.tree.graft(app, "/")
cherrypy.server.unsubscribe() # very important gets rid of default.
server = cherrypy._cpserver.Server()
server.socket_host="0.0.0.0"
server.socket_port = 5002
server.thread_pool = 10
server.subscribe()
cherrypy.engine.start() #now starts only one server instance
cherrypy.engine.block()
Your problem above is that you are staring two servers, and only one of them is falling over/erroring/closing, so port 8080 is still bound to local host and prevents a restart..