Skip to content

Instantly share code, notes, and snippets.

@camshaft
Last active April 9, 2017 16:01
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save camshaft/f0359b6aaaade2a11d73 to your computer and use it in GitHub Desktop.
Save camshaft/f0359b6aaaade2a11d73 to your computer and use it in GitHub Desktop.
elixir startup script with graceful shutdown
#!/bin/bash
HOSTNAME="localhost"
PORT=${PORT-4000}
NODE="app_$PORT"
if [ -z "$COOKIE" ]
then
COOKIE=$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 32 | head -n 1)
fi
# Default to 64 threads
if [ -z "$THREAD_COUNT" ]
then
THREAD_COUNT="64"
fi
stop(){
echo Shutting down server
erl \
-sname "shutdown" \
-setcookie $COOKIE \
-noinput \
-eval "rpc:call('$NODE', init, stop, []), init:stop()."
}
trap stop SIGQUIT SIGINT SIGTERM
exec elixir \
-pa _build/prod/consolidated \
--no-halt \
--erl "+A$THREAD_COUNT" \
--erl "+K true" \
--erl "-smp auto" \
--erl "+scl false" \
--erl "+spp true" \
--erl "+swt low" \
--erl "+sbwt long" \
--sname $NODE \
--cookie $COOKIE \
-S mix run \
--no-compile \
$@ \
&
pid=$!
sleep 0
while kill -0 $pid 2>/dev/null ; do wait $pid ; done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment