public
Created

This is a unix wrapper around the erlang vm.

  • Download Gist
my_app.sh
Shell
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
#!/bin/bash
 
# This is a unix wrapper around the erlang vm. It provides the following functionality:
#
# * Spawns in foreground
# * Handle SIGHUP and call RELOADFUNC
# * Handle SIGTERM SIGQUIT and SIGINT telling to the vm to quit
# * Dies if the vm dies (for example kernel killing because out of memory)
#
# Forks and improvements are welcome.
#
 
export APPNAME=my_app
export BASEDIR=`readlink -f $(dirname $0)/..`
export HOME=$BASEDIR
export APPDIR=$BASEDIR/apps/$APPNAME
export ENV=production
export PORT=18080
export SERVICE=my_service_name
export NODE="$SERVICE@`hostname -f`"
export CONFIG_FILE=$APPDIR/priv/$ENV.config
export COOKIE=sbs
export RELOAD="my_module my_func [my_args]"
 
cd $BASEDIR
 
reload(){
echo Reloading the app..
erl_call -c $COOKIE -a "$RELOAD" -n ${NODE}
}
trap reload SIGHUP
 
stop(){
echo Stopping the app
erl_call -c $COOKIE -q -n ${NODE}
}
trap stop SIGQUIT SIGINT SIGTERM
 
 
# Maybe you should adapt this to your needs.
exec erl -pa deps/*/ebin apps/*/ebin \
-boot start_sasl \
-sasl sasl_error_logger '{file, "./log/sasl.log"}' \
-s ${APPNAME}_app \
-noinput \
+K true \
+A 4 \
+swt very_low \
-$APPNAME environment $ENV \
-$APPNAME port $PORT \
-config "${CONFIG_FILE}" \
-setcookie $COOKIE \
-name $NODE $* &
pid=$!
sleep 0
 
 
echo Controlling the erlang VM $NODE running in $pid from $$. Waiting...
while kill -0 $pid ; do wait $pid ; done

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.