Systemd
使用 systemd 服務執行後無法訪問伺服器
我正在嘗試在我的 VPS 上連續執行 nodeJs 伺服器,我創建了一個
systemd
服務並啟動了它。我的伺服器仍然無法訪問,我可以檢查狀態並且它可以正常工作:
服務狀態:
Node.service - Runs the Node Server for Node API Loaded: loaded (/etc/systemd/system/Node.service; disabled; vendor preset: enabled) Active: active (running) since Sat 2018-05-12 16:16:38 CEST; 2min 37s ago Main PID: 26697 (node) Tasks: 10 Memory: 87.5M CPU: 2.734s CGroup: /system.slice/Node.service └─26697 /root/.nvm/versions/node/v9.11.1/bin/node www May 12 16:16:38 vps543107 systemd[1]: Started Runs the Node Server for Node API. May 12 16:16:41 vps543107 node[26697]: Listening on port 3000
服務 :
[Unit] Description=Runs the Node Server for Node API Documentation="No Docs" After=network.target [Service] Type=simple User=root WorkingDirectory=/root/Node/bin ExecStart=/root/.nvm/versions/node/v9.11.1/bin/node www Restart=on-failure [Install] WantedBy=multi-user.target
我無法通過任何 HTTP 請求訪問伺服器,所有請求都超時。
我的服務有問題嗎?
嘗試關注
[Unit] Description="Runs the Node Server for Node API" #Requires=After=mysql.service # If you have any dependency then add it [Service] ExecStart=/root/.nvm/versions/node/v9.11.1/bin/node /root/Node/bin/www Restart=always # Restart service after 10 seconds if node service crashes RestartSec=10 # Output to syslog StandardOutput=syslog StandardError=syslog #Change this to find app logs in /var/log/syslog SyslogIdentifier=nodejs-api # Followig will require if you are using the PORT or Node from Envirnoment Environment=NODE_ENV=production PORT=3000 [Install] WantedBy=multi-user.target
一旦您的伺服器機器啟動並且您無法訪問伺服器,您可以通過以下命令檢查來自 /var/log/syslog 的日誌來進行故障排除
sudo cat /var/log/syslog | grep -r "nodejs-api"
開機啟動: sudo systemctl enable rocketchat