[英]Upstart node.js app on dokku deployment (Digital Ocean)
編輯文件/etc/init/node.conf
並將以下代碼放入其中。將/opt/node_project/
更改為項目的路徑。 編輯此文件時,您需要是root用戶,因此請使用sudo
打開編輯器。
description "Node server"
author "eagor"
# Stanzas
#
# Stanzas control when and how a process is started and stopped
# See a list of stanzas here: http://upstart.ubuntu.com/wiki/Stanzas#respawn
# When to start the service
start on runlevel [2345]
# When to stop the service
stop on runlevel [016]
# Automatically restart process if crashed
respawn
script
echo $$ > /var/run/node.pid;
exec node /opt/node_project/app.js
end script
post-stop script
rm -f /var/run/node.pid
end script
現在,您已經為流程創建了Upstart配置,您可以從命令行啟動它:
$ sudo service node start
Upstart將監視您的進程,並在發生故障時將其重新啟動。
它還會將日志重定向到/var/log/upstart/node.log
。
上面的方法直接與node一起使用,並且會繞過Dokku。 看起來Upstart並不是解決此問題的最佳方法。
您應該考慮使用forever
模塊。 forever
添加到您的package.json依賴項。 然后在您的Procfile中使用以下代碼: web: ./node_modules/forever/bin/forever app.js
從Dokku 0.7.0開始,它內置了重新啟動策略:
https://github.com/dokku/dokku/blob/master/docs/deployment/process-management.md#restart-policies
例如
# only restart it on Docker restart if it was not manually stopped
dokku ps:set-restart-policy node-js-app unless-stopped
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.