Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100755 324 lines (297 sloc) 10.188 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 fo...
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 fo...
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/ya...
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 suppo...
authored
81
82
21abc5b @klacke Initial revision
authored
83
22fd788 Added the '-r <Mod>' switch.
Tobbe Tornquist authored
84 debug="";
38fb85e @klacke ""
authored
85 daemon="";
86 interactive="";
22fd788 Added the '-r <Mod>' switch.
Tobbe Tornquist authored
87 trace="";
88 conf="";
89 runmod="";
ab3a6d0 Added the '-sname <Node>' switch to the yaws script
Tobbe Tornquist authored
90 sname="";
844fe5a Added support for the '-heart' switch.
Tobbe Tornquist authored
91 heart="";
767ff08 added -pa switch to the yaws start script
Tobbe Tornquist authored
92 xpath="";
c7c87a4 @klacke -sname and mnesia flag added to start script
authored
93 mnesia="";
dc00e52 @klacke postvar bug by hal snyder, added yaws_api:query_url/1 added the id suppo...
authored
94 id="default";
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`
107 ${program} --id ${id} --status 2>&1 > /dev/null
2ba5805 @vinoski add new --heart-restart option to allow control over heart restarts
vinoski authored
108 [ $? = 0 ] && exit 0
ddf3bee @klacke preparing for 1.78
authored
109 done
110 echo "No yaws system responding for id=${id}"
111 exit 1
112 }
113
6949c22 @vinoski set HEART_COMMAND to allow a maximum of 5 restarts within any 60 second ...
vinoski authored
114 now=`date -u +%s`
2ba5805 @vinoski add new --heart-restart option to allow control over heart restarts
vinoski authored
115 restarts=1
116 starttime=$now
6949c22 @vinoski set HEART_COMMAND to allow a maximum of 5 restarts within any 60 second ...
vinoski authored
117 if [ "$HEART" = true ]; then
118 # 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
119 # if we get $YAWS_HEART_COUNT restarts within $YAWS_HEART_SECS seconds, we
120 # exit completely
121 # if both are 0, disable restart checking and just always restart
122 if [ $YAWS_HEART_COUNT -ne 0 -o $YAWS_HEART_SECS -ne 0 ]; then
123 timediff=`expr $now - $YAWS_HEART_START`
124 if [ $timediff -le $YAWS_HEART_SECS ]; then
125 if [ $YAWS_HEART_RESTARTS -eq $YAWS_HEART_COUNT ]; then
126 echo $YAWS_HEART_COUNT restarts attempted within $YAWS_HEART_SECS seconds, exiting
127 exit 1
128 else
129 # we haven't reached the restart max count yet, but we're still
130 # within the $YAWS_HEART_SECS second window so increment the counter
131 # but keep the same start time
132 restarts=`expr $YAWS_HEART_RESTARTS + 1`
133 starttime=$YAWS_HEART_START
134 fi
6949c22 @vinoski set HEART_COMMAND to allow a maximum of 5 restarts within any 60 second ...
vinoski authored
135 fi
136 fi
137 fi
138 HEART_COMMAND="${ENV_PGM} HEART=true YAWS_HEART_RESTARTS=$restarts YAWS_HEART_START=$starttime $program "${1+"$@"}
139 export HEART_COMMAND
140
88355a3 @vinoski * Document the --wait-started option for the yaws script
vinoski authored
141 while [ $# -gt 0 ]
28972a3 @klacke run_erl to_erl support patch from Mats Cronquist
authored
142 do
143 arg=$1
144 shift;
145 case $arg in
146 -i|--interactive)
0be3c7e @klacke untabified all of yaws
authored
147 interactive="true";
148 debug=" -yaws debug ";
149 daemon="";;
28972a3 @klacke run_erl to_erl support patch from Mats Cronquist
authored
150 -w|--winteractive)
0be3c7e @klacke untabified all of yaws
authored
151 interactive="true";
152 debug=" -yaws debug ";
153 daemon="";
154 erl=$werl;;
28972a3 @klacke run_erl to_erl support patch from Mats Cronquist
authored
155 -D|--daemon)
0be3c7e @klacke untabified all of yaws
authored
156 daemon=" -detached ";;
88355a3 @vinoski * Document the --wait-started option for the yaws script
vinoski authored
157 --wait-started=*)
2ba5805 @vinoski add new --heart-restart option to allow control over heart restarts
vinoski authored
158 call_wait_started=`echo $arg | sed -e 's/--wait-started=//'`
159 num=`expr "$call_wait_started" : "([0-9]*)"`
160 if [ "$num" != "$call_wait_started" ]; then
161 echo error: argument to --wait-started is $call_wait_started, not a number
162 exit 1
163 fi;;
ddf3bee @klacke preparing for 1.78
authored
164 --wait-started)
88355a3 @vinoski * Document the --wait-started option for the yaws script
vinoski authored
165 call_wait_started=6;;
28972a3 @klacke run_erl to_erl support patch from Mats Cronquist
authored
166 -d|--debug)
0be3c7e @klacke untabified all of yaws
authored
167 debug=" -boot start_sasl -yaws debug ";;
a80cfee @vinoski add --nodebug option
vinoski authored
168 --nodebug)
169 debug="";;
28972a3 @klacke run_erl to_erl support patch from Mats Cronquist
authored
170 -t|--tracetraf)
0be3c7e @klacke untabified all of yaws
authored
171 trace=" -yaws trace traffic ";;
28972a3 @klacke run_erl to_erl support patch from Mats Cronquist
authored
172 -T|--tracehttp)
0be3c7e @klacke untabified all of yaws
authored
173 trace=" -yaws trace http ";;
28972a3 @klacke run_erl to_erl support patch from Mats Cronquist
authored
174 -I|--id)
0be3c7e @klacke untabified all of yaws
authored
175 id=$1
176 shift;;
28972a3 @klacke run_erl to_erl support patch from Mats Cronquist
authored
177 -x|--traceout)
0be3c7e @klacke untabified all of yaws
authored
178 traceoutput=" -yaws traceoutput ";;
28972a3 @klacke run_erl to_erl support patch from Mats Cronquist
authored
179 --trace)
0be3c7e @klacke untabified all of yaws
authored
180 traceoutput=" -yaws traceoutput ";
181 trace=" -yaws trace traffic ";;
28972a3 @klacke run_erl to_erl support patch from Mats Cronquist
authored
182 -M|--mnesiadir)
91a5018 @klacke quote patch for mnesiadir by Richard Bucker
authored
183 mnesia=" -mnesia dir '\"$1\"' -run mnesia start"
0be3c7e @klacke untabified all of yaws
authored
184 shift;;
28972a3 @klacke run_erl to_erl support patch from Mats Cronquist
authored
185 -c|--conf)
0be3c7e @klacke untabified all of yaws
authored
186 conf=" -conf $1 "
187 shift;;
28972a3 @klacke run_erl to_erl support patch from Mats Cronquist
authored
188 -pa|--pa)
0be3c7e @klacke untabified all of yaws
authored
189 xpath=" ${xpath} -pa $1 "
190 shift;;
28972a3 @klacke run_erl to_erl support patch from Mats Cronquist
authored
191 -r|--runmod)
0be3c7e @klacke untabified all of yaws
authored
192 runmod=" -runmod $1 "
193 shift;;
28972a3 @klacke run_erl to_erl support patch from Mats Cronquist
authored
194 -h|--hup)
0be3c7e @klacke untabified all of yaws
authored
195 ex="$erl -noshell -pa ${yawsdir}${delim}ebin -s yaws_ctl hup";;
28972a3 @klacke run_erl to_erl support patch from Mats Cronquist
authored
196 -s|--stop)
0be3c7e @klacke untabified all of yaws
authored
197 ex="$erl -noshell -pa ${yawsdir}${delim}ebin -s yaws_ctl stop";;
28972a3 @klacke run_erl to_erl support patch from Mats Cronquist
authored
198 -ls|--ls)
0be3c7e @klacke untabified all of yaws
authored
199 ex="$erl -noshell -pa ${yawsdir}${delim}ebin -s yaws_ctl ls";;
28972a3 @klacke run_erl to_erl support patch from Mats Cronquist
authored
200 -S|--status)
0be3c7e @klacke untabified all of yaws
authored
201 ex="$erl -noshell -pa ${yawsdir}${delim}ebin -s yaws_ctl status";;
eedaca5 @oliv3 yaws_ctl --stats added
oliv3 authored
202 --stats)
203 ex="$erl -noshell -pa ${yawsdir}${delim}ebin -s yaws_ctl stats";;
28972a3 @klacke run_erl to_erl support patch from Mats Cronquist
authored
204 -load|--load)
a679f38 @klacke --load and --id togehtehr didn't work
authored
205 $erl -noshell -pa ${yawsdir}${delim}ebin -s yaws_ctl load $* ${id}
0be3c7e @klacke untabified all of yaws
authored
206 exit 0;;
5207102 @klacke Added debug dump functionality
authored
207 --debug-dump)
208 $erl -noshell -pa ${yawsdir}${delim}ebin -s yaws_ctl debug_dump ${id}
209 exit 0;;
28972a3 @klacke run_erl to_erl support patch from Mats Cronquist
authored
210 -j|--ctltrace)
0be3c7e @klacke untabified all of yaws
authored
211 ex="$erl -noshell -pa ${yawsdir}${delim}ebin -s yaws_ctl trace $1"
212 shift;;
88355a3 @vinoski * Document the --wait-started option for the yaws script
vinoski authored
213 -v|--version)
0be3c7e @klacke untabified all of yaws
authored
214 exec $erl -noshell -pa ${yawsdir}${delim}ebin -s yaws printversion;
215 exit 0;;
28972a3 @klacke run_erl to_erl support patch from Mats Cronquist
authored
216 --sname|-sname)
0be3c7e @klacke untabified all of yaws
authored
217 sname=" -sname $1 "
218 shift;;
28972a3 @klacke run_erl to_erl support patch from Mats Cronquist
authored
219 -name|--name)
0be3c7e @klacke untabified all of yaws
authored
220 sname=" -name $1 "
221 shift;;
a90bd68 @klacke added kpoll as default
authored
222 --disable-kpoll)
223 kpoll=false;;
28972a3 @klacke run_erl to_erl support patch from Mats Cronquist
authored
224 -heart|--heart)
0be3c7e @klacke untabified all of yaws
authored
225 heart=" -heart ";;
2ba5805 @vinoski add new --heart-restart option to allow control over heart restarts
vinoski authored
226 --heart-restart=*)
227 vals=`echo $arg | sed -e 's/--heart-restart=//'`
228 saveifs="$IFS"
229 IFS=,
230 var='YAWS_HEART_COUNT'
231 for v in $vals; do
232 eval "$var=$v"
233 var='YAWS_HEART_SECS'
234 done
0e5ebd2 @vinoski improved checking of --heart-restart arguments
vinoski authored
235 num=`expr "$YAWS_HEART_COUNT" : '\([0-9]*\)'`
236 if [ -z "$num" -o "$num" != "$YAWS_HEART_COUNT" ]; then
237 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
238 exit 1
239 fi
0e5ebd2 @vinoski improved checking of --heart-restart arguments
vinoski authored
240 num=`expr "$YAWS_HEART_SECS" : '\([0-9]*\)'`
241 if [ -z "$num" -o "$num" != "$YAWS_HEART_SECS" ]; then
242 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
243 exit 1
244 fi
245 IFS="$saveifs"
246 heart=" -heart ";;
28972a3 @klacke run_erl to_erl support patch from Mats Cronquist
authored
247 -proto_dist|--proto_dist)
0be3c7e @klacke untabified all of yaws
authored
248 pdist=" -proto_dist $1 "
249 shift;;
88355a3 @vinoski * Document the --wait-started option for the yaws script
vinoski authored
250 -setcookie|--setcookie)
251 erlarg="$erlarg -setcookie $1 "
252 shift;;
28972a3 @klacke run_erl to_erl support patch from Mats Cronquist
authored
253 -erlarg|--erlarg)
0be3c7e @klacke untabified all of yaws
authored
254 erlarg="$erlarg $1 "
255 shift;;
28972a3 @klacke run_erl to_erl support patch from Mats Cronquist
authored
256 -check|--check)
0be3c7e @klacke untabified all of yaws
authored
257 mkdir ${HOME}/.yaws/ 2> /dev/null
258 mkdir ${HOME}/.yaws/${ID} 2> /dev/null
259 out=`exec $erl -noshell -pa ${yawsdir}${delim}ebin ${xpath} -s yaws_ctl check ${id} $*`
260 if [ "$?" = "0" ]; then
261 echo "$out"
262 echo "$1" ok
263 exit 0
264 fi
265 echo "$out"
266 exit 1;;
28972a3 @klacke run_erl to_erl support patch from Mats Cronquist
authored
267 --to_erl)
0be3c7e @klacke untabified all of yaws
authored
268 TO_ERL=yes
269 PIPE_DIR="${vardir}/run/yaws/pipe/$1"
270 shift;;
28972a3 @klacke run_erl to_erl support patch from Mats Cronquist
authored
271 --run_erl)
0be3c7e @klacke untabified all of yaws
authored
272 RUN_ERL=yes
273 daemon=""
274 PIPE_DIR="${vardir}/run/yaws/pipe/$1"
275 LOG_DIR="${vardir}/log/yaws/erlang-log/$1"
276 shift;;
28972a3 @klacke run_erl to_erl support patch from Mats Cronquist
authored
277 *)
0be3c7e @klacke untabified all of yaws
authored
278 help
28972a3 @klacke run_erl to_erl support patch from Mats Cronquist
authored
279 esac
21abc5b @klacke Initial revision
authored
280 done
2ba5805 @vinoski add new --heart-restart option to allow control over heart restarts
vinoski authored
281 YAWS_HEART_COUNT=${YAWS_HEART_COUNT:-5}
282 YAWS_HEART_SECS=${YAWS_HEART_SECS:-60}
283 export YAWS_HEART_COUNT YAWS_HEART_SECS
21abc5b @klacke Initial revision
authored
284
88355a3 @vinoski * Document the --wait-started option for the yaws script
vinoski authored
285 [ -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 suppo...
authored
286
287 if [ ! -z "${ex}" ]; then
288 exec ${ex} ${id}
289 exit 0
290 fi
291
28972a3 @klacke run_erl to_erl support patch from Mats Cronquist
authored
292 if [ -n "$TO_ERL" ]; then
293 $to_erl $PIPE_DIR/
294 exit 0
295 fi
296
297 if [ -n "$RUN_ERL" ]; then
298 if [ ! -d $LOG_DIR ]; then
0be3c7e @klacke untabified all of yaws
authored
299 mkdir -p $LOG_DIR
28972a3 @klacke run_erl to_erl support patch from Mats Cronquist
authored
300 fi
301 if [ ! -d $PIPE_DIR ]; then
0be3c7e @klacke untabified all of yaws
authored
302 mkdir -p $PIPE_DIR
28972a3 @klacke run_erl to_erl support patch from Mats Cronquist
authored
303 fi
304 RUN_ERL="$run_erl -daemon $PIPE_DIR/ $LOG_DIR"
305 else
306 RUN_ERL="eval"
307 fi
308
92bafb4 @klacke removed the ability change userid, also stopped writing to /tmp/yaws and...
authored
309 if [ ! -z "${id}" ]; then
310 id="-yaws id ${id}"
311 fi
dc00e52 @klacke postvar bug by hal snyder, added yaws_api:query_url/1 added the id suppo...
authored
312
82d6e29 @klacke added -x flag for tty trace and did the 1.3 release
authored
313 trace="${trace} ${traceoutput}"
314
28972a3 @klacke run_erl to_erl support patch from Mats Cronquist
authored
315 [ "$run_erl" = "eval" ] && [ -z "$daemon" ] && [ -z "$interactive" ] && help
316
a90bd68 @klacke added kpoll as default
authored
317 XEC="${daemon} ${heart} +K ${kpoll} -pa ${yawsdir}${delim}ebin ${xpath} ${sname} ${pdist} ${erlarg} ${debug} -run yaws ${trace} ${conf} ${runmod} ${mnesia} ${id}"
38fb85e @klacke ""
authored
318
f22e6e8 Fixed heart bug
Johan Bevemyr authored
319 if [ -z "$heart" ] || [ -z "$daemon" ]; then
6949c22 @vinoski set HEART_COMMAND to allow a maximum of 5 restarts within any 60 second ...
vinoski authored
320 unset HEART_COMMAND
844fe5a Added support for the '-heart' switch.
Tobbe Tornquist authored
321 fi
322
28972a3 @klacke run_erl to_erl support patch from Mats Cronquist
authored
323 ${RUN_ERL} "exec $erl $XEC"
Something went wrong with that request. Please try again.