Timeout with exit(0) from bash

Trying to setup a Travis bash script where we run our application to make sure it starts up fine similar to CRON. If it does then we can pass the build. Testing catches errors on start up. However, it is an API (CloudFactory) server and if I run the binary and it is successful it will just run indefinitely like infinite loop.

I did:

timeout --preserve-status 20s <binary>

This just returns the code of the binary which is 143 when killed from a timeout.

timeout 20s <binary>

This returns exit 127 when successful.

Any script I could use that runs the binary fails if the binary errors on startup and if sucessful starting up say after 20-25 seconds exits with 0 to pass the Travis build? Thank you.

Hey @SolarUltima,

There’s no need to use sleep. You can change your command(s) in the following way to enforce the return code at 0:

(timeout 20s <binary>; exit 0) 

This is true with essentially any timeout, specifically if you’re going to be using it as a deploy.sh or something like that.

To get back to what I was discussing, I’ve written an example for you:

(timeout 2s '/bin/sleep' 100; exit 0) #subshell creation by Montana                                                                                        
echo $?

If you take that, and contrast that to the following:

timeout 2s '/bin/sleep' 100
echo $?

This will solve your issue. If it doesn’t please let me know.