2
數據我有兩個小systemd插座和服務文件:沒有從插座激活與systemd
插座:
[Socket]
ListenStream=80
# also tried with Accept=no
[Install]
WantedBy=sockets.target
服務:
[Unit]
Description=Test Webserver
[Service]
EnvironmentFile=/path/to/node-script.env
ExecStart=/path/to/node /path/to/server.js
Restart=always
StandardOutput=syslog
StandardError=syslog
SyslogIdentifier=node-script
Type=simple
User=test-user
Group=test-user
[Install]
WantedBy=sockets.target
ENV:
PORT=80
我有一個小小的Node.js腳本:
var http = require('http');
var server = http.createServer();
server.on('connection', function(conn) {
// socket connection
console.log('new connection', conn.address());
conn.on('data', function(data) {
console.log('more data', data.length);
});
}).on('request', function(req, res) {
// a request!
console.log('new request', req.headers);
}).listen({fd: 3}, function() {
console.log('listening on provided descriptor', server.address());
});
如果我啓動它:
$ systemctl start node-script.socket
$ curl localhost
捲曲只是坐在那裏。同樣的事情,如果我嘗試直接netcat數據到套接字。檢查日誌,我注意到服務器獲得了連接,但從未獲得任何數據或請求。
listening on provided descriptor { address: '::', family: 'IPv6', port: 80 }
new connection { address: '::1', family: 'IPv6', port: 80 }
數據在哪裏?
如果您從命令行啓動應用程序,「/ path/to/node/path/to/server.js」是否按預期工作? – Jonathan
當然可以。自那時起我就解決了我的問題,但我不記得如何。 – skeggse