Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100755 329 lines (302 sloc) 10.314 kb
21abc5b @klacke Initial revision
authored
1 #!/bin/sh
f6a5b93 @klacke ""
authored
2
28e4c73 @klacke first attempt to run properly under cygwin
authored
3 yawsdir="%yawsdir%"
28972a3 @klacke run_erl to_erl support patch from Mats Cronquist
authored
4 vardir="%vardir%"
28e4c73 @klacke first attempt to run properly under cygwin
authored
5 erl="%erl%"
28972a3 @klacke run_erl to_erl support patch from Mats Cronquist
authored
6 run_erl="%run_erl%"
7 to_erl="%to_erl%"
8
df7a68b @klacke set HOME if unset, this is required since some distros don't set HOME…
authored
9 # erlexec requires HOME to be set, and some distros
10 # run /etc/rc scripts without HOME being set
11 if [ -z "$HOME" ]; then
e9344fa @klacke prepare for 1.84
authored
12 if [ `id -u` = 0 -a -d /root ]; then
5e1d1ec @klacke prepare for 1.82
authored
13 export HOME=/root
14 else
15 export HOME=/tmp
e71db24 @klacke prepare for 1.82
authored
16 fi
df7a68b @klacke set HOME if unset, this is required since some distros don't set HOME…
authored
17 fi
18
28e4c73 @klacke first attempt to run properly under cygwin
authored
19 case `uname` in
20 CYGWIN*)
4607990 @klacke cygwin support
authored
21 yawsdir=`cygpath -m $yawsdir`
0be3c7e @klacke untabified all of yaws
authored
22 werl="%werl%"
4607990 @klacke cygwin support
authored
23 delim=/;;
28e4c73 @klacke first attempt to run properly under cygwin
authored
24 *)
25 delim=/
26 esac
21abc5b @klacke Initial revision
authored
27
28
844fe5a Added support for the '-heart' switch.
Tobbe Tornquist authored
29 ENV_PGM=`which env`
30
31
21abc5b @klacke Initial revision
authored
32 help()
33 {
28972a3 @klacke run_erl to_erl support patch from Mats Cronquist
authored
34 echo "usage: "
35 echo ""
88355a3 @vinoski * Document the --wait-started option for the yaws script
vinoski authored
36 echo
c9cd304 @klacke git-svn-id: https://erlyaws.svn.sourceforge.net/svnroot/erlyaws/trunk…
authored
37 echo " yaws -i | --interactive -- interactive (no daemon) mode"
38 echo " yaws -w | --winteractive -- cygwin interactive (werl) "
39 echo " yaws --daemon -- daemon mode"
88355a3 @vinoski * Document the --wait-started option for the yaws script
vinoski authored
40
28972a3 @klacke run_erl to_erl support patch from Mats Cronquist
authored
41 echo ""
88355a3 @vinoski * Document the --wait-started option for the yaws script
vinoski authored
42
28972a3 @klacke run_erl to_erl support patch from Mats Cronquist
authored
43 echo ""
88355a3 @vinoski * Document the --wait-started option for the yaws script
vinoski authored
44 echo " Auxiliary flags for the daemon: "
2ba5805 @vinoski add new --heart-restart option to allow control over heart restarts
vinoski authored
45 echo " --id Id -- set system id"
a80cfee @vinoski add --nodebug option
vinoski authored
46 echo " --debug -- debug mode"
47 echo " --nodebug -- turn off debug mode"
2ba5805 @vinoski add new --heart-restart option to allow control over heart restarts
vinoski authored
48 echo " --conf File -- set config file"
49 echo " --tracetraf -- trace traffic"
50 echo " --tracehttp -- trace http traffic"
51 echo " --traceout -- trace output to stdout"
52 echo " --version -- print version"
53 echo " --pa path -- add load path"
54 echo " --mnesiadir dir -- start Mnesia in dir"
55 echo " --proto_dist Mod -- use Mod for distrib"
56 echo " --sname xxx -- start with sname xxx"
57 echo " --name xxx -- start with name xxx"
58 echo " --runmod mod -- call mod:start/0 at startup"
59 echo " --heart -- auto restart yaws if it crashes"
60 echo " --heart-restart=C,T -- allow C heart restarts in T seconds"
61 echo " --erlarg X -- pass argument X to $erl"
62 echo " --setcookie X -- set an erlang cookie"
63 echo " --run_erl X -- use run_erl with pipe-id X"
64 echo " --to_erl X -- connect to pipe-id X"
65 echo " --disable-kpoll -- pass +K false to erlang"
28972a3 @klacke run_erl to_erl support patch from Mats Cronquist
authored
66 echo ""
88355a3 @vinoski * Document the --wait-started option for the yaws script
vinoski authored
67
28972a3 @klacke run_erl to_erl support patch from Mats Cronquist
authored
68 echo "ctl functions ... "
88355a3 @vinoski * Document the --wait-started option for the yaws script
vinoski authored
69 echo " yaws --hup [--id ID] -- hup the daemon, reload conf"
70 echo " yaws --stop [--id ID] -- stop the daemon "
71 echo " yaws --debug-dump [--id ID] -- produce a debug dump "
72 echo " yaws --status [--id ID] -- query the daemon status "
73 echo " yaws --load Modules -- load modules "
74 echo " yaws --ls -- list Yaws nodes and their status"
75 echo " yaws --ctltrace traffic|http -- toggle trace of running daemon"
76 echo " yaws --check YawsFile [IncDirs] -- test compile File "
77 echo " yaws --wait-started[=secs] [--id ID] -- wait for daemon to be ready"
a42cf46 @oliv3 yaws_ctl and conf template
oliv3 authored
78 echo " yaws --stats [--id ID] -- show daemon statistics"
28972a3 @klacke run_erl to_erl support patch from Mats Cronquist
authored
79 exit 1
21abc5b @klacke Initial revision
authored
80 }
dc00e52 @klacke postvar bug by hal snyder, added yaws_api:query_url/1 added the id su…
authored
81
82
21abc5b @klacke Initial revision
authored
83
d63642e @vinoski do not pass the --id option if the default id is used
vinoski authored
84 debug=""
85 daemon=""
86 interactive=""
87 trace=""
88 conf=""
89 runmod=""
90 sname=""
91 heart=""
92 xpath=""
93 mnesia=""
94 id=""
4d59534 @klacke ""
authored
95 pdist=""
37e9d70 @klacke -erlarg patch by Fredrik Thulin
authored
96 erlarg=""
a90bd68 @klacke added kpoll as default
authored
97 kpoll=true
88355a3 @vinoski * Document the --wait-started option for the yaws script
vinoski authored
98 call_wait_started=""
ddf3bee @klacke preparing for 1.78
authored
99 program=$0
100
101 wait_started() {
102 i=0
88355a3 @vinoski * Document the --wait-started option for the yaws script
vinoski authored
103 count=$1
104 while [ $i -lt $count ]; do
ddf3bee @klacke preparing for 1.78
authored
105 sleep 1
106 i=`expr $i + 1`
d63642e @vinoski do not pass the --id option if the default id is used
vinoski authored
107 idarg="--id ${id:-default}"
108 ${program} ${idarg} --status 2>&1 > /dev/null
2ba5805 @vinoski add new --heart-restart option to allow control over heart restarts
vinoski authored
109 [ $? = 0 ] && exit 0
ddf3bee @klacke preparing for 1.78
authored
110 done
d63642e @vinoski do not pass the --id option if the default id is used
vinoski authored
111 echo "No yaws system responding for id=$id"
ddf3bee @klacke preparing for 1.78
authored
112 exit 1
113 }
114
6949c22 @vinoski set HEART_COMMAND to allow a maximum of 5 restarts within any 60 seco…
vinoski authored
115 now=`date -u +%s`
2ba5805 @vinoski add new --heart-restart option to allow control over heart restarts
vinoski authored
116 restarts=1
117 starttime=$now
6949c22 @vinoski set HEART_COMMAND to allow a maximum of 5 restarts within any 60 seco…
vinoski authored
118 if [ "$HEART" = true ]; then
119 # we were restarted by heart, make sure we haven't reached our restart count
2ba5805 @vinoski add new --heart-restart option to allow control over heart restarts
vinoski authored
120 # if we get $YAWS_HEART_COUNT restarts within $YAWS_HEART_SECS seconds, we
121 # exit completely
122 # if both are 0, disable restart checking and just always restart
123 if [ $YAWS_HEART_COUNT -ne 0 -o $YAWS_HEART_SECS -ne 0 ]; then
124 timediff=`expr $now - $YAWS_HEART_START`
125 if [ $timediff -le $YAWS_HEART_SECS ]; then
126 if [ $YAWS_HEART_RESTARTS -eq $YAWS_HEART_COUNT ]; then
127 echo $YAWS_HEART_COUNT restarts attempted within $YAWS_HEART_SECS seconds, exiting
128 exit 1
129 else
130 # we haven't reached the restart max count yet, but we're still
131 # within the $YAWS_HEART_SECS second window so increment the counter
132 # but keep the same start time
133 restarts=`expr $YAWS_HEART_RESTARTS + 1`
134 starttime=$YAWS_HEART_START
135 fi
6949c22 @vinoski set HEART_COMMAND to allow a maximum of 5 restarts within any 60 seco…
vinoski authored
136 fi
137 fi
138 fi
d63642e @vinoski do not pass the --id option if the default id is used
vinoski authored
139 HEART_COMMAND="$ENV_PGM HEART=true YAWS_HEART_RESTARTS=$restarts YAWS_HEART_START=$starttime $program "${1+"$@"}
6949c22 @vinoski set HEART_COMMAND to allow a maximum of 5 restarts within any 60 seco…
vinoski authored
140 export HEART_COMMAND
141
88355a3 @vinoski * Document the --wait-started option for the yaws script
vinoski authored
142 while [ $# -gt 0 ]
28972a3 @klacke run_erl to_erl support patch from Mats Cronquist
authored
143 do
144 arg=$1
145 shift;
146 case $arg in
147 -i|--interactive)
0be3c7e @klacke untabified all of yaws
authored
148 interactive="true";
149 debug=" -yaws debug ";
150 daemon="";;
28972a3 @klacke run_erl to_erl support patch from Mats Cronquist
authored
151 -w|--winteractive)
0be3c7e @klacke untabified all of yaws
authored
152 interactive="true";
153 debug=" -yaws debug ";
154 daemon="";
155 erl=$werl;;
28972a3 @klacke run_erl to_erl support patch from Mats Cronquist
authored
156 -D|--daemon)
0be3c7e @klacke untabified all of yaws
authored
157 daemon=" -detached ";;
88355a3 @vinoski * Document the --wait-started option for the yaws script
vinoski authored
158 --wait-started=*)
2ba5805 @vinoski add new --heart-restart option to allow control over heart restarts
vinoski authored
159 call_wait_started=`echo $arg | sed -e 's/--wait-started=//'`
160 num=`expr "$call_wait_started" : "([0-9]*)"`
161 if [ "$num" != "$call_wait_started" ]; then
162 echo error: argument to --wait-started is $call_wait_started, not a number
163 exit 1
164 fi;;
ddf3bee @klacke preparing for 1.78
authored
165 --wait-started)
88355a3 @vinoski * Document the --wait-started option for the yaws script
vinoski authored
166 call_wait_started=6;;
28972a3 @klacke run_erl to_erl support patch from Mats Cronquist
authored
167 -d|--debug)
0be3c7e @klacke untabified all of yaws
authored
168 debug=" -boot start_sasl -yaws debug ";;
a80cfee @vinoski add --nodebug option
vinoski authored
169 --nodebug)
170 debug="";;
28972a3 @klacke run_erl to_erl support patch from Mats Cronquist
authored
171 -t|--tracetraf)
0be3c7e @klacke untabified all of yaws
authored
172 trace=" -yaws trace traffic ";;
28972a3 @klacke run_erl to_erl support patch from Mats Cronquist
authored
173 -T|--tracehttp)
0be3c7e @klacke untabified all of yaws
authored
174 trace=" -yaws trace http ";;
28972a3 @klacke run_erl to_erl support patch from Mats Cronquist
authored
175 -I|--id)
0be3c7e @klacke untabified all of yaws
authored
176 id=$1
177 shift;;
28972a3 @klacke run_erl to_erl support patch from Mats Cronquist
authored
178 -x|--traceout)
0be3c7e @klacke untabified all of yaws
authored
179 traceoutput=" -yaws traceoutput ";;
28972a3 @klacke run_erl to_erl support patch from Mats Cronquist
authored
180 --trace)
0be3c7e @klacke untabified all of yaws
authored
181 traceoutput=" -yaws traceoutput ";
182 trace=" -yaws trace traffic ";;
28972a3 @klacke run_erl to_erl support patch from Mats Cronquist
authored
183 -M|--mnesiadir)
91a5018 @klacke quote patch for mnesiadir by Richard Bucker
authored
184 mnesia=" -mnesia dir '\"$1\"' -run mnesia start"
0be3c7e @klacke untabified all of yaws
authored
185 shift;;
28972a3 @klacke run_erl to_erl support patch from Mats Cronquist
authored
186 -c|--conf)
0be3c7e @klacke untabified all of yaws
authored
187 conf=" -conf $1 "
188 shift;;
28972a3 @klacke run_erl to_erl support patch from Mats Cronquist
authored
189 -pa|--pa)
d63642e @vinoski do not pass the --id option if the default id is used
vinoski authored
190 xpath=" $xpath -pa $1 "
0be3c7e @klacke untabified all of yaws
authored
191 shift;;
28972a3 @klacke run_erl to_erl support patch from Mats Cronquist
authored
192 -r|--runmod)
0be3c7e @klacke untabified all of yaws
authored
193 runmod=" -runmod $1 "
194 shift;;
28972a3 @klacke run_erl to_erl support patch from Mats Cronquist
authored
195 -h|--hup)
0be3c7e @klacke untabified all of yaws
authored
196 ex="$erl -noshell -pa ${yawsdir}${delim}ebin -s yaws_ctl hup";;
28972a3 @klacke run_erl to_erl support patch from Mats Cronquist
authored
197 -s|--stop)
0be3c7e @klacke untabified all of yaws
authored
198 ex="$erl -noshell -pa ${yawsdir}${delim}ebin -s yaws_ctl stop";;
28972a3 @klacke run_erl to_erl support patch from Mats Cronquist
authored
199 -ls|--ls)
0be3c7e @klacke untabified all of yaws
authored
200 ex="$erl -noshell -pa ${yawsdir}${delim}ebin -s yaws_ctl ls";;
28972a3 @klacke run_erl to_erl support patch from Mats Cronquist
authored
201 -S|--status)
0be3c7e @klacke untabified all of yaws
authored
202 ex="$erl -noshell -pa ${yawsdir}${delim}ebin -s yaws_ctl status";;
eedaca5 @oliv3 yaws_ctl --stats added
oliv3 authored
203 --stats)
204 ex="$erl -noshell -pa ${yawsdir}${delim}ebin -s yaws_ctl stats";;
28972a3 @klacke run_erl to_erl support patch from Mats Cronquist
authored
205 -load|--load)
d63642e @vinoski do not pass the --id option if the default id is used
vinoski authored
206 loadid=${id:-default}
207 $erl -noshell -pa ${yawsdir}${delim}ebin -s yaws_ctl load $* $loadid
0be3c7e @klacke untabified all of yaws
authored
208 exit 0;;
5207102 @klacke Added debug dump functionality
authored
209 --debug-dump)
d63642e @vinoski do not pass the --id option if the default id is used
vinoski authored
210 ddid=${id:-default}
211 $erl -noshell -pa ${yawsdir}${delim}ebin -s yaws_ctl debug_dump $ddid
5207102 @klacke Added debug dump functionality
authored
212 exit 0;;
28972a3 @klacke run_erl to_erl support patch from Mats Cronquist
authored
213 -j|--ctltrace)
0be3c7e @klacke untabified all of yaws
authored
214 ex="$erl -noshell -pa ${yawsdir}${delim}ebin -s yaws_ctl trace $1"
215 shift;;
88355a3 @vinoski * Document the --wait-started option for the yaws script
vinoski authored
216 -v|--version)
0be3c7e @klacke untabified all of yaws
authored
217 exec $erl -noshell -pa ${yawsdir}${delim}ebin -s yaws printversion;
218 exit 0;;
28972a3 @klacke run_erl to_erl support patch from Mats Cronquist
authored
219 --sname|-sname)
0be3c7e @klacke untabified all of yaws
authored
220 sname=" -sname $1 "
221 shift;;
28972a3 @klacke run_erl to_erl support patch from Mats Cronquist
authored
222 -name|--name)
0be3c7e @klacke untabified all of yaws
authored
223 sname=" -name $1 "
224 shift;;
a90bd68 @klacke added kpoll as default
authored
225 --disable-kpoll)
226 kpoll=false;;
28972a3 @klacke run_erl to_erl support patch from Mats Cronquist
authored
227 -heart|--heart)
0be3c7e @klacke untabified all of yaws
authored
228 heart=" -heart ";;
2ba5805 @vinoski add new --heart-restart option to allow control over heart restarts
vinoski authored
229 --heart-restart=*)
230 vals=`echo $arg | sed -e 's/--heart-restart=//'`
231 saveifs="$IFS"
232 IFS=,
233 var='YAWS_HEART_COUNT'
234 for v in $vals; do
235 eval "$var=$v"
236 var='YAWS_HEART_SECS'
237 done
0e5ebd2 @vinoski improved checking of --heart-restart arguments
vinoski authored
238 num=`expr "$YAWS_HEART_COUNT" : '\([0-9]*\)'`
239 if [ -z "$num" -o "$num" != "$YAWS_HEART_COUNT" ]; then
240 echo error: count argument to --heart-restart is '"'$YAWS_HEART_COUNT'"': not a number
2ba5805 @vinoski add new --heart-restart option to allow control over heart restarts
vinoski authored
241 exit 1
242 fi
0e5ebd2 @vinoski improved checking of --heart-restart arguments
vinoski authored
243 num=`expr "$YAWS_HEART_SECS" : '\([0-9]*\)'`
244 if [ -z "$num" -o "$num" != "$YAWS_HEART_SECS" ]; then
245 echo error: time argument to --heart-restart is '"'$YAWS_HEART_SECS'"': not a number
2ba5805 @vinoski add new --heart-restart option to allow control over heart restarts
vinoski authored
246 exit 1
247 fi
248 IFS="$saveifs"
249 heart=" -heart ";;
28972a3 @klacke run_erl to_erl support patch from Mats Cronquist
authored
250 -proto_dist|--proto_dist)
0be3c7e @klacke untabified all of yaws
authored
251 pdist=" -proto_dist $1 "
252 shift;;
88355a3 @vinoski * Document the --wait-started option for the yaws script
vinoski authored
253 -setcookie|--setcookie)
254 erlarg="$erlarg -setcookie $1 "
255 shift;;
28972a3 @klacke run_erl to_erl support patch from Mats Cronquist
authored
256 -erlarg|--erlarg)
0be3c7e @klacke untabified all of yaws
authored
257 erlarg="$erlarg $1 "
258 shift;;
28972a3 @klacke run_erl to_erl support patch from Mats Cronquist
authored
259 -check|--check)
d63642e @vinoski do not pass the --id option if the default id is used
vinoski authored
260 checkid=${id:-default}
261 mkdir ${HOME}/.yaws/yaws 2> /dev/null
262 mkdir ${HOME}/.yaws/yaws/$checkid 2> /dev/null
263 out=`exec $erl -noshell -pa ${yawsdir}${delim}ebin $xpath -s yaws_ctl check $checkid $*`
0be3c7e @klacke untabified all of yaws
authored
264 if [ "$?" = "0" ]; then
265 echo "$out"
266 echo "$1" ok
267 exit 0
268 fi
269 echo "$out"
270 exit 1;;
28972a3 @klacke run_erl to_erl support patch from Mats Cronquist
authored
271 --to_erl)
0be3c7e @klacke untabified all of yaws
authored
272 TO_ERL=yes
273 PIPE_DIR="${vardir}/run/yaws/pipe/$1"
274 shift;;
28972a3 @klacke run_erl to_erl support patch from Mats Cronquist
authored
275 --run_erl)
0be3c7e @klacke untabified all of yaws
authored
276 RUN_ERL=yes
277 daemon=""
278 PIPE_DIR="${vardir}/run/yaws/pipe/$1"
279 LOG_DIR="${vardir}/log/yaws/erlang-log/$1"
280 shift;;
28972a3 @klacke run_erl to_erl support patch from Mats Cronquist
authored
281 *)
0be3c7e @klacke untabified all of yaws
authored
282 help
28972a3 @klacke run_erl to_erl support patch from Mats Cronquist
authored
283 esac
21abc5b @klacke Initial revision
authored
284 done
2ba5805 @vinoski add new --heart-restart option to allow control over heart restarts
vinoski authored
285 YAWS_HEART_COUNT=${YAWS_HEART_COUNT:-5}
286 YAWS_HEART_SECS=${YAWS_HEART_SECS:-60}
287 export YAWS_HEART_COUNT YAWS_HEART_SECS
21abc5b @klacke Initial revision
authored
288
88355a3 @vinoski * Document the --wait-started option for the yaws script
vinoski authored
289 [ -n "$call_wait_started" ] && wait_started $call_wait_started
dc00e52 @klacke postvar bug by hal snyder, added yaws_api:query_url/1 added the id su…
authored
290
d63642e @vinoski do not pass the --id option if the default id is used
vinoski authored
291 if [ -n "$ex" ]; then
292 [ -n "$id" ] && execid=$id || execid=default
293 exec $ex $execid
dc00e52 @klacke postvar bug by hal snyder, added yaws_api:query_url/1 added the id su…
authored
294 exit 0
295 fi
296
28972a3 @klacke run_erl to_erl support patch from Mats Cronquist
authored
297 if [ -n "$TO_ERL" ]; then
298 $to_erl $PIPE_DIR/
299 exit 0
300 fi
301
302 if [ -n "$RUN_ERL" ]; then
303 if [ ! -d $LOG_DIR ]; then
0be3c7e @klacke untabified all of yaws
authored
304 mkdir -p $LOG_DIR
28972a3 @klacke run_erl to_erl support patch from Mats Cronquist
authored
305 fi
306 if [ ! -d $PIPE_DIR ]; then
0be3c7e @klacke untabified all of yaws
authored
307 mkdir -p $PIPE_DIR
28972a3 @klacke run_erl to_erl support patch from Mats Cronquist
authored
308 fi
309 RUN_ERL="$run_erl -daemon $PIPE_DIR/ $LOG_DIR"
310 else
311 RUN_ERL="eval"
312 fi
313
d63642e @vinoski do not pass the --id option if the default id is used
vinoski authored
314 if [ -n "$id" ]; then
315 id="-yaws id $id"
92bafb4 @klacke removed the ability change userid, also stopped writing to /tmp/yaws …
authored
316 fi
dc00e52 @klacke postvar bug by hal snyder, added yaws_api:query_url/1 added the id su…
authored
317
d63642e @vinoski do not pass the --id option if the default id is used
vinoski authored
318 trace="$trace $traceoutput"
82d6e29 @klacke added -x flag for tty trace and did the 1.3 release
authored
319
28972a3 @klacke run_erl to_erl support patch from Mats Cronquist
authored
320 [ "$run_erl" = "eval" ] && [ -z "$daemon" ] && [ -z "$interactive" ] && help
321
d63642e @vinoski do not pass the --id option if the default id is used
vinoski authored
322 XEC="$daemon $heart +K $kpoll -pa ${yawsdir}${delim}ebin $xpath $sname $pdist $erlarg $debug -run yaws $trace $conf $runmod $mnesia $id"
38fb85e @klacke ""
authored
323
f22e6e8 Fixed heart bug
Johan Bevemyr authored
324 if [ -z "$heart" ] || [ -z "$daemon" ]; then
6949c22 @vinoski set HEART_COMMAND to allow a maximum of 5 restarts within any 60 seco…
vinoski authored
325 unset HEART_COMMAND
844fe5a Added support for the '-heart' switch.
Tobbe Tornquist authored
326 fi
327
d63642e @vinoski do not pass the --id option if the default id is used
vinoski authored
328 $RUN_ERL "exec $erl $XEC"
Something went wrong with that request. Please try again.