Skip to content

Instantly share code, notes, and snippets.

@rlb3
Forked from bitwalker/run.sh
Created June 24, 2022 17:25
Show Gist options
  • Save rlb3/a666efc531eaea1c779fdb1b43aecdb1 to your computer and use it in GitHub Desktop.
Save rlb3/a666efc531eaea1c779fdb1b43aecdb1 to your computer and use it in GitHub Desktop.
Handling of UNIX-signals in Erlang/Elixir is not supported, this script provides start-stop management with handling TERM signal for Docker installation.
#!/usr/bin/env bash
set -x
term_handler() {
echo "Stopping the server process with PID $PID"
erl -noshell -name "term@127.0.0.1" -eval "rpc:call('app@127.0.0.1', init, stop, [])" -s init stop
echo "Stopped"
}
trap 'term_handler' TERM INT
elixir --name app@127.0.0.1 -S mix run --no-halt &
PID=$!
echo "Started the server process with PID $PID"
wait $PID
# remove the trap if the first signal received or 'mix run' stopped for some reason
trap - TERM INT
# return the exit status of the 'mix run'
wait $PID
EXIT_STATUS=$?
exit $EXIT_STATUS
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment