Home > Software engineering >  Running bash file on Heroku
Running bash file on Heroku

Time:01-06

I'm trying to start my Discord bot using a bash file on Heroku, so the bot wil automaticly restart when it gets an error.

My worker on Heroku is: chmod a x run.sh

The run.sh file:

#!/bin/sh
function main(){
node .
echo "The bot is crashed, restarting now..."
main
}
main

Edit: I changed the worker to bash run.sh and limited the run.sh file to:

#!/bin/bash
node index.js
echo "The bot is online."

Now I'm getting this response: Error: Cannot find module '/app/index.js

CodePudding user response:

Try changing your header to /bin/bash. function is not POSIX. You can also just omit function if you won't be using other bash features.

Also I notice that you're calling main from main and that would cause repeated calls. Even if that's intended it would still be better to use a loop. Bash is not tail call optimzation aware.

CodePudding user response:

You don't need to (and shouldn't) write your own startup script with Heroku. That's what the Procfile is for. Something like this should do it:

worker: node index.js

That defines a worker process type that will run node index.js. Then, as long as you have a worker dyno running, your script should run.

  •  Tags:  
  • Related