Cherrypy Daemon shutdown fails - daemon

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..

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

Remote Logging using Log4j2

So i have this task to log activities to a file, but it has to be done
remotely on the server side, Remote logging.
NOTE : Remote Logging has to be in latest version of Log4j2(2.10)
My task was simple
Send logging info to a port.
Log info from port to a file.
My Discoveries
Socket Appender exist which help send info to a port. This is it, you dont need to create a client side code or anything.
Socket appender configuration in log4j2.properties
appender.socket.type = Socket
appender.socket.name= Socket_Appender
appender.socket.host = "IP address"
appender.socket.port = 8101
appender.socket.layout.type = SerializedLayout
appender.socket.connectTimeoutMillis = 2000
appender.socket.reconnectionDelayMillis = 1000
appender.socket.protocol = TCP
Adapting from here. But this is also log4j 1.x adaptation.
I found out that before log4j 2.6 to listen to a port we used TcpSocketServer which started a server using LogEventBridgeThis helped reach that conclusion. This class was in core.net.server which is no longer available.Assuming it is not used anymore and the only similar/closest class, TcpSocketManager.Other links that helped. How to use SocketAppend?
Then i tried this
public static final Logger LOG=LogManager.getLogger(myapp.class.getName());
main(){
LOG.debug("DEBUG LEVEL");
}
and got the following error
main ERROR TcpSocketManager (TCP:IPAddress:8111) caught exception
and will continue: java.net.SocketTimeoutException: connect timed out
I know this work because i made it read to a socket but there was no one listening, but somehow i messed up big time and there was a code change.
I need help how to go ahead. Thank You in advance
The socket server to remotely receive log events has been moved to a separate repository: https://github.com/apache/logging-log4j-tools
This still needs to be released.

failed to find free socket port for process dispatcher when trying remote debug

Highlights:
windows 10 host machine
ubuntu vagrant box (virtualbox) as guest vm
using vagrant port forwarding as like this: config.vm.network "forwarded_port", guest: 1234, host: 12340
IDE: IntelliJ IDEA with Ruby plugin
The Issue:
I've tried to set up remote ruby debug following this guide and getting an error in IDE: "failed to find free socket port for process dispatcher". It looks this issue is not IntelliJ-specific, I was able to reproduce it with latest RubyMine as well.
From IDEA's log
2017-07-07 21:53:03,515 [8879188] INFO - tion.impl.ExecutionManagerImpl - Failed to find free socket port for process dispatcher
com.intellij.execution.ExecutionException: Failed to find free socket port for process dispatcher
at org.jetbrains.plugins.ruby.ruby.debugger.RubyProcessDispatcher.<init>(RubyProcessDispatcher.java:46)
at org.jetbrains.plugins.ruby.ruby.debugger.RubyRemoteDebugRunner.doExecute(RubyRemoteDebugRunner.java:62)
...
Caused by: java.net.BindException: Address already in use: JVM_Bind
at java.net.TwoStacksPlainSocketImpl.socketBind(Native Method)
at java.net.TwoStacksPlainSocketImpl.socketBind(TwoStacksPlainSocketImpl.java:137)
...
I can understand it says Address already in use: JVM_Bind, but how remote debug supposed to work at all then? (I mean Is there any way to access guest vm port not forwarding it before? Clearly no) Any help to solve this issue is much appreciated.
For me the issue was due to another debug session that was open in the background. To prevent that from happening again (and also close all other currently open sessions, once you run the configuration again) select "Single instance only" in the Debug Configuration:

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

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.

The Datastax cassandra community server 2.1.10 service on local computer started and then stopped

I am trying to configure a two node cluster with cassandra in windows r2 2008
So i installed cassandra community version in one server (10.xxx.0.1,10.xxx.0.2)
And then I stopped the service and then edited the configuraton.yaml file in the conf folder.
The changes are:
cluster_name
commented the num_tokens
gave the tokens in initial_token,
seeds as 10.xxx.0.1,10.xxx.0.2,
listen_addresses are their respective ip addresses which are 10.xxx.0.1,10.xxx.0.2,
rpc_addresses as 0.0.0.0,
endpointsnitch as gossip
I also changed the cassandra rackdc.properties file to dc=DC1 rack=RAC1.
I then saved and started back the service and opened the cqlsh, but it is not connecting. Below is the error:
2015-10-12 16:20:13 Commons Daemon procrun stderr initialized
If rpc_address is set to a wildcard address (0.0.0.0), then you must set broadcast_rpc_address to a value other than 0.0.0.0
Fatal configuration error; unable to start. See log for stacktrace.
..
ERROR 21:20:14 Fatal configuration error
org.apache.cassandra.exceptions.ConfigurationException: If rpc_address is set to a wildcard address (0.0.0.0), then you must set broadcast_rpc_address to a value other than 0.0.0.0
at org.apache.cassandra.config.DatabaseDescriptor.applyAddressConfig(DatabaseDescriptor.java:285) ~[apache-cassandra-2.1.10.jar:2.1.10]
at org.apache.cassandra.config.DatabaseDescriptor.applyConfig(DatabaseDescriptor.java:443) ~[apache-cassandra-2.1.10.jar:2.1.10]
at org.apache.cassandra.config.DatabaseDescriptor.<clinit>(DatabaseDescriptor.java:136) ~[apache-cassandra-2.1.10.jar:2.1.10]
at org.apache.cassandra.service.CassandraDaemon.setup(CassandraDaemon.java:168) [apache-cassandra-2.1.10.jar:2.1.10]
at org.apache.cassandra.service.CassandraDaemon.activate(CassandraDaemon.java:562) [apache-cassandra-2.1.10.jar:2.1.10]
at org.apache.cassandra.service.CassandraDaemon.main(CassandraDaemon.java:651) [apache-cassandra-2.1.10.jar:2.1.10]
If you out 0.0.0.0 to the rpc_address you have to change the broadcast_rpc_address like in http://docs.datastax.com/en/cassandra/2.1/cassandra/configuration/configCassandra_yaml_r.html , I think that the right broadcast_rpc_address can be the own ip address.