수색…


소개

많은 웹 서버와 달리 Node는 기본적으로 서비스로 설치되지 않습니다. 그러나 제작 과정에서는 init 시스템에 의해 관리되는 dæmon으로 실행하는 것이 좋습니다.

systemd dæmon으로 Node.js

systemd는 대부분의 Linux 배포판에서 사실상 init 시스템입니다. Node가 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 를 자동으로 시작하도록 systemd에 알리려면 다음을 입력하십시오. systemctl enable node .

그게 다야, 지금 노드는 데몬으로 실행된다.



Modified text is an extract of the original Stack Overflow Documentation
아래 라이선스 CC BY-SA 3.0
와 제휴하지 않음 Stack Overflow