Ylianst / MeshCentral

A complete web-based remote monitoring and management web site. Once setup you can install agents and perform remote desktop session to devices on the local network or over the Internet.
https://meshcentral.com
Apache License 2.0
4.25k stars 568 forks source link

archiver Error after updating to 1.1.22 #5952

Closed ghost closed 7 months ago

ghost commented 7 months ago

Describe the bug Updated to 1.1.22 and the server did not come back up after updating. So I logged in to the server via ssh and stopped the service and ran node node_modules/meshcentral. With luck the server started back up, So I went to the server logs and it shows this error.

-------- 3/25/2024, 1:10:58 AM ---- 1.1.22 --------

/home/meh324/node_modules/archiver-utils/node_modules/minimatch/dist/cjs/ast.js:86
    #fillNegs() {
             ^

SyntaxError: Unexpected token '('
    at wrapSafe (internal/modules/cjs/loader.js:915:16)
    at Module._compile (internal/modules/cjs/loader.js:963:27)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1027:10)
    at Module.load (internal/modules/cjs/loader.js:863:32)
    at Function.Module._load (internal/modules/cjs/loader.js:708:14)
    at Module.require (internal/modules/cjs/loader.js:887:19)
    at require (internal/modules/cjs/helpers.js:74:18)
    at Object.<anonymous> (/home/meh324/node_modules/archiver-utils/node_modules/minimatch/dist/cjs/index.js:9:18)
    at Module._compile (internal/modules/cjs/loader.js:999:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1027:10)
    at Module.load (internal/modules/cjs/loader.js:863:32)
    at Function.Module._load (internal/modules/cjs/loader.js:708:14)
    at Module.require (internal/modules/cjs/loader.js:887:19)
    at require (internal/modules/cjs/helpers.js:74:18)
    at Object.<anonymous> (/home/meh324/node_modules/archiver-utils/node_modules/glob/dist/commonjs/index.js:4:21)
    at Module._compile (internal/modules/cjs/loader.js:999:30)

Also the server says it "Failed to load web certificate at: "https://server.com, host: "server.com". When I run the le command to check the ssl certificate it says its valid for 72 days. All agents came back online.

To Reproduce Steps to reproduce the behavior:

  1. update to 1.1.22

Server Software (please complete the following information):

Additional context Add any other context about the problem here.

Configuration File (removed sensitive information)

{
  "$schema": "https://raw.githubusercontent.com/Ylianst/MeshCentral/master/meshcentral-config-schema.json",
  "settings": {
    "cert": "server.com",
    "WANonly": true,
    "port": 443,
    "redirPort": 80
  },
  "domains": {
    "": {
      "certurl": "https://server.com",
      "title": "Server",
      "_newAccounts": false,
      "agentInviteCodes": true,
      "authStrategies": {
        "azure": {
          "newAccounts": true,
          "clientid": "myclientid",
          "clientsecret": "myclientsecret",
          "tenantid": "mytenantid"
        }
      },
      "agentCustomization":{
        "displyName": "server",
        "description": "mydesc",
        "companyName": "server",
        "serviceName": "Agent",
        "fileName": "Agent"
      }
    }
  },
  "letsencrypt": {
    "email": "user@server.com",
    "names": "server.com",
    "production": true
  }
}

Service file

[Unit]
Description=MeshCentral Server
[Service]
Type=simple
LimitNOFILE=1000000
ExecStart=/usr/bin/node /home/meh324/node_modules/meshcentral
WorkingDirectory=/home/meh324
Environment=NODE_ENV=production
User=meh324
Group=meh324
Restart=always
# Restart service after 10 seconds if node service crashes
RestartSec=10
# Set port permissions capability
AmbientCapabilities=cap_net_bind_service
[Install]
WantedBy=multi-user.target
ghost commented 7 months ago

Restored to 1.1.0 and the service worked fine. I updated to 1.1.22 from 1.1.0 and the service stops working. I'm going to use 1.1.0 until the issue is fixed. Happy to help if I can.

si458 commented 7 months ago

this seems to be related to the archiver module which @Ylianst updated the other day, not sure why its crashing, will have to look into it

quizhead commented 7 months ago

How can I restore back? I can't run the server with node meshcentral command. Getting Permission denided errror

[Error: EACCES: permission denied, open '/home/quizhead/meshcentral/meshcentral-data/meshcentral-power.db'] {
  errno: -13,
  code: 'EACCES',
  syscall: 'open',
  path: '/home/quizhead/meshcentral/meshcentral-data/meshcentral-power.db'
}

Node.js v20.11.1

    at ChildProcess.exithandler (node:child_process:422:12)
    at ChildProcess.emit (node:events:530:35)
    at maybeClose (node:internal/child_process:1105:16)
    at Socket.<anonymous> (node:internal/child_process:457:11)
    at Socket.emit (node:events:518:28)
    at Pipe.<anonymous> (node:net:337:12) {
  code: 1,
  killed: false,
  signal: null,
  cmd: '/usr/local/bin/node /home/quizhead/meshcentral/node_modules/meshcentral --launch 5789'
}
ERROR: MeshCentral failed with critical error, check mesherrors.txt. Restarting in 5 seconds...

The meshcentral.service is configured as needed

si458 commented 7 months ago

@quizhead the error is right there... [Error: EACCES: permission denied, open '/home/quizhead/meshcentral/meshcentral-data/meshcentral-power.db']

the file meshcentral-power.db ISNT the same as whats inside your meshcentral.service OR whatever user you are using to RUN node with, so make sure they all match

quizhead commented 7 months ago

@quizhead the error is right there... [Error: EACCES: permission denied, open '/home/quizhead/meshcentral/meshcentral-data/meshcentral-power.db']

the file meshcentral-power.db ISNT the same as whats inside your meshcentral.service OR whatever user you are using to RUN node with, so make sure they all match It's configured as needed. Should I delete the Node_Modules folder and reinstall?

si458 commented 7 months ago

@quizhead please open an issue in the 'discussions' this thread is about the archiver bug

si458 commented 7 months ago

@meh324 just looked into this, it appears minimatch which is a dependency for archiver now required node 16 or above, you say you are using node 21 which might be the case when running node node_modules/meshcentral can you check your startup scripts are using the correct node version?

ghost commented 7 months ago

You were correct, it says it's running 12.22.9.

How do I update that node that the services use?

ctrlaltca commented 7 months ago

I had the same error on Ubuntu 22.04 (using nodejs 12) and fixed it by installing nodejs version 20.

npm install -g n
n lts
node --version

I had to edit /etc/systemd/system/meshcentral.service changing /usr/bin/node to the new path /usr/local/bin/node for the new version of nodejs to be picked up.

systemctl stop meshcentral.service
nano /etc/systemd/system/meshcentral.service
systemctl daemon-reload
systemctl start meshcentral.service
systemctl status meshcentral.service
si458 commented 7 months ago

@ctrlaltca yes the min requirement for meshcentral was 12 but im guessing the archiver now means we need to upgrade it now to 16 at least, but really people should be using at least the LTS version (20)

ghost commented 7 months ago

That fixed it, thanks so much!

I had the same error on Ubuntu 22.04 (using nodejs 12) and fixed it by installing nodejs version 20.

npm install -g n
n lts
node --version

I had to edit /etc/systemd/system/meshcentral.service changing /usr/bin/node to the new path /usr/local/bin/node for the new version of nodejs to be picked up.

systemctl stop meshcentral.service
nano /etc/systemd/system/meshcentral.service
systemctl daemon-reload
systemctl start meshcentral.service
systemctl status meshcentral.service