Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: websockets
Fetching contributors…

Cannot retrieve contributors at this time

executable file 140 lines (127 sloc) 2.739 kb
#!/bin/sh
#
# Playdar ctl script for controlling playdar
#
if [ -e /lib/lsb/init-functions ]
then
. /lib/lsb/init-functions
else
log_daemon_msg ()
{
echo $@
}
log_end_msg ()
{
if [ $@ -eq 0 ]
then
echo "OK"
else
echo "ERROR"
fi
}
fi
ORIGDIR=${CWD}
cd `dirname "$0"`
# Erl node name:
if [ ! "$ENAME" ]
then
ENAME="playdar"
fi
ERL=erl
ERL_OPTS="+K true +P 1000000"
EBIN_DIR="ebin"
PLAYDAR_OPTS="-s playdar -sname ${ENAME}@localhost -pa ${EBIN_DIR} -boot start_sasl"
PLAYDAR_LOG_DIR=.
ctl ()
{
SNAME=playdar_ctl-`date +%s`
$ERL $ERL_OPTS \
-sname "${SNAME}" \
-noinput \
-pa ebin \
-s playdar_ctl \
-extra playdar@localhost \
"$@"
R=$?
if [ $R -eq 0 ]
then
return 0
else
if [ ! "$1" = "stop" ]
then
echo "Usage: playdarctl <start|start-debug|stop|help>"
echo " (additional commands available once playdar is running)"
fi
exit $R
fi
}
startdebug ()
{
echo "Starting Playdar (debug interactive mode)."
echo "NB: to safely exit the erlang shell, type: q().<enter>"
echo "Press enter to continue.."
read foo
echo "Launching: $ERL $ERL_OPTS -s reloader $PLAYDAR_OPTS"
$ERL $ERL_OPTS -s reloader $PLAYDAR_OPTS
return $?
}
debug()
{
echo "This will start an interactive erlang shell connected to the running instance."
echo "If you type the wrong thing, you will crash Playdar."
echo "Press ^C^C to exit safely once connected."
echo "Enter to continue, ^C to abort."
read foo
$ERL -hidden -sname debug@localhost -pa ${EBIN_DIR} -remsh playdar@localhost
return $?
}
start ()
{
log_daemon_msg "Starting Playdar Daemon"
nohup $ERL $ERL_OPTS \
-detatched -noinput -noshell \
$PLAYDAR_OPTS 1> $PLAYDAR_LOG_DIR/playdar.log 2> $PLAYDAR_LOG_DIR/playdar.err &
# now to check if it spawned ok (within 5 secs):
i=5
while [ $i -gt 0 ]
do
pong=`$0 ping`
if [ "$pong" = "PONG" ]
then
log_end_msg 0
exit 0
fi
i=$((i-1))
sleep 1
done
log_end_msg 1
exit 1
}
startexec ()
{
exec $ERL $ERL_OPTS $PLAYDAR_OPTS \
-noinput 1> $PLAYDAR_LOG_DIR/playdar.log 2> $PLAYDAR_LOG_DIR/playdar.err
}
stop ()
{
log_daemon_msg "Stopping Playdar Daemon"
ctl stop
if [ $? -eq 0 ]
then
sleep 1
log_end_msg 0
return 0
else
log_end_msg 1
return 1
fi
}
case "$@" in
'start') start;;
'start-debug') startdebug;;
'start-exec') startexec;;
'debug') debug;;
'stop') stop;;
*) ctl "$@";;
esac
cd "${ORIGDIR}"
Jump to Line
Something went wrong with that request. Please try again.