-
Notifications
You must be signed in to change notification settings - Fork 12
/
service_generic.sh
171 lines (158 loc) · 5.22 KB
/
service_generic.sh
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
#!/bin/bash
cmd=$0
argscount=$#
function usage {
echo "usage: $1 add service_name app_name node_name node_host cluster_name cluster_host cookie dderlip dderlport imemip imemport imemtype imemschema"
echo " $1 remove service_name"
echo " $1 start service_name"
echo " $1 stop service_name"
echo " $1 list service_name"
echo " $1 attach node_name node_host cookie"
echo " $1 gui service_name app_name node_name node_host cluster_name cluster_host cookie dderlip dderlport imemip imemport imemtype imemschema"
echo " $1 txt service_name app_name node_name node_host cluster_name cluster_host cookie dderlip dderlport imemip imemport imemtype imemschema"
echo " $1 check node_name node_host cookie"
echo " $1 escript script_file_path_name node_name node_host cookie"
}
function path2win {
eval $1=$(echo "${!1}" | sed 's/^\(\/\)\(.\)\(\/\)/\2:\//')
}
function check_arg_count {
if [ $argscount -le $1 ]; then
echo "Missing arguments; got $argscount"
usage $cmd
exit 0
fi
}
deps=''
for dir in $PWD/_build/default/lib/*/
do
dir=${dir%*/}
dr=$PWD/_build/default/lib/${dir##*/}/ebin
path2win dr
deps="$deps $dr"
done
# augment pwd to the front of all paths
erlpaths="-pa $deps"
kernellogfile=$PWD/log/kernel.txt
path2win kernellogfile
kernelconfig="-kernel inet_dist_listen_min 7000 -kernel inet_dist_listen_max 7020 -proto_dist imem_inet_tcp"
kernelconfigsrv="$kernelconfig -kernel error_logger {file,\\\"""$kernellogfile\\\"""}"
service_name=$2
app_name=$3
node_name=$4
node_host=$5
cluster_name=$6
cluster_host=$7
cookie=$8
dderlip=$9
dderlport=${10}
imemip=${11}
imemport=${12}
imemtype=${13}
imemschema=${14}
lagerconfig=${15}
# dderl opts
dderl_opts="-dderl"
dderl_srv_opts=$dderl_opts" interface \\\"$dderlip\\\" port $dderlport"
dderl_opts=$dderl_opts" interface \"$dderlip\" port $dderlport"
# imem opts
imem_opts="-imem"
imem_opts=$imem_opts" tcp_port $imemport"
imem_opts=$imem_opts" mnesia_node_type $imemtype"
imem_opts=$imem_opts" mnesia_schema_name $imemschema"
imem_opts=$imem_opts" erl_cluster_mgrs ['$cluster_name@$cluster_host']"
imem_srv_opts=$imem_opts" tcp_ip \\\"$imemip\\\""
imem_opts=$imem_opts" tcp_ip \"$imemip\""
# sasl opts
sasl_opts="-sasl"
sasl_opts=$sasl_opts" sasl_error_logger false"
# lager config
config=""
if [ -n "$lagerconfig" ]; then
path2win lagerconfig
config="-config $lagerconfig"
fi
commonparams="$erlpaths -emu_args -setcookie $cookie $dderl_opts $imem_opts $sasl_opts $config -s $app_name"
common_srv_params="$erlpaths -emu_args -setcookie $cookie $dderl_srv_opts $imem_srv_opts $config -s $app_name"
name="-name $node_name@$node_host"
case $1 in
"gui" )
check_arg_count 6
unamestr=`uname`
if [[ "$unamestr" == 'Linux' ]]; then
exename=erl
else
exename="start //MAX werl.exe"
fi
echo "Starting $service_name local GUI with '$exename $name $kernelconfig $commonparams'"
$exename $name $kernelconfig $commonparams
;;
"txt" )
check_arg_count 6
echo "Starting $service_name local TEXT with 'erl.exe -name $name $kernelconfig $commonparams'"
unamestr=`uname`
if [[ "$unamestr" == 'Linux' ]]; then
exename=erl
else
exename=erl.exe
fi
$exename $name $kernelconfig $commonparams
;;
"add" )
check_arg_count 6
echo "Adding $service_name service erlsrv.exe add $service_name -c \"$service_name Service\" -stopaction \"init:stop().\" -debugtype new -w $PWD $name -args \"$kernelconfigsrv $commonparams\""
erlsrv.exe add $service_name -c "$service_name Service" -stopaction "init:stop()." -debugtype new -w $PWD $name -args "$kernelconfigsrv $common_srv_params"
;;
"remove" )
check_arg_count 1
echo Removing $service_name service
erlsrv.exe remove $service_name
;;
"start" )
check_arg_count 1
echo Starting $service_name service
erlsrv.exe start $service_name
;;
"stop" )
check_arg_count 1
echo Stopping $service_name service
erlsrv.exe stop $service_name
;;
"list" )
check_arg_count 1
erlsrv.exe list $service_name
;;
"escript" )
check_arg_count 4
if [ -f "$2" ]; then
$2 $3 $4 $5
else
echo escript not found $2
fi
;;
"check" )
check_arg_count 3
if [ -f "./check.escript" ]; then
./check.escript $2 $3 $4
elif [ -f "./_build/default/lib/dderl/check.escript" ]; then
./_build/default/lib/dderl/check.escript $2 $3 $4
else
echo file not found : check.escript
fi
;;
"attach" )
check_arg_count 3
node=$2@$3
cookie_service=$4
echo "Connecting local node start //MAX werl.exe -remsh $node -name remsh_$node -setcookie $cookie_service"
start //MAX werl.exe -remsh $node -name remsh_$node -setcookie $cookie_service
;;
*)
erlsrv.exe list $service_name
echo
if [ ! -z "$1" -a "$1" != " " ]; then
echo Bad Argument : "'"$1"'"
fi
usage $cmd
;;
esac