-
Notifications
You must be signed in to change notification settings - Fork 3
/
nextimctl
executable file
·142 lines (125 loc) · 4.46 KB
/
nextimctl
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
#!/bin/bash
#define default configuration
POLL=true
SMP=disable
ERL=erl
ERL_MAX_PORTS=32000
ERL_PROCESSES=250000
ERL_MAX_ETS_TABLES=1400
NODE_NAME=nextim
ROOTDIR=`cd $(dirname $0); pwd`
EBINS=$ROOTDIR/ebin
EXTRA_DB_NODE=$2
# define environment variables
NEXTIM_HOME=$ROOTDIR
DATETIME=`date "+%Y%m%d-%H%M%S"`
SASL_LOG_PATH="$ROOTDIR/var/log/${NODE_NAME}_sasl.log"
ERL_CRASH_DUMP="$ROOTDIR/var/log/erl_crash_$DATETIME.dump"
NEXTIM_SO_PATH="$ROOTDIR/priv/lib"
NEXTIM_DB="$ROOTDIR/var/data/$NODE_NAME"
NEXTIM_CONFIG_PATH="$ROOTDIR/etc/nextim/nextim"
NEXTIM_LOG="$ROOTDIR/var/log"
NEXTIM_LOG_LEVEL=4
NEXTIM_LOG_PATH="$NEXTIM_LOG/${NODE_NAME}.log"
RUNAPP=nextim
CTLAPP=nextim_ctl
# export global variables
export NEXTIM_HOME
export NEXTIM_SO_PATH
export SASL_LOG_PATH
export ERL_MAX_PORTS
export ERL_MAX_ETS_TABLES
export ERL_CRASH_DUMP
ERLANG_OPTS="-smp $SMP +P $ERL_PROCESSES +K $POLL "
[ -d $NEXTIM_DB ] || mkdir -p $NEXTIM_DB
[ -d $NEXTIM_LOG ] || mkdir -p $NEXTIM_LOG
ARGS=
while [ $# -ne 0 ] ; do
PARAM=$1
shift
case $PARAM in
--) break ;;
--node) NODE_NAME=$1; shift ;;
*) ARGS="$ARGS $PARAM" ;;
esac
done
# start server
# -noinput -detached \
start ()
{
$ERL $ERLANG_OPTS \
-sname $NODE_NAME \
-pa $ROOTDIR/ebin \
-setcookie public \
-mnesia dir "\"$NEXTIM_DB\"" \
-config $NEXTIM_CONFIG_PATH \
-sasl sasl_error_logger \{file,\"$SASL_LOG_PATH\"\} \
-boot start_sasl \
-s reloader start -s nextim start -log_level $NEXTIM_LOG_LEVEL -log_path $NEXTIM_LOG_PATH
}
# start cluster
# -noinput -detached \
cluster ()
{
$ERL $ERLANG_OPTS \
-sname $NODE_NAME \
-pa $ROOTDIR/ebin \
-setcookie public \
-mnesia extra_db_nodes \[$EXTRA_DB_NODE\] \
-config $NEXTIM_CONFIG_PATH \
-sasl sasl_error_logger \{file,\"$SASL_LOG_PATH\"\} \
-boot start_sasl \
-s reloader start -s nextim start -log_level $NEXTIM_LOG_LEVEL -log_path $NEXTIM_LOG_PATH
}
stop()
{
$ERL \
-noinput -sname nextim_ctl \
-pa $ROOTDIR/ebin \
-setcookie public \
-s nextim_ctl -extra nextim stop
}
# status
status ()
{
$ERL \
-noinput -sname nextim_ctl \
-pa $ROOTDIR/ebin \
-setcookie public \
-s nextim_ctl -extra nextim status
}
# common control function
ctl ()
{
$ERL \
-sname nextim_ctl \
-noinput \
-setcookie public \
-boot start_clean \
-pa $EBINS \
-s ${CTLAPP} -extra nextim $@
result=$?
case $result in
0) :;;
*) usage;;
esac
return $result
}
# display ctl usage
usage ()
{
echo ""
echo "Commands to start an nextim node:"
echo " start Start nextim"
echo " cluster Start cluster node"
echo " stop Stop nextim"
echo " status Status of nextim"
echo ""
}
case $ARGS in
' start') start;;
' stop') stop;;
' live') live;;
' cluster'*) cluster $ARGS;;
*) ctl $ARGS;;
esac