-
Notifications
You must be signed in to change notification settings - Fork 0
/
control
executable file
·192 lines (170 loc) · 3.6 KB
/
control
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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
#!/bin/bash
#
# erlsearch Start/stop Erlang Search Server
#
### BEGIN INIT INFO
# Provides: erlsearch
# Required-Start: $network $all
# Required-Stop: $network $all
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Starts erlsearch server
# Description: Starts erlsearch server
### END INIT INFO
NAME=erlsearch
HOST=127.0.0.1
NODE=$NAME@$HOST
SET_ERL=/opt/erlang/r17.3/activate
NAME_TEST=${NAME}_test
NODE_TEST=$NAME_TEST@$HOST
NODE_TEST_INST=${NAME_TEST}_inst@$HOST
SERVER_USER=$NAME
USER=`id -nu`
if [ $USER == $SERVER_USER ]
then
SERVER_BASE=/opt/$NAME
else
SERVER_BASE=/home/$USER/$NAME
fi
LOG_BASE=$SERVER_BASE/log
LOG_TEST_BASE=$SERVER_BASE/test/logs
SERVER_CONF=$SERVER_BASE/priv/$NAME.config
SERVER_DEV_CONF=$SERVER_BASE/priv/${NAME}_dev.config
SERVER_TEST_CONF=$SERVER_BASE/priv/${NAME}_test.config
SERVER_LOG=$LOG_BASE/$NAME.error.log
SERVER_SASLLOG=$LOG_BASE/$NAME.sasl.log
SERVER_TEST_LOG=$LOG_TEST_BASE/$NAME.error.log
SERVER_TEST_SASLLOG=$LOG_TEST_BASE/$NAME.sasl.log
ERL_CRASH_DUMP=$LOG_BASE/erl_crash.dump
export ERL_CRASH_DUMP
user_do() {
if [ $USER == "root" ]
then
su $SERVER_USER -c "$0 $1"
else
exec $0 $1
fi
}
start() {
. $SET_ERL
erl -name "$NODE" -pa ebin deps/*/ebin -s $NAME \
-sasl sasl_error_logger "{file, \"$SERVER_SASLLOG\"}" \
-config $SERVER_CONF \
-kernel error_logger "{file, \"$SERVER_LOG\"}" \
-noshell -detached
}
debug() {
. $SET_ERL
cd $SERVER_BASE
echo $NODE
erl -name "$NODE" -config $SERVER_DEV_CONF -pa ebin deps/*/ebin -s $NAME -s reloader
}
test() {
. $SET_ERL
cd $SERVER_BASE
erl -name "$NODE_TEST" -config $SERVER_TEST_CONF -pa ebin deps/*/ebin -s $NAME \
-sasl sasl_error_logger "{file, \"$SERVER_TEST_SASLLOG\"}" \
-kernel error_logger "{file, \"$SERVER_TEST_LOG\"}" \
-noshell -detached
erl -name "$NODE_TEST_INST" -config $SERVER_TEST_CONF -pa ebin deps/*/ebin -s ${NAME}_test test_all -s init stop
# erl -name "$NODE_TEST_INST" -config $SERVER_TEST_CONF -pa ebin deps/*/ebin -s ${NAME}_test test_all
# erl -name "$NODE_TEST_INST" -config $SERVER_TEST_CONF -pa ebin deps/*/ebin
}
stop() {
. $SET_ERL
cd $SERVER_BASE
echo "rpc:call('$NODE', init, stop, [])." | erl -name "stop@$HOST" > /dev/null
}
stop_test() {
. $SET_ERL
cd $SERVER_BASE
echo "rpc:call('$NODE_TEST', init, stop, [])." | erl -name "stop@$HOST" > /dev/null
}
running() {
. $SET_ERL
epmd -names | grep "name $NAME at" > /dev/null
}
running_test() {
. $SET_ERL
epmd -names | grep "name $NAME_TEST at" > /dev/null
}
status() {
if running ; then
echo "$NAME is running."
else
echo "$NAME is stopped."
fi
}
case "$1" in
start)
user_do user_start
;;
stop)
user_do user_stop
;;
restart)
user_do user_restart
;;
attach)
user_do user_attach
;;
debug)
user_do user_debug
;;
test)
user_do user_test
;;
user_start)
echo "Starting $NAME server: $NODE ..."
if running ; then
echo "$NAME is already running!"
else
start
fi
;;
user_stop)
echo "Stopping $NAME server: $NODE ..."
if running ; then
stop
else
echo "$NAME is already stopped!"
fi
;;
user_restart)
echo "Restarting $NAME server: $NODE ..."
if running ; then
stop
sleep 1
start
else
start
fi
;;
user_test)
if running_test ; then
stop_test
else
echo "Start testing..."
test
stop_test
fi
;;
user_debug)
if running ; then
echo "Stop $NAME for debugging!"
else
debug
fi
;;
status)
status
;;
user_attach)
. $SET_ERL
erl -name "remsh$RANDOM@$HOST" -remsh "$NODE"
;;
*)
echo "Usage: $0 {start|stop|restart|debug|test|status|attach}"
exit 1
;;
esac