-
Notifications
You must be signed in to change notification settings - Fork 17
/
playdarctl
executable file
·139 lines (127 loc) · 2.67 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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
#!/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}"