tobyweston / temperature-machine

Data logger for multiple DS18B20 temperature sensors on one or more machines
Apache License 2.0
67 stars 22 forks source link

Port already in use when starting up #66

Closed tobyweston closed 6 years ago

tobyweston commented 6 years ago

Trying to start up with the temperature-machine command (or even to check the version) will fail if it is already running. The message is as follows.

$ temperature-machine -- -v
Error: Exception thrown by the agent : java.rmi.server.ExportException: Port already in use: 1616; nested exception is: 
    java.net.BindException: Address already in use

It'd be nicer to report that the server is already running and to stop it before trying again.

The following

nc -z 127.0.0.1 11900; echo $?

...will return 0 if it is running (could use port 1616 also). Could use this in the startup script to check and fail before even trying to startup the JVM.

tobyweston commented 6 years ago

Create a random port with

-Dcom.sun.management.jmxremote.port=0

but then it's tricky to communicate the chosen port with the outside world. One way would be to rely on Java's logging:

# jmx_logging.properties
handlers=java.util.logging.ConsoleHandler
.level=INFO
java.util.logging.ConsoleHandler.level=CONFIG
java.util.logging.ConsoleHandler.formatter=java.util.logging.SimpleFormatter
sun.management.jmxremote.level=CONFIG

and

-Djava.util.logging.config.file=jmx_logging.properties

which outputs the following on startup (which should appear in the main log TBC):

ConnectorBootstrap startRemoteConnectorServer
CONFIG: JMX Connector ready at: service:jmx:rmi:///jndi/rmi://UKLONLT929592:53250/jmxrmi
tobyweston commented 6 years ago

Fixed in 2.1