LoxYourLife / loxberry-express

3 stars 0 forks source link

Express Server works after initial installation, but reboot breaks the installation #8

Open 2-click opened 2 months ago

2-click commented 2 months ago

Summary:

Plugin works after Installation. When device is rebooted, Plugin no longer works, gives this error message: Cannot load configuration. Try to restart the Server and reload the page.

Detailed issue:

After installing the Plugin, the express Server is running fine. We can confirm this by using the webinteface. With the PID we can also see the command that has been used to start the plugin:

root@loxberry:/opt/loxberry/bin/plugins/express# ps -p 3522 -f
UID          PID    PPID  C STIME TTY          TIME CMD
loxberry    3522    3109  2 11:36 ?        00:00:00 node /opt/loxberry/bin/plugins/express/index.js

After the reboot, the webinterface shows : Cannot load configuration. Try to restart the Server and reload the page. image

Running the Server manually still works though

su loxberry
node /opt/loxberry/bin/plugins/express/index.js
[2024-08-25 09:39:51] Express|INFO: LoxBerry Express Server listening at http://localhost:3300
[2024-08-25 09:39:53] Unifi Presence|INFO: ACCESS GET /api/socket.ws
[2024-08-25 09:39:53] Unifi Presence|DEBUG: new client connection, send null

When Checking index.js we notice These lines:

const configFile = path.resolve(directories.config, 'express.json');
const config = require(configFile);

We can reveal where that file is stored:

find /opt/loxberry -type f -name "express.json"
/opt/loxberry/config/plugins/express/express.json

Permissions of the file: -rw-r--r-- 1 loxberry loxberry 109 Aug 25 11:34 /opt/loxberry/config/plugins/express/express.json Contents are {"expressPort":"3300","managerPort":"3301","loglevel":{"info":true,"debug":true,"warning":true,"error":true}}

Log files

No log files could be found under /opt/loxberry/log/plugins/express

System information

Device model : RPi 5 Model B (aarch64)
Loxberry: v3.0.1.2
DietPi v9.6.1
2-click commented 2 months ago

Interesting. npm run start shows Express Manager as errored. image npm run logs shows these lines:

/opt/loxberry/bin/plugins/logs/express-error.log last 15 lines:
1|Express  | Require stack:
1|Express  | - /opt/loxberry/bin/plugins/express/index.js
1|Express  |     at Module._resolveFilename (node:internal/modules/cjs/loader:1248:15)
1|Express  |     at Hook._require.Module.require (/opt/loxberry/bin/plugins/express/node_modules/require-in-the-middle/index.js:61:29)
1|Express  |     at require (node:internal/modules/helpers:125:16)
1|Express  |     at Object.<anonymous> (/opt/loxberry/bin/plugins/express/index.js:13:16)
1|Express  |     at Module._compile (node:internal/modules/cjs/loader:1546:14)
1|Express  |     at Module._extensions..js (node:internal/modules/cjs/loader:1691:10)
1|Express  |     at Module.load (node:internal/modules/cjs/loader:1317:32)
1|Express  |     at Module._load (node:internal/modules/cjs/loader:1127:12)
1|Express  |     at Object.<anonymous> (/opt/loxberry/bin/plugins/express/node_modules/pm2/lib/ProcessContainerFork.js:33:23)
1|Express  |     at Module._compile (node:internal/modules/cjs/loader:1546:14) {
1|Express  |   code: 'MODULE_NOT_FOUND',
1|Express  |   requireStack: [ '/opt/loxberry/bin/plugins/express/index.js' ]
1|Express  | }
2-click commented 2 months ago

I put a debug line in there and found out the path it tries to load:

const configFile = path.resolve(directories.config, 'express.json');
console.log('Resolved config file path:', configFile);  // Debug line
const config = require(configFile);
loxberry@loxberry:~/bin/plugins/express $ cat /opt/loxberry/bin/plugins/config/express.json
cat: /opt/loxberry/bin/plugins/config/express.json: No such file or directory

Interesting! The path is wrong.

This is the correct path that exists: /opt/loxberry/config/plugins/express/express.json
This is the one it tries to load:     /opt/loxberry/bin/plugins/config/express.json

With a debug statement I found out that lib/directories.js uses the debug environment and not the production environment. This could be due to me starting it with npm run or an actual bug.

2-click commented 2 months ago

Since this is no longer maintained I started my own plugin: https://github.com/2-click/loxberry-plugin-wifi-presence-unifi