2

I recently got a host where java apps are launched this way:

/bin/bash ./restarter.sh java <lot of java params>

It ensures that if the app dies, then restarter.sh runs it again.

There is content of restarter.sh:

#!/bin/bash
until "$@"; do
  echo "Server crashed with exit code $?.  Respawning.." >&2
  sleep 1
done

Please help me to understand how it works.

1 Answer 1

2

It means to loop until the command("$@") completes execution with a exit code of 0.

Example:

$ until (echo Myprog ; sleep 1; exit 1;); do echo Error respawning ...; done
Myprog
Error respawning ...
Myprog
Error respawning ...
Myprog
^C

$ until (echo Myprog ; sleep 1; exit 0;); do echo Error respawning ...; done
Myprog

Analyzing your script: Normally, a well written application would exit with exit code of zero on successful completion and non-zero exit code otherwise. In your case, you are using the until command to keep restarting the application:

java <lot of java params> 

until the application completes its execution successfully(exit code of zero).

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .