我正在尝试为一个简单的 React 应用程序设置一个 systemd 服务。此应用程序托管在 /home/myuser/test 中。npm 和 node 都在 PATH 中并且硬链接到 /usr/bin。所有文件都具有 myuser:myuser 用户和组的权限。如果我手动启动它,npm start
它会正确启动并从http://localhost:3000
Compiled successfully!
You can now view test in the browser.
Local: http://localhost:3000
On Your Network: http://myipaddress:3000
Note that the development build is not optimized.
To create a production build, use npm run build.
Run Code Online (Sandbox Code Playgroud)
如果我尝试通过 systemd 启动应用程序,它会失败但没有说明原因。我从相同的路径、相同的用户启动它,并尝试了 ExecStart 可以想象的所有组合:
ExecStart=npm start
ExecStart=/usr/bin/npm start
ExecStart=/usr/bin/node /home/myuser/test/node_modules/react-scripts/scripts/start.js
Run Code Online (Sandbox Code Playgroud)
它们都产生相同的结果,即它“开始”正常,但很快就失败了,在 journalctl 中显然没有理由:
$sudo systemctl status node-client
? node-client.service - Node-React Frontend Server
Loaded: loaded (/etc/systemd/system/node-client.service; disabled; …
Run Code Online (Sandbox Code Playgroud)