Has anybody successfully run mosquitto on the openshift online version in a free account?
There are two SO questions relevant but not really solve all the questions:
- "How to connect to my MQTT Broker in Openshift". It runs JBoss Fuse and needs either the SNI feature on the server or the port-forwarding on the client.
- "How can I access socket through Openshift". The author mentions running mosquitto but there is no details as to how.
Stuffs that have been done so far:
- I have run a python websocket server thus to have verified openshift does support websocket nicely though the DIY cartridge.
- I have also compiled mosquitto and run it locally with a sample off github.
What is the exact steps to put mosquitto to run on the openshift from here?
Finally I got it working on openshift, though with a simplest configuration. Here is the key steps:
DIY
cartridge to get the websocket support which exposes external port8000
and that is routed to internal port8080
on an virtual IP address specified byOPENSHIFT_DIY_IP
.config.mk
just to avoid installing lot of packages to openshift:WITH_TLS
,WITH_TLS_PSK
,WITH_THREADING
,WITH_BRIDGE
,WITH_SRV
,WITH_UUID
,WITH_DOCS
,WITH_SOCKS
.Makefile
of mosquitto to comment out the command to install fromDOCSDIR
. This seems to be a minor bug in mosquitto because if theWITH_DOCS
is turned off it should not try to install fromDOCSDIR
.WITH_WEBSOCKETS
inconfig.mk
.src/webockets.c
. In the functionmosq_websockets_init()
at about line 625, add a line ofinfo.iface = listener->host;
, below the line which isinfo.user = user;
. This is to make mosquitto able to bind to the virtual IP address in the openshift DIY gear. By default mosquitto only allow you to bind to0.0.0.0
for any IP address. This seems to be a disconnection between mosquitto and libwebosockets.libwebsockets
andlibwebsockets-devel
packages.make
to build mosquitto.../mosrun
directory. Create the directory. Runmake prefix= DESTDIR=$(pwd)/../mosrun install
.../mosrun
exceptsbin
.cd ../mosrun/sbin
andcp /usr/lib/libwebsockets.so.7 .
. Adjust the source path of your stock libwebsockets lib.https://github.com/jpmens/simple-mqtt-websocket-example
. Put them into yourmosrun/sbin/simpleweb
directory.mosrun/sbin/simpleweb/config.js
to use your openshift DIY domain name, and port 8000. This is where the javascript connects to your DIY server from a browser.mosrun/sbin/mosquitto.conf
which contains four lines:listener 8080 <OPENSHIFT_DIY_IP>
,protocol websockets
,http_dir simpleweb
, andconnection_messages
. Use your actual DIY virtual IP address in place of<OPENSHIFT_DIY_OP>
..openshift/action_hooks/start
and.../stop
scripts to comment out the existing commands. Push to openshift. Now you should not be able to connect to the default server but the gear is running.mosrun/sbin
directory.LD_LIBRARY_PATH=. ./mosquitto -c mosquitto.conf -v
to start mosquitto.diy-yourdomain.rhcloud.com:8000/index.html
. You shall see the mqtt websockets test page copied from jpmen's github repo.The next step would be to move the tree into DIY git tree. Modify the start and stop hooks to start and stop your mosquitto instead of the default server. And a script running on the openshift gear to create the
config.js
andmosquitto.conf
from the actual openshift environment variables.Tow posts are very helpful to guide you through the steps of building mosquitto: the blog by jpman, and the blog by Jeremy Gooch.
In case anyone else runs across this post; I have a non-websocket Mosquitto running on OpenShift v3.11: https://github.com/john2exonets/OpenShift-MQTT-Mosquitto