-
Notifications
You must be signed in to change notification settings - Fork 32
/
yaws.template
executable file
·221 lines (196 loc) · 5.52 KB
/
yaws.template
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
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
#!/bin/sh
yawsdir="%yawsdir%"
vardir="%vardir%"
erl="%erl%"
run_erl="%run_erl%"
to_erl="%to_erl%"
case `uname` in
CYGWIN*)
yawsdir=`cygpath --windows $yawsdir`
werl="%werl%"
delim=\\;;
*)
delim=/
esac
ENV_PGM=`which env`
help()
{
echo "usage: "
echo ""
echo
echo " yaws -i | --interactive -- interactive (no daemon) mode"
echo " yaws -w | --winteractive -- cygwin interactive (werl) "
echo " yaws --daemon -- daemon mode"
echo ""
echo ""
echo " Auxilliary flags for the daemon: "
echo " --id Id -- Set system id"
echo " --debug -- debug mode "
echo " --conf File -- set config file"
echo " --tracetraf -- trace traffic"
echo " --tracehttp -- trace http traffic"
echo " --traceout -- trace output to stdout"
echo " --version -- print version"
echo " --pa path -- add load path"
echo " --mnesiadir dir -- start Mnesia in dir"
echo " --proto_dist Mod -- use Mod for distrib"
echo " --sname xxx -- start with sname xxx"
echo " --name xxx -- start with name xxx"
echo " --runmod mod -- call mod:start/0 at startup"
echo " --heart -- auto restart yaws if it crashes"
echo " --erlarg X -- pass argument X to $erl"
echo " --run_erl X -- use run_erl with pipe-id X"
echo " --to_erl X -- connect to pipe-id X"
echo ""
echo "ctl functions ... "
echo " yaws --hup [--id ID] -- hup the daemon, reload conf"
echo " yaws --stop [--id ID] -- stop the daemon "
echo " yaws --status [--id ID] -- query the daemon status "
echo " yaws --load Modules -- load modules "
echo " yaws --ls -- list Yaws nodes and their status"
echo " yaws --ctltrace traffic|http -- toggle trace of running daemon"
echo " yaws --check YawsFile [IncDirs] -- test compile File "
exit 1
}
debug="";
daemon="";
interactive="";
trace="";
conf="";
runmod="";
sname="";
heart="";
xpath="";
mnesia="";
id="default";
pdist=""
erlarg=""
while [ $# -gt 0 ]
do
arg=$1
shift;
case $arg in
-i|--interactive)
interactive="true";
debug=" -yaws debug ";
daemon="";;
-w|--winteractive)
interactive="true";
debug=" -yaws debug ";
daemon="";
erl=$werl;;
-D|--daemon)
daemon=" -detached ";;
-d|--debug)
debug=" -boot start_sasl -yaws debug ";;
-t|--tracetraf)
trace=" -yaws trace traffic ";;
-T|--tracehttp)
trace=" -yaws trace http ";;
-I|--id)
id=$1
shift;;
-x|--traceout)
traceoutput=" -yaws traceoutput ";;
--trace)
traceoutput=" -yaws traceoutput ";
trace=" -yaws trace traffic ";;
-M|--mnesiadir)
mnesia=" -mnesia dir '"$1"' -run mnesia start"
shift;;
-c|--conf)
conf=" -conf $1 "
shift;;
-pa|--pa)
xpath=" ${xpath} -pa $1 "
shift;;
-r|--runmod)
runmod=" -runmod $1 "
shift;;
-h|--hup)
ex="$erl -noshell -pa ${yawsdir}${delim}ebin -s yaws_ctl hup";;
-s|--stop)
ex="$erl -noshell -pa ${yawsdir}${delim}ebin -s yaws_ctl stop";;
-ls|--ls)
ex="$erl -noshell -pa ${yawsdir}${delim}ebin -s yaws_ctl ls";;
-S|--status)
ex="$erl -noshell -pa ${yawsdir}${delim}ebin -s yaws_ctl status";;
-load|--load)
$erl -noshell -pa ${yawsdir}${delim}ebin -s yaws_ctl load ${id} $*
exit 0;;
-j|--ctltrace)
ex="$erl -noshell -pa ${yawsdir}${delim}ebin -s yaws_ctl trace $1"
shift;;
-v|--version)
exec $erl -noshell -pa ${yawsdir}${delim}ebin -s yaws printversion;
exit 0;;
--sname|-sname)
sname=" -sname $1 "
shift;;
-name|--name)
sname=" -name $1 "
shift;;
-heart|--heart)
heart=" -heart ";;
-proto_dist|--proto_dist)
pdist=" -proto_dist $1 "
shift;;
-erlarg|--erlarg)
erlarg="$erlarg $1 "
shift;;
-check|--check)
mkdir ${HOME}/.yaws/ 2> /dev/null
mkdir ${HOME}/.yaws/${ID} 2> /dev/null
out=`exec $erl -noshell -pa ${yawsdir}${delim}ebin ${xpath} -s yaws_ctl check ${id} $*`
if [ "$?" = "0" ]; then
echo "$out"
echo "$1" ok
exit 0
fi
echo "$out"
exit 1;;
--to_erl)
TO_ERL=yes
PIPE_DIR="${vardir}/run/yaws/pipe/$1"
shift;;
--run_erl)
RUN_ERL=yes
daemon=""
PIPE_DIR="${vardir}/run/yaws/pipe/$1"
LOG_DIR="${vardir}/log/yaws/erlang-log/$1"
shift;;
*)
help
esac
done
if [ ! -z "${ex}" ]; then
exec ${ex} ${id}
exit 0
fi
if [ -n "$TO_ERL" ]; then
$to_erl $PIPE_DIR/
exit 0
fi
if [ -n "$RUN_ERL" ]; then
if [ ! -d $LOG_DIR ]; then
mkdir -p $LOG_DIR
fi
if [ ! -d $PIPE_DIR ]; then
mkdir -p $PIPE_DIR
fi
RUN_ERL="$run_erl -daemon $PIPE_DIR/ $LOG_DIR"
else
RUN_ERL="eval"
fi
if [ ! -z "${id}" ]; then
id="-yaws id ${id}"
fi
trace="${trace} ${traceoutput}"
[ "$run_erl" = "eval" ] && [ -z "$daemon" ] && [ -z "$interactive" ] && help
XEC="${daemon} ${heart} -pa ${yawsdir}${delim}ebin ${xpath} ${sname} ${pdist} ${erlarg} ${debug} -run yaws ${trace} ${conf} ${runmod} ${mnesia} ${id}"
if [ -z "$heart" ] || [ -z "$daemon" ]; then
HEART_COMMAND="";
else
export HEART_COMMAND="${ENV_PGM} HEART=true \"$erl\" $XEC";
fi
${RUN_ERL} "exec $erl $XEC"