简体   繁体   English

第一行的ForeverJS bash脚本错误

[英]ForeverJS bash script errors on first line

Im trying to get a foreverJS script to run a Node server on an EC2 instance. 我试图获取一个foreverJS脚本来在EC2实例上运行Node服务器。 The script looks like: 该脚本如下所示:

#!/bin/bash
forever stopall
forever hakuna-matata store in appropriate logs start 'full/qualified path'

Even if I add an echo "getting here" statement as the first line I still get an error. 即使我将echo "getting here"语句添加为第一行,也仍然会出现错误。 I do not know bash scripting well, so it may be permissions, relative/absolute path, EC2/node, environment variable related, but I honestly do not know. 我不太了解bash脚本,因此可能与权限,相对/绝对路径,EC2 /节点,环境变量有关,但老实说我不知道​​。

Stacktrace: 堆栈跟踪:

[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

I also tried via running the script via the forever service script with forever start startup.sh and get the same error. 我还尝试通过forever start startup.sh的永远服务脚本运行脚本,并得到相同的错误。 I've launched from the parent direct and with a (qualified) path. 我是从父级直接启动的,并具有(限定的)路径。

whoami - user which forever - /usr/local/bin/forever which npm - /usr/local/bin/npm sudo whomai - root sudo which npm - /usr/bin/npm sudo which forever - /usr/bin/forever node -v -v8.2.1 npm -v - 5.3.0 whoami-永远的用户-/ usr / local / bin /永远的npm-/ usr / local / bin / npm sudo whomai-根sudo的npm-/ usr / bin / npm sudo的永远-/ usr / bin / forever节点-v -v8.2.1 npm -v-5.3.0

Ask if you need additional environmental information... 询问您是否需要其他环境信息...

Forever assumes SCRIPT is a JS file that can be executed with Node.js You're trying to run a bash script instead, so it errors out since echo "getting here" obviously isn't valid JS code. 永远假定SCRIPT是可以与Node.js一起执行的JS文件。您正尝试运行bash脚本,因此它会出错,因为echo "getting here"显然不是有效的JS代码。

To fix this, you need to use the -c command line option when running forever . 要解决此问题,请在forever运行时使用-c命令行选项。 From the docs : 文档

-c  COMMAND      COMMAND to execute (defaults to node)

So in your case, you'd set -c to /bin/bash ; 因此,在您的情况下,请将-c设置为/bin/bash like this: 像这样:

forever start [LOG OPTIONS] -c /bin/bash path/to/your-shell-script.sh

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM