Skip to content

Instantly share code, notes, and snippets.

@maxlapshin
Created August 16, 2013 16:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save maxlapshin/6251552 to your computer and use it in GitHub Desktop.
Save maxlapshin/6251552 to your computer and use it in GitHub Desktop.
Debian initscript for erlyvideo (flussonic)
#!/bin/bash
### BEGIN INIT INFO
# Provides: flussonic
# Required-Start: $local_fs $network $syslog
# Required-Stop: $local_fs $network $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Start/stop flussonic streaming server
### END INIT INFO
FLUDIR=/opt/flussonic
export PIDFILE=/var/run/flussonic/pid
COOKIEFILE=/etc/flussonic/cookie
export LOGDIR=/var/log/flussonic
export HOME=/opt/flussonic
#PATH
[ -f /etc/default/flussonic ] && . /etc/default/flussonic
[ -e priv/flussonic.conf ] && CONF=priv/flussonic.conf
[ -e priv/sample/flussonic.conf ] && CONF=priv/sample/flussonic.conf
case $1 in
"start")
PID=`cat $PIDFILE 2>/dev/null`
if [ "$PID" != "" ] ; then
if kill $PID >/dev/null 2>&1 ; then
echo "Killing old flussonic instance with pid $PID"
fi
fi
echo -n "Starting flussonic: "
mkdir -p /var/log/flussonic/console
mkdir -p /var/run/flussonic
export RUN_ERL_LOG_GENERATIONS=5
export RUN_ERL_LOG_MAXSIZE=100000
run_erl -daemon /var/run/flussonic/ /var/log/flussonic/console "exec $0 launch"
i=0
while ((i < 100)) && [ ! -f "$PIDFILE" ] ; do
echo -n "."
((i = i+1))
sleep 1
done
[ -f "$PIDFILE" ] && echo "done" || (echo "failed"; exit 1)
;;
"stop")
echo "Stopping flussonic"
if [ -f $COOKIEFILE ] ; then
COOKIE=`cat $COOKIEFILE`
echo `erl_call -a 'erlang halt' -n flussonic@127.0.0.1 -c "$COOKIE"`
fi
PID=`cat $PIDFILE 2>/dev/null`
[ "$PID" != "" ] && kill $PID >/dev/null 2>&1
rm -f $PIDFILE
if [ -e "/var/run/flussonic/erlang.pipe.1.w" ] ; then
echo -e "erlang:halt().\n" > /var/run/flussonic/erlang.pipe.1.w
fi
;;
"run")
echo "Running"
$0 launch
;;
"launch")
[ -e $FLUDIR ] && cd $FLUDIR
export ERL_LIBS=apps:deps
export PIDFILE
SBT="+stbt s"
if [ ! -f $COOKIEFILE ] ; then
date | md5sum | awk '{print $1}' > $COOKIEFILE
chmod 0600 $COOKIEFILE
fi
COOKIE=`cat $COOKIEFILE`
if [ "$ASYNC_THREADS" == "" ] ; then
ASYNC_THREADS="100 +a 32"
fi
CMD="erl +K true +A ${ASYNC_THREADS} ${SBT} -name flussonic@127.0.0.1 -setcookie $COOKIE -pa apps/*/ebin -pa deps/*/ebin -boot start_sasl -s flussonic -sasl errlog_type error"
exec $CMD
;;
"reload")
COOKIE=`cat $COOKIEFILE`
echo `erl_call -a 'flu reconf' -n flussonic@127.0.0.1 -c "$COOKIE"`
;;
"status")
COOKIE=`cat $COOKIEFILE`
eval "STATUS=`erl_call -a 'flu status' -n flussonic@127.0.0.1 -c "$COOKIE"`"
# echo `erl_call -a 'flu status' -n flussonic@127.0.0.1 -c "$COOKIE"`
echo -e $STATUS
;;
"restart")
echo "Restarting"
$0 stop
$0 start
;;
"attach")
echo "Attaching"
cd $FLUDIR
[ -f /usr/lib/erlang/bin/to_erl ] && TO_ERL=/usr/lib/erlang/bin/to_erl || TO_ERL=to_erl
$TO_ERL /var/run/flussonic/
;;
"shell")
echo "Remote shell"
COOKIE=`cat $COOKIEFILE`
erl -name debug@127.0.0.1 -remsh flussonic@127.0.0.1 -setcookie $COOKIE
;;
"force-reload")
echo "Force reload"
$0 stop
$0 start
;;
*)
echo "$0 start|stop|run|reload|restart|attach|shell"
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment