Reputation: 19688
Im trying to get a foreverJS script to run a Node server on an EC2 instance. 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. 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.
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. 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
Ask if you need additional environmental information...
Upvotes: 1
Views: 2603
Reputation: 6994
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.
To fix this, you need to use the -c
command line option when running forever
. From the docs:
-c COMMAND COMMAND to execute (defaults to node)
So in your case, you'd set -c
to /bin/bash
; like this:
forever start [LOG OPTIONS] -c /bin/bash path/to/your-shell-script.sh
Upvotes: 3