nodejs-tw / ama

Ask me anything!
MIT License
31 stars 1 forks source link

請問如何在開機的時候就啟動多個node.js腳本 on linux #8

Open e314520513 opened 8 years ago

e314520513 commented 8 years ago

遇到的問題

請問如何在開機的時候就啟動多個node.js腳本 on linux

我把指令寫在/etc/rc.local 但只會啟動 node /var/www/nodeJs/todoList/bin/www 下面的都不會啟動

/etc/rc.local

#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.
node /var/www/nodeJs/todoList/bin/www
node /var/www/nodeJs/chatroom/app.js
exit 0
poying commented 8 years ago

@e314520513 提供幾種方法給你參考:

  1. 使用 nohup,我覺得最簡單的方式。nohup node /var/www/nodeJs/todoList/bin/www &
  2. pm2,不需要修改 js 程式碼
  3. deamon.node,需要修改 js 程式碼