Previously, `nodeRestart()` would spawn a detached child and exit. Under
PM2 that's a problem: PM2 also respawns on exit, so both race to bind
the same port.
The fix: When `process.env.pm_id` is set, just exit and let PM2 handle
the restart.
The spawn logic is moved into its own method so it can be tested
cleanly.
Partially fixes#4165
The restart approach I introduced in #4156 still crashes under Electron:
```
TypeError: Cannot read properties of undefined (reading 'disableHardwareAcceleration')
at electron.js:18
```
`nodeRestart()` hardcodes `node` as the interpreter, but under Electron
`process.argv[0]` is the Electron binary. Spawning `node js/electron.js`
causes `require("electron")` to return a string instead of the API, so
`electron.app` is `undefined`.
This uses `process.argv[0]` as the binary directly, which works for both
Electron and plain Node.
I introduced more variables for more clarity.
Fixes#4154.
Use current process arguments when spawning the restart command so
auto-restart keeps the active runtime mode (for example `start:x11`)
instead of always defaulting to `start`.
This should fix#4154.
We can rely on PM2's native restart-on-exit behavior instead of the
programmatic pm2 API.
Fixes
https://github.com/MagicMirrorOrg/MagicMirror/security/dependabot/82 by
removing pm2.
Note: Originally this PR was intended to update pm2, but after
discussion, we decided to replace it instead. See the discussion below.
In PR #4072 GitHub Bot complained about an unused var. Instead of just
removing that one, I checked why ESLint hadn't complained about it: We
had disabled the rule for it.
So I enabled rule and resolved the issues that ESLint then detected.
Related to #4073
Since the project's inception, I've missed a clear separation between
default and third-party modules.
This increases complexity within the project (exclude `modules`, but not
`modules/default`), but the mixed use is particularly problematic in
Docker setups.
Therefore, with this pull request, I'm moving the default modules to a
different directory.
~~I've chosen `default/modules`, but I'm not bothered about it;
`defaultmodules` or something similar would work just as well.~~
Changed to `defaultmodules`.
Let me know if there's a majority in favor of this change.