本帖最後由 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
複製代碼 |