本帖最后由 gamezz 于 2022-5-19 10:45 编辑
我跟住这教学在oracle cloud centos 8 使用 Systemd 建立 Node.js rest server service:
https://blog.gtwang.org/linux/no ... d-service-tutorial/
可是 status 显示 test.service: Start request repeated too quickly.
test.service: Failed with result 'exit-code'.
test.js- const http = require('http');
- const hostname = '0.0.0.0';
- const port = process.env.NODE_PORT || 3000;
- const server = http.createServer((req, res) => {
- res.writeHead(200, { 'Content-Type': 'text/plain' });
- res.write("Hello, world.");
- res.end();
- });
- server.listen(port, hostname, () => {
- console.log("Server running at http://" + hostname + ":" + port + "/");
- });
复制代码 test.service- [Unit]
- After=network.target
- # 服务名称
- Description=My Node.js App
- [Service]
- Type=simple
- # 设定环境变数
- Environment=NODE_PORT=3000 NODE_ENV=production
- # 执行服务的使用者
- User=root
- # 启动服务指令
- ExecStart=/usr/bin/node /var/www/node4/test.js
- # 不正常停止时重新启动
- Restart=on-failure
- [Install]
- WantedBy=multi-user.target
复制代码 |