Node.js ForeverJS bash脚本在第一行出现错误
我正在尝试获取foreverJS脚本,以便在EC2实例上运行节点服务器。脚本如下所示:Node.js ForeverJS bash脚本在第一行出现错误,node.js,bash,amazon-ec2,npm,forever,Node.js,Bash,Amazon Ec2,Npm,Forever,我正在尝试获取foreverJS脚本,以便在EC2实例上运行节点服务器。脚本如下所示: #!/bin/bash forever stopall forever hakuna-matata store in appropriate logs start 'full/qualified path' 即使我添加了一个echo“getting here”语句作为第一行,我仍然会得到一个错误。我不太了解bash脚本,所以可能是权限、相对/绝对路径、EC2/节点、环境变量相关,但我真的不知道 堆栈跟踪:
#!/bin/bash
forever stopall
forever hakuna-matata store in appropriate logs start 'full/qualified path'
即使我添加了一个echo“getting here”
语句作为第一行,我仍然会得到一个错误。我不太了解bash脚本,所以可能是权限、相对/绝对路径、EC2/节点、环境变量相关,但我真的不知道
堆栈跟踪:
[ec2-user@12-34-56 folder]$ forever startup.sh
warn: --minUptime not set. Defaulting to: 1000ms
warn: --spinSleepTime not set. Your script will exit if it does not stay up for at least 1000ms
/home/user/var/www/folder/startup.sh:2
echo "gh"
^^^^
SyntaxError: Unexpected string
at createScript (vm.js:74:10)
at Object.runInThisContext (vm.js:116:10)
at Module._compile (module.js:533:28)
at Object.Module._extensions..js (module.js:580:10)
at Module.load (module.js:503:32)
at tryModuleLoad (module.js:466:12)
at Function.Module._load (module.js:458:3)
at Function.Module.runMain (module.js:605:10)
at startup (bootstrap_node.js:158:16)
at bootstrap_node.js:575:3
error: Forever detected script exited with code: 1
我还尝试使用forever start startup.sh
通过永久服务脚本运行该脚本,但得到了相同的错误。我已从父级直接启动,并具有(合格)路径
whoami-用户
哪个永远-/usr/local/bin/forever
哪个npm-/usr/local/bin/npm
须藤
sudo哪个npm-/usr/bin/npm
sudo which forever-/usr/bin/forever
节点-v-v8.2.1
npm-v-5.3.0
询问您是否需要其他环境信息…永远假设
脚本是一个可以使用Node.JS执行的JS文件。您尝试运行bash脚本,因此它会出错,因为echo“getting here”
显然不是有效的JS代码
要解决此问题,您需要在永远运行时使用-c
命令行选项。发件人:
因此,在您的例子中,您将-c
设置为/bin/bash
;像这样:
forever start [LOG OPTIONS] -c /bin/bash path/to/your-shell-script.sh
Forever假设SCRIPT
是一个JS文件,可以使用Node.JS执行。如果您尝试运行bash脚本,则会出错,因为echo“getting here”
显然不是有效的JS代码
要解决此问题,您需要在永远运行时使用-c
命令行选项。发件人:
因此,在您的例子中,您将-c
设置为/bin/bash
;像这样:
forever start [LOG OPTIONS] -c /bin/bash path/to/your-shell-script.sh
你不会像运行bash./startup.sh那样运行它吗?@stdunbar在使用forever语法之前我已经运行过了-Options$forever--help用法:forever[action][Options]SCRIPT[SCRIPT Options]你不会像运行bash./startup.sh那样运行它吗?@stdunbar在使用forever语法之前我已经运行过了-Options$forever--help用法:forever[action][Options]SCRIPT[SCRIPT Options]