node.js 永远:找不到命令
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/23445639/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Forever: command not found
提问by azero0
I am getting a
我得到一个
forever: command not founderror when I run a nodejs process using the forever command as a cronjob (in an amazon ec2 machine): the bash script I am using has the following code:
永远:当我使用forever命令作为cronjob(在亚马逊ec2机器中)运行nodejs进程时,命令未找到错误:我使用的bash脚本具有以下代码:
cd to/location/of/the/nodejs/file
cd 到/location/of/the/nodejs/file
forever start file.js
永远开始 file.js
but I am able to run this file by using bash script.sh but I get the forever:command not found error when I run it via cronjob
但是我可以使用 bash script.sh 运行这个文件,但是当我通过 cronjob 运行它时,我得到了永远:找不到命令的错误
I am confused dont know what could be the reason for this.
我很困惑不知道这可能是什么原因。
Has anybody else faced this problem?
有没有其他人遇到过这个问题?
Thanks in advance
提前致谢
回答by sunitj
Run this command: npm install forever -g
运行此命令: npm install forever -g
-gis to install it globally.
-g是全局安装。
回答by azero0
For other users who face this problem:
对于遇到此问题的其他用户:
you have to add the path of forever module and then run the script as a cronjob.
您必须添加forever 模块的路径,然后将脚本作为cronjob 运行。
In linux the path normally is:
在linux中,路径通常是:
/usr/local/lib/node_modules/forever/bin/forever start file.js
/usr/local/lib/node_modules/forever/bin/forever start file.js
just use this command in your script and the error forever:command not foundwill not bother you.
只需在您的脚本中使用此命令,错误永远:找不到命令不会打扰您。
I know there must be some other fancy ways to do this but I am happy with this hack
我知道一定有其他一些奇特的方法可以做到这一点,但我对这个 hack 很满意
回答by babycakes
in case azero0's solution doesn't work for you and you're running linux, try
如果 azero0 的解决方案对您不起作用并且您正在运行 linux,请尝试
sudo npm install forever -g
回答by meesern
If you have already tried:
如果您已经尝试过:
sudo npm install forever -g
and still get forever:command not foundpay attention to the first line in the output. This should be something like:
并且仍然forever:command not found注意输出中的第一行。这应该是这样的:
/<node_bin_path>/forever -> /lib/node_modules/forever/bin/forever
where node_bin_pathis the place in which the executable is located. This is most likely not where you expect.
wherenode_bin_path是可执行文件所在的位置。这很可能不是您所期望的。
This may be because nodein your path is a symbolic link. In this case foreverwill be installed in the actual install location of nodenot the location of the symbolic link.
这可能是因为node在您的路径中是一个符号链接。在这种情况下forever将安装在实际安装位置而node不是符号链接的位置。
回答by KARTHIKEYAN.A
it seems forever not found in globally, use the below command to solve
好像永远找不到全局,用下面的命令解决
npm i forever -g
回答by Yasin Bikmazer
Below bash script Code Check your script running. If not running Stop and Start and notification mail.
在 bash 脚本代码下方检查您的脚本正在运行。如果没有运行停止和启动和通知邮件。
Crontab
定时任务表
*/1 * * * * sh /root/yourscriptdirectory/checklive.sh >> /root/yourscriptdirectory/cron.log 2>&1
checklive.sh
checklive.sh
chmod +x ./checklive.sh
chmod +x ./checklive.sh
cd /root/yourscriptdirectory/
ps xa | grep -F "/usr/local/bin/node /root/yourscriptdirectory/script.js" | grep -Fv "grep" > /dev/null
if [ $? -eq 0 ]; then
echo ""
else
echo "script.js not running. Restart"
/usr/local/bin/node /usr/local/lib/node_modules/forever/bin/forever stop script.js
/usr/local/bin/node /usr/local/lib/node_modules/forever/bin/forever start script.js
echo "STOP : script.js Process is stoped restarting..." | mail -s "STOP : script.js Process is stoped restarting..." "<[email protected]>" &
fi
回答by alicanozkara
sudo npm install forever --global
this worked for me on ubuntu 16.04 server and nodejs v7.5.0
这在 ubuntu 16.04 服务器和 nodejs v7.5.0 上对我有用

