Hello,
This is a guide on how to setup a openHAB Cloud instance on the Google Cloud Platform. I was initially following the instructions on the Quick start guide, and while it was mostly successful, it still has some issues to be resolved. I am recreating the VM there (basically because I want to make the disk smaller, and CGP does not allow one to easily do this), so I will be rewriting and improving the instructions.
VM setup
Sizing: micro (1 vCPU, 0.6 GB memory) - it may give you occasional performance warnings, but it could run mostly well enough
Disk: 10 GB HDD - minimum size required by the OS image, it should be more than sufficient
Firewall: Allow HTTPS traffic
Preemptibility: Off (recommended)
OS: Ubuntu 17.10
Before starting anything else, after connecting to the VM via SSH, get the latest packages:
sudo apt-get update
sudo apt-get upgrade
DNS configuration
A record created, pointing âmydomain.comâ to the public IP of the VM instance. One option is to assign a static IP to the instance (but then you must keep it constantly running, otherwise you will be charged). To avoid that, you may want to use ddclient and configure it to regularly push your ephemeral IP to your DNS configuration:
sudo apt-get install ddclient
sudo vi /etc/ddclient.conf
openHAB Cloud install
sudo apt-get install build-essential redis-server mongodb nginx python git
cd /opt
sudo git clone https://github.com/openhab/openhab-cloud.git
cd openhab-cloud
sudo apt-get install npm
node --version
sudo npm install (lots of warnings while installing the dependencies)
redis-cli ping
Redis answered âPONGâ, so letâs move to the web server setup.
Nginx configuration
sudo cp /opt/openhab-cloud/etc/nginx_openhabcloud.conf /etc/nginx/sites-available/default
cd /etc/nginx/sites-available
sudo sed -i 's/opt\/openhabcloud/opt\/openhab-cloud/g' default
sudo sed -i 's/your-openhab-cloud-host/mydomain.com/g' default
Here we have defined the domain name, and replaced /openhabcloud with /openhab-cloud, as the nginx default configuration does not match the installation directory name. If you donât do this, the login page will load, but without any formatting:
Before restarting the web server, we can generate the SSL certificate. To keep it simple for now, you may generate a self-signed cert (or use Letâs Encrypt as described further below) and then restart the service:
sudo openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout /etc/nginx/ssl/openhabcloud.key -out /etc/nginx/ssl/openhabcloud.crt
sudo service nginx restart
Final configuration and service startup
You first need to configure the application:
sudo cp config-production.json config.json
sudo vi config.json
"system": {
"host": "mydomain.com",
[...]
"mongodb": {
"hosts": ["127.0.0.1"],
"db": "openhab",
},
[...] Plus SMTP settings for "mail" and "mailer"
<ESC> :wq!
Please notice that mongodb
come with a (blank) user and password, you need to remove these in order for the connection to work. You may also want to remove the password from redis
, as leaving the blank entry could cause a warning in the logs. In a nutshell, besides removing these credentials, I only changed the domain name and defined SMTP configuration.
It is finally time to try to start openHAB Cloud as follows:
sudo node app.js
After trying to restart openHAB Cloud again, got an error, âCannot find module ââŠ/build/Debug/addonââ. After some additional searching on the web, this is how I could fix the issue and finally start it successfully:
npm rebuild (you may also need to upgrade nodejs to +7.10.1)
sudo node app.js
2018-01-04T05:38:43.539Z - info: openHAB-cloud: Backend service is starting up...
2018-01-04T05:38:43.548Z - info: openHAB-cloud: Backend logging initialized...
2018-01-04T05:38:44.071Z - info: openHAB-cloud: Initializing XMPP connection to GCM
2018-01-04T05:38:44.286Z - info: openHAB-cloud: Connecting ro Redis at 127.0.0.1:6379
2018-01-04T05:38:47.103Z - info: openHAB-cloud: Mailer will emulate sending in development environment
2018-01-04T05:38:47.304Z - info: opneHAB-cloud: Trying to connect to mongodb at: mongodb://127.0.0.1/openhab?poolSize=100
2018-01-04T05:38:47.361Z - info: openHAB-cloud: Scheduling a statistics job (every 5 min)
2018-01-04T05:38:48.220Z - info: openHAB-cloud: IFTTT is configured, app handling IFTTT capabilities...
Option polling duration is not valid. Please refer to the README.
2018-01-04T05:38:48.272Z - info: openHAB-cloud: express server listening on port 3000
2018-01-04T05:38:48.280Z - info: openHAB-cloud: Redis connect response: OK
2018-01-04T05:38:48.281Z - info: Redis is ready
2018-01-04T05:38:48.459Z - info: openHAB-cloud: Successfully connected to mongodb
2018-01-04T05:38:48.462Z - warn: openHAB-cloud: GCM XMPP error: XMPP authentication failure