簡體   English   中英

Crontab啟動節點應用程序永遠處於生產模式

[英]Crontab start node application with forever in production mode

我有一個node.js應用程序,我開始永遠使用,如下所示:

NODE_ENV=production forever start index.js

我還研究了如何設置crontab以在服務器重啟時自動啟動此應用程序的forever命令:

@reboot /usr/local/bin/forever start /path/to/my/app/index.js

這里唯一的問題是節點環境。 如何將生產環境添加到crontab命令?

如果你需要在crontab中執行帶變量等的特殊命令,那么編寫一個簡單的shell腳本並從crontab調用該腳本會更容易:

#!/bin/bash
export NODE_ENV=production
/usr/local/bin/forever start /path/to/my/app/index.js

使其可執行: chmod 755 /usr/local/bin/start_my_app.sh

然后在你的crontab中:

@reboot /usr/local/bin/start_my_app.sh

如果只想設置一個環境變量,可以在forever命令之前使用export命令。

@reboot export NODE_ENV=production; /usr/local/bin/forever start /path/to/my/app/index.js

對於多個變量,Sukima的方法更好。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM