खोज…


परिचय

कई वेब सर्वरों के विपरीत, नोड बॉक्स से बाहर सेवा के रूप में स्थापित नहीं है। लेकिन उत्पादन में, यह बेहतर है कि इसे एक डॉमन के रूप में चलाया जाए, जिसे एक इनिट सिस्टम द्वारा प्रबंधित किया जाता है।

Node.js एक systemd d.mon के रूप में

systemd अधिकांश लिनक्स वितरणों में वास्तविक तथ्य प्रणाली है। नोड को सिस्टमड के साथ चलाने के लिए कॉन्फ़िगर किया गया है, इसे प्रबंधित करने के लिए service कमांड का उपयोग करना संभव है।

सबसे पहले, इसे एक कॉन्फ़िगर फ़ाइल की आवश्यकता है, चलो इसे बनाते हैं। डेबियन आधारित डिस्ट्रोस के लिए, यह /etc/systemd/system/node.service में होगा

[Unit]
Description=My super nodejs app

[Service]
# set the working directory to have consistent relative paths
WorkingDirectory=/var/www/app

# start the server file (file is relative to WorkingDirectory here)
ExecStart=/usr/bin/node serverCluster.js

# if process crashes, always try to restart
Restart=always

# let 500ms between the crash and the restart
RestartSec=500ms

# send log tot syslog here (it doesn't compete with other log config in the app itself)
StandardOutput=syslog
StandardError=syslog

# nodejs process name in syslog
SyslogIdentifier=nodejs

# user and group starting the app
User=www-data
Group=www-data

# set the environement (dev, prod…)
Environment=NODE_ENV=production


[Install]
# start node at multi user system level (= sysVinit runlevel 3) 
WantedBy=multi-user.target

अब एप्लिकेशन को क्रमशः शुरू करना, रोकना और पुनः आरंभ करना संभव है:

service node start
service node stop
service node restart

सिस्टमड को बूट पर नोड को स्वचालित रूप से शुरू करने के लिए कहने के लिए, बस टाइप करें: systemctl enable node

यह सब, नोड अब एक dæmon के रूप में चलता है।



Modified text is an extract of the original Stack Overflow Documentation
के तहत लाइसेंस प्राप्त है CC BY-SA 3.0
से संबद्ध नहीं है Stack Overflow