2018年9月20日 星期四

讓 nodejs 跑 service

編輯 /etc/systemd/system/nodejs.service
[Unit]
Description=nodejs server

[Service]
ExecStart=/usr/bin/node /var/nodejs/index.js
Restart=always
User=nobody
Group=nobody
Environment=PATH=/usr/bin:/usr/local/bin
Environment=NODE_ENV=production
WorkingDirectory=/var/nodejs

[Install]
WantedBy=multi-user.target

編輯測試程式 /var/nodejs/index.js 內容
var http = require('http');

var hostname = '10.10.10.10';
var port = 3849;

http.createServer(function(req, res) {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end('Hello World');
}).listen(port, hostname, function () {
console.log('Server running at http://%s:%s/', hostname, port);
});

重新載入所有service
systemctl daemon-reload

啟動 nodejs service
systemctl start nodejs

用lynx連結 http://10.10.10.10:3849,網頁顯示 Hello World 表示成功

設定自動啟動 nodejs
systemctl enable nodejs

沒有留言:

Ubuntu 的 amavis & clamav 問題

紀錄一下~ 最近把老舊的Centos換成 Ubuntu ,重裝後 發現 log 總有 clamav 沒有權限 2025-04-01T08:07:37.567746+08:00 mail amavis[24976]: (24976-01) (!)run_av (ClamAV-cla...