forked from RJ/playdar-core
-
Notifications
You must be signed in to change notification settings - Fork 1
/
playdarctl
executable file
·120 lines (111 loc) · 2.09 KB
/
playdarctl
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
#!/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=erl
ERL_OPTS="+K true +P 1000000"
EBIN=./ebin/
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 [ ! "$@" = "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 any key to continue.."
read foo
$ERL $ERL_OPTS \
-sname playdar@localhost \
-pa ebin \
-boot start_sasl \
-s reloader \
-s playdar
return $?
}
start ()
{
log_daemon_msg "Starting Playdar Daemon"
nohup $ERL $ERL_OPTS \
-sname playdar@localhost \
-detatched -noinput -noshell \
-pa ebin \
-boot start_sasl \
-s playdar 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
}
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;;
'stop') stop;;
*) ctl "$@";;
esac
cd "${ORIGDIR}"