Problems with OpenHAB Cloud

I have installed OpenHAB Cloud on Ubuntu 22.04 on AWS. After starting nginx and app.js, I get a 500 error from nginx when trying to access it with a browser.
The log shows:
024/06/17 18:57:55 [error] 449#449: *1 connect() failed (111: Unknown error) while connecting to upstream, client: 73.234.97.133, server: , request: “GET /favicon.ico HTTP/1.1”, upstream: “http://127.0.0.1:3000/favicon.ico”, host: “52.23.169.119”, referrer: “http://52.23.169.119/

What is your configuration ?

Ubuntu 22.04.4 LTS, Node 14.21.3, Python 3.10.12
I had to install MongoDB separately (7.0)
I did not significantly change the nginx default file (other than replacing openhabcloud by openhab-cloud) nor config.json. I did not name a server_name (no dns name for my instance).
Anything else I should look at or should have changed?
Thanks.

In nohup.out, I am seeing a problem that Authkey.p8 is not found. Removing apn from config.js does not help, but leads to ‘module not found’ errors.
app.js is running ( ps aux | grep node), but a curl http://127.0.0.3000 shows a connection refused.
Any suggestions?

Are there any versions of dependencies that ‘golden’? For instance, could my problems be caused by the wrong version of node, mongodb, Ubuntu or something else?

Not sure how the forum works. I posted some info on the thread about my configuration. Any hints would be highly appreciated, thanks.

What is significant ? E.g. in the config.json file you have to enter your servers names for host and proxyhost. I would say that this is significant or at least essential.

Thanks, and of course you are right.
Here is the config.json file

{
“system”: {
“host”: “openhabcloud.foobar.com”,
“listenIp”: “0.0.0.0”,
“port”: “80”,
“protocol”: “http”,
“logger” : {
“dir”: “./logs”,
“maxFiles” : “7d”,
“level” : “debug”,
“morganOption” : null
},
“subDomainCookies”: false,
“muteNotifications”: false
},
“express”:{
“key” : “some express key”
},
“apn” : {
“team”: “PB1234567”,
“keyId”: “BLABLA1”,
“defaultTopic”: “es.spaphone.openhab”,
“signingKey”: “certs/aps/AuthKey.p8”
},
“gcm” : {
“senderId”: “1234567890”,
“serviceFile” : “serviceAccountKey.json”
},
“ifttt” : {
“iftttChannelKey” : “key”,
“iftttTestToken” : “token”
},
“mail”: {
“host” : “smtp”,
“port” : 465,
“user” : “foo@bar.com”,
“pass” : “password”
},
“mongodb”: {
“hosts”: [“127.0.0.1”],
“db”: “openhab”
},
“redis”: {
“host”: “127.0.0.1”,
“port”: “6379”
},
“mailer”: {
“host” : “smtp”,
“port”: 465,
“secureConnection”: true,
“user”: “foo@bar.com”,
“password”: “password”,
“from”: “openHAB Cloud kristofrk@gmail.com
},
“legal”: {
“terms” : “”,
“policy”: “”
},
“registration_enabled”: false
}

I added a dummy name for the host. I am using an AWS EC2 instance, I don’t have a fixed DNS name. Should I use the IP address, instead?
I also changed the port to 80 and the protocol to http.

Here is the nginx ‘default’ file

#This file was modified to comment out the dns name and to change the paths from openhabcloud to openhab-cloud
server {
#listen *:443;
#listen *:80;
listen *:80 default_server;
ssl on;

ssl_certificate /etc/nginx/ssl/YOUR-KEY.crt;

ssl_certificate_key /etc/nginx/ssl/YOUR-KEY.key;

#ssl_certificate /etc/nginx/ssl/YOUR-CER.crt;
#ssl_certificate_key /etc/nginx/ssl/YOUR-KEY.key;

#server_name YOUR-DNS-NAME;

if ( $scheme = “http” ) {

rewrite ^/(.*)$ https://$host/$1 permanent;

#}

charset utf-8;

access_log /var/log/nginx/openhab-cloud.org-access.log;
error_log /var/log/nginx/openhab-cloud-error.log;
client_max_body_size 300m;

location / {

root /var/www/html;

index index.nginx-debian.html;

#}

location /css {
alias /home/ubuntu/openhab-cloud/public/css;
}
location /js {
alias /home/ubuntu/openhab-cloud/public/js;
}
location /img {
alias /home/ubuntu/openhab-cloud/public/img;
}
location /bootstrap {
alias /home/ubuntu/openhab-cloud/public/bootstrap;
}
location /font-icons {
alias /home/ubuntu/openhab-cloud/public/font-icons;
}
location /fonts {
alias /home/ubuntu/openhab-cloud/public/fonts;
}
location /js-plugin {
alias /home/ubuntu/openhab-cloud/public/js-plugin;
}
location /staff/js-plugin {
alias /home/ubuntu/openhab-cloud/public/js-plugin;
}
location /downloads {
alias /home/ubuntu/openhab-cloud/public/downloads;
}
location / {
proxy_pass http://localhost:3000;
proxy_redirect off;
proxy_http_version 1.1;
proxy_set_header Host $host;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection “upgrade”;
proxy_set_header X-Real-IP $remote_addr ;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for ;
proxy_set_header X-Forwarded-Proto https;
}

I commented out the DNS name and change openhabcloud to openhab-cloud to match the installation path.
app.js tells me {“errno”:-2,“code”:“ENOENT”,“syscall”:“open”,“path”:“certs/aps/AuthKey.p8”}
nginx cannot connect to the upstream service, app.js.
2024/06/14 21:06:56 [error] 442#442: *1 connect() failed (111: Unknown error) while connecting to upstream, client: 34.140.130.61, server: , request: “GET / HTTP/1.1”, upstream: “http://127.0.0.1:3000/”, host: “34.224.215.205”

Thanks!

Have you checked if there is any error reported in the nginx error log file ?
Where does the rewrite rule come from ? Why do you need it ?
With regard to the AuthKey.p8 error: did you create that certificate ? If not remove the apn section from the config.js file and the error will be gone also means that actions related to that part can’t be used.

Sorry, the formatting of the default file didn’t come out too well when I copied it. The rewrite rule is commented out, it was in the default in the instructions from github (but also commented out).
Here is the error message from the nginx log.
2024/06/14 21:06:56 [error] 442#442: *1 connect() failed (111: Unknown error) while connecting to upstream, client: 34.140.130.61, server: , request: “GET / HTTP/1.1”, upstream: “http://127.0.0.1:3000/”, host: “34.224.215.205”
[/quote]
At one point in time, I removed the apn entry, but it led to other problems. I created a dummy file, but not a ‘real’ certificate.

Hmm. Didn’t observe any problem here but must admit that I don’t use apple push.
A link in https://community.openhab.org/t/ssl-issue-connecting-to-habian-server-through-self-hosted-cloud-instance/ refers to my setup.

I am seeing a problem that Authkey.p8 is not found. Removing apn from config.js does not help, but leads to ‘module not found’ errors.

What exact message do you get ? That sounds like some nodejs module is missing.

app.js is running ( ps aux | grep node), but a curl http://127.0.0.3000 shows a connection

What is the output of :

netstat -tulpn |grep node

Did you run curl on your AWS instance ? Just to be sure that the right localhost is being used.
Btw localhost … Your post shows

curl http://127.0.0.3000

which needs to be

curl http://127.0.0.1:3000

or

curl http://localhost:3000

Thanks.
The curl command shows:
root 1973 0.0 0.5 11900 5504 pts/0 S 16:57 0:00 sudo nohup node app.js
root 1974 0.0 0.2 11900 2300 pts/1 Ss+ 16:57 0:00 sudo nohup node app.js
root 1975 0.2 9.0 1143576 88392 pts/1 Sl 16:57 0:01 node app.js

The netstat command shows nothing.
curl gives:
curl: (7) Failed to connect to 127.0.0.1 port 3000 after 0 ms: Connection refused
I haven’t removed the apn entries yet, but will try it again and post any error messages.
Thanks a lot for your help.

Here is what I found when I removed the apn entries in config.json:{“code”:“MODULE_NOT_FOUND”,“requireStack”:[“/home/ubuntu/openhab-cloud/notificationsender/firebase.js”,“/home/ubuntu/openhab-cloud/routes/devices.js”,“/home/ubuntu/openhab-cloud/routes/index.js”,“/home/ubuntu/openhab-cloud/app.js”]}
All modules actually exist.

You can try a variant: sudo nestat -tulpn | grep 3000
If that also doesn’t show the node process running on port 3000 then it is not lisitening on port 3000 and thus you get the connection refused

Thanks. This also shows nothing, so I guess app.js is not listening on port 3000. Here is what netstat -tulpn gives:
roto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 637/sshd: /usr/sbin
tcp 0 0 127.0.0.1:6379 0.0.0.0:* LISTEN 361/redis-server 12
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 1884/nginx: master
tcp 0 0 127.0.0.53:53 0.0.0.0:* LISTEN 312/systemd-resolve
tcp6 0 0 :::22 :::* LISTEN 637/sshd: /usr/sbin
tcp6 0 0 ::1:6379 :::* LISTEN 361/redis-server 12
It shows redis, should it also show mongodb? I noticed that it has an entry for “hosts”, but not “host” in the config.json file.

mongodb service need to run as well. This service is not started by the cloud software/instance itself. The service need to be started by the OS.

This is due to the nature of the software/service ( mongodb ). Looking into the documentation the documentation in most cases talks about items in plural.

There should be a logging file for the mongodb service e.g. at /var/log/mongodb/mongod.log. If you can’t find it there check the mongod.conf configuration file. The log file should give an idea about the root cause why the service is not running. In case nothing is stated there check the system log/messages file or output of journalctl.

Thanks. It seems I had to start mongodb by hand.
However, even after doing that, I don’t see app.js listening on port 3000. I looked at the logs and here is what it shows when I remove the apn entries from config.json. 2024-06-24 15:07:50:5050 info: Backend service is starting up…
2024-06-24 15:07:50:5050 info: Backend logging initialized…
2024-06-24 15:07:50:5050 info: Connecting to Redis at 127.0.0.1:6379
2024-06-24 15:07:53:5353 info: Mailer will emulate sending in development environment
2024-06-24 15:07:53:5353 error: uncaughtException: Cannot find module ‘/home/ubuntu/openhab-cloud/serviceAccountKey.json’
Require stack:

  • /home/ubuntu/openhab-cloud/notificationsender/firebase.js
  • /home/ubuntu/openhab-cloud/routes/devices.js
  • /home/ubuntu/openhab-cloud/routes/index.js
  • /home/ubuntu/openhab-cloud/app.js
    Error: Cannot find module ‘/home/ubuntu/openhab-cloud/serviceAccountKey.json’
    Require stack:
  • /home/ubuntu/openhab-cloud/notificationsender/firebase.js
  • /home/ubuntu/openhab-cloud/routes/devices.js
  • /home/ubuntu/openhab-cloud/routes/index.js
  • /home/ubuntu/openhab-cloud/app.js
    at Module._resolveFilename (node:internal/modules/cjs/loader:1145:15)
    at Module._load (node:internal/modules/cjs/loader:986:27)
    at Module.require (node:internal/modules/cjs/loader:1233:19)
    at require (node:internal/modules/helpers:179:18)
    at Object. (/home/ubuntu/openhab-cloud/notificationsender/firebase.js:7:28)
    at Module._compile (node:internal/modules/cjs/loader:1358:14)
    What is the serviceAccountKey?

Have a look into your config.json file.

    "gcm" : {
      "senderId": "1234567890",
      "serviceFile" : "serviceAccountKey.json"
    },

1234567890 is just a placeholder. The file serviceAccontKey.json needs to be filled and exist in case that gcm is to be used.
Info about gcm: Google Cloud Messaging - Wikipedia
مجوز ارسال درخواست ها  |  Firebase Cloud Messaging
This may help in case it is still uptodate: java - what is "serviceAccountKey.json" referring to in the Firebase device-to-device notifications tutorial - Stack Overflow

Thanks for your all your help. Removing apn and acquiring a Service Account Key from Google seems to have done it. I am now seeing a log-in screen. I guess I now have to enable registration and can explore a bit more.