NodeJs 和 systemd 出现 raspbian 错误,MODULE_NOT_FOUND / Module._resolveFilename

NodeJs 和 systemd 出现 raspbian 错误,MODULE_NOT_FOUND / Module._resolveFilename

嘿嘿!我有一个节点脚本,可以从系统上的任何位置运行

/usr/bin/node /home/admin/git-repos/MMMMobileAlerts/maserver/mobilealerts.js

之后我还添加了 x 位

 sudo chmod +x /home/admin/git-repos/MMMMobileAlerts/maserver/mobilealerts.js

现在我想要的只是将其作为服务运行。因此我创建了一个maserver.service文件/etc/systemd/system

[Service]
ExecStart= /usr/bin/node /home/admin/git-repos/MMMMobileAlerts/maserver/mobilealerts.js

我也尝试过#!

输入命令后,sudo systemctl daemon-reload我查看了 sudo systemctl status maserver


● maserver.service
     Loaded: loaded (/etc/systemd/system/maserver.service; static)
     Active: failed (Result: exit-code) since Mon 2023-08-21 10:00:16 CEST; 5h 9min ago
   Main PID: 2404124 (code=exited, status=1/FAILURE)
        CPU: 234ms

Aug 21 10:00:16 dockerpi node[2404124]:     at Module._resolveFilename (node:internal/modules/cjs/loader:1077:15)
Aug 21 10:00:16 dockerpi node[2404124]:     at Module._load (node:internal/modules/cjs/loader:922:27)
Aug 21 10:00:16 dockerpi node[2404124]:     at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)
Aug 21 10:00:16 dockerpi node[2404124]:     at node:internal/main/run_main_module:23:47 {
Aug 21 10:00:16 dockerpi node[2404124]:   code: 'MODULE_NOT_FOUND',
Aug 21 10:00:16 dockerpi node[2404124]:   requireStack: []
Aug 21 10:00:16 dockerpi node[2404124]: }
Aug 21 10:00:16 dockerpi node[2404124]: Node.js v18.17.1
Aug 21 10:00:16 dockerpi systemd[1]: maserver.service: Main process exited, code=exited, status=1/FAILURE
Aug 21 10:00:16 dockerpi systemd[1]: maserver.service: Failed with result 'exit-code'.

我想在 raspbian 上使用 systemd 将 NodeJs 脚本作为服务运行。

答案1

我修复了将服务文件的用户和组指令设置为在 Node 调用的 js 上设置的相同问题:

[Service]
User=ubuntu
Group=ubuntu

相关内容