Last active
April 9, 2017 16:01
-
-
Save camshaft/f0359b6aaaade2a11d73 to your computer and use it in GitHub Desktop.
elixir startup script with graceful shutdown
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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