./bin/myapp stop fails when application isn't running

I have an umbrella application I’m deploying through Bitbucket pipelines and AWS CodeDeploy. I’m using Distillery to build the release. During my pre_start hook, I run migrations and add fixtures to the database. If anything fails at this stage, the deployment will fail, typically with the error:

[stdout]{"init terminating in do_boot",{#...
init terminating in do_boot ...
Crash dump is being written to: erl_crash.dump...done

This itself is fine. However, when I go to deploy the fix, AWS CodeDeploy goes through a lifecycle event, ApplicationStop. This just runs $ ./bin/<myapp> stop, but it always fails, presumably because the application never started during the prior deployment due to a pre-start failure.

My question is, is my understanding here correct? If so, is there a way to check if the application is running before stopping it?

Try sub command status that’s the most idioms tic way for services.

You mean like: ./bin/<myapp> status?

Or something like this:

    result=`./bin/$APP_NAME ping`

	if [ "$result" = "pong" ];
	then
	 ./bin/$APP_NAME stop
	fi

Hard to tell, since we do not know how you built it. Between the deployment builders there are slight differences sometimes·

I think I might be getting off track. It sounds like you’re saying that I should be checking to see if the application is running before issuing the stop command. Am I understanding you correctly?

You asked for a way to check if it is running, I said the subcommand status should do, becuase its common for services to do have this subcommand.

And yes, in your certain situation I’d check if it is running before stoping it. Another way might be to change the executable to emit exit-code 0 even if not previously running. Depending on the buildsystem you used, there might be options available…

1 Like