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