2017-07-25 40 views
0

我试图让一个foreverJS脚本在EC2实例上运行节点服务器。该脚本看起来像:ForeverJS第一行bash脚本错误

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

即使我添加一个echo "getting here"语句作为第一行我还得到一个错误。我不知道bash脚本很好,所以它可能是权限,相对/绝对路径,EC2 /节点,环境变量有关,但我真的不知道。

堆栈跟踪:

[[email protected] 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中/永远 其中NPM - 的/ usr/local/bin中/ NPM 须藤whomai - 根 须藤其中NPM - 的/ usr /斌/ NPM 须藤其永远的 - 在/ usr/bin中/永远 节点-v -v8.2.1 NPM -v - 5.3.0

询问是否需要额外的环境信息...

+0

难道你不会像'bash。/ startup.sh'那样运行吗? – stdunbar

+0

@stdunbar我在使用永久语法之前运行它 - 选项 $ forever --help usage:forever [action] [options] SCRIPT [script-options] https://github.com/foreverjs/forever –

回答

1

永远假设SCRIPT是一个JS文件可以使用Node.js执行您正在尝试运行bash脚本,因此它自0123以来出错显然是无效的JS代码。

要解决此问题,需要在运行forever时使用-c命令行选项。从the docs

-c COMMAND  COMMAND to execute (defaults to node) 

所以你的情况,你会设置-c/bin/bash;像这样:

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