[SOLVED] OH1 upgrade from jessie to stretch -> connection refused

Upgrade my Raspberry Pi 2 Model B from Jessie to Stretch; still running OHv1

Mosquitto is working as tested between two terminals, while I run mosquitto -v in a third terminal.
when I stop mosquitto in the third terminal pub/sub between terminal 1 and 2 no longer works as expected.

When I sudo service mosquitto start I get an error Error: Address already in use in the /var/log/mosquitto/broker.log.

May 24 17:29:01 rpiautomation mosquitto[4732]: Config loaded from /etc/mosquitto/mosquitto.conf.
May 24 17:29:01 rpiautomation mosquitto[4732]: Opening ipv4 listen socket on port 1883.
May 24 17:29:01 rpiautomation mosquitto[4732]: Opening ipv6 listen socket on port 1883.
May 24 17:29:01 rpiautomation mosquitto[4732]: Opening ipv4 listen socket on port 8883.
May 24 17:29:01 rpiautomation mosquitto[4732]: Opening ipv6 listen socket on port 8883.
May 24 17:29:01 rpiautomation mosquitto[4732]: Opening ipv4 listen socket on port 1883.
May 24 17:29:01 rpiautomation mosquitto[4732]: Error: Address already in use

sudo netstat -tulpn | grep :1883 shows no result;
neither does sudo netstat -tulpn | grep :8883.

Of course openHABv1, throws an error:

2018-05-24 17:01:19.865 [INFO ] [o.i.t.m.i.MqttBrokerConnection] - Starting MQTT broker connection 'mymosquitto'
2018-05-24 17:01:20.417 [ERROR] [.io.transport.mqtt.MqttService] - Error starting broker connection
org.eclipse.paho.client.mqttv3.MqttException: Unable to connect to server
        at org.eclipse.paho.client.mqttv3.internal.TCPNetworkModule.start(TCPNetworkModule.java:75) ~[na:na]
        at org.eclipse.paho.client.mqttv3.internal.ClientComms$ConnectBG.run(ClientComms.java:538) ~[na:na]
        at java.lang.Thread.run(Thread.java:745) ~[na:1.8.0_65]
Caused by: java.net.ConnectException: Connection refused

Since most of my automation relies on MQTT, I am stuffed ā€“ more so down since 13:21.

Any ideas how to solve this?

May 24 17:29:01 rpiautomation mosquitto[4732]: Opening ipv4 listen socket on port 1883.
May 24 17:29:01 rpiautomation mosquitto[4732]: Opening ipv6 listen socket on port 1883.
May 24 17:29:01 rpiautomation mosquitto[4732]: Opening ipv4 listen socket on port 8883.
May 24 17:29:01 rpiautomation mosquitto[4732]: Opening ipv6 listen socket on port 8883.
May 24 17:29:01 rpiautomation mosquitto[4732]: Opening ipv4 listen socket on port 1883.

Why does it open a listen port twice on the same port on the same protocol? Seems to me that the daemon launcher or mosquitto install has become somewhat bugged. Try reinstalling mosquitto?

1 Like

Thanksā€¦ looking into thisā€¦ didnā€™t think of it muchā€¦

Uninstalled mosquitto.
Installed it againā€¦

config files were preservedā€¦

same result, still loading port 1883 twice, then failā€¦

checked the /etc/mosquitto/mosquitto.conf

# /etc/mosquitto/mosquitto.conf
#
# Place your local configuration in /etc/mosquitto/conf.d/
#

pid_file /var/run/mosquitto.pid
persistence true
persistence_location /var/lib/mosquitto/

# 170620-2106 MaxG: changed to none
#log_dest file /var/log/mosquitto/mosquitto.log
#log_dest none

# 170622-1822 MaxG: set to syslog, and then use rsyslog to log to separate log; then use logrotate to rotate them
log_dest syslog
log_facility 0
log_type error
log_type warning
log_type information
log_timestamp true

#include_dir /etc/mosquitto/conf.d

The last statement is of interest --> it was there before the upgrade to Stretch; however, commenting it out, led to a successful start of mosquittoā€¦ listening on port 1883.

May 24 18:39:32 rpiautomation mosquitto[11676]: mosquitto version 1.5 starting
May 24 18:39:32 rpiautomation mosquitto[11676]: Config loaded from /etc/mosquitto/mosquitto.conf.
May 24 18:39:32 rpiautomation mosquitto[11676]: Opening ipv4 listen socket on port 1883.
May 24 18:39:32 rpiautomation mosquitto[11676]: Opening ipv6 listen socket on port 1883.

the openHAB configuration was not touched, and is listening on 1883.
However, openHAB does not receive any updates from mosquittoā€¦
Well, a restart of the openHAB service resolved the issue.

All in all strangeā€¦ given that no config files were touched during the updateā€¦ yet some things work differentlyā€¦

Issue resolved!

Unless you go out of your way to install a program like Mosquitto from the source, what you get when you run apt-get install mosquitto is a version that has been tested and known to work with your particular distro (e.g. Debian Jessie). Programs that are not as popular often do not get updated that often in the patch updates to that distro. So when you do a major upgrade to a new version of a distro (e.g. Jessie to Stretch) many apps also involve major version updates. Often the programs are pretty stable and the difference between versions are pretty minor and the change is pretty transparent. Other times the differences can be as major as the change between Oh 1.8 and 2.0.

In this case it very much looks like the version of Mosquitto that ships with stretch has significantly changed how it manages the conf file to work more like standard Linux apps. In this case you have a main conf file that imports configs from a conf.d folder. So the proper way to add listeners would be to create a separate file for each one in the conf.d folder and use the include_dir in the main conf file to import them.

1 Like

While I have been working with *nixes for quite some time, I never really looked under the hood ā€“ as in how it all works togetherā€¦ settled for Ubuntu/Debian based distros (Mint for desktop; Rasbian for the Pis), and use apt-get to keep my house in orderā€¦ with no intend to deviate, based on the ā€˜fearā€™ of creating dependencies or do the wrong thing, or have to manually keep things up to date.

I am aware of the Jessie -> Stretch issues, in particular with mosquitto and openssl and some libxxxx, but the latest mosquitto v1.5, and the issues have been resolvedā€¦ also as I experienced with a quick check with sub/pub on different terminals.

So yes, firstly ā€˜thanksā€™ for the explanation, and secondly, I have excluded the include_dir directive, which made it work :slight_smile:
Since I only need port 1883, I am now aware and should the need arise configure 8883 in separate config files.