Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100755 707 lines (616 sloc) 19.516 kB
a3fd023 new preflight repo
Steve Conover authored
1 #!/bin/sh
2
3 # chkconfig: 3 99 99
4 # description: Finance Jetty 6 webserver
5 # processname: finance-jetty
6
7 THIS_DIR=$(dirname $0)
2c3ee0a create a preflight settings class so we can reuse defaults and such, …
Steve Conover & Shawn Morel authored
8 WEB_ROOT=<%=@settings.app_root%>
a3fd023 new preflight repo
Steve Conover authored
9
2c3ee0a create a preflight settings class so we can reuse defaults and such, …
Steve Conover & Shawn Morel authored
10 JAVA_OPTIONS="<%=@settings.java_options%>"
11 JETTY_HOME=<%=@settings.app_root%>/vendor/jetty
6755bef jetty pid is available through settings
Steve Conover & Shawn Morel authored
12 JETTY_RUN=<%=File.dirname(@settings.jetty_pid_path)%>
a3fd023 new preflight repo
Steve Conover authored
13 JETTY_LOGS=$WEB_ROOT/log
14 # Avoid unnecessary su call if we're already the app user
2c3ee0a create a preflight settings class so we can reuse defaults and such, …
Steve Conover & Shawn Morel authored
15 test `whoami` != <%=@settings.app_user%> && JETTY_USER=<%=@settings.app_user%>
a3fd023 new preflight repo
Steve Conover authored
16
d49aa04 optionally specify and environment file in jetpack.yml that the init …
Steve Conover authored
17 <% if @settings.environment %>
18 source <%=@settings.environment%>
19 <% end %>
20
a3fd023 new preflight repo
Steve Conover authored
21 # Startup script for jetty under *nix systems (it works under NT/cygwin too).
22
23 # To get the service to restart correctly on reboot, uncomment below (3 lines):
24 # ========================
25 # chkconfig: 3 99 99
26 # description: Jetty 6 webserver
27 # processname: jetty
28 # ========================
29
30 # Configuration files
31 #
32 # /etc/default/jetty
33ff505 @xaviershay Remove all trailing whitespace.
xaviershay authored
33 # If it exists, this is read at the start of script. It may perform any
a3fd023 new preflight repo
Steve Conover authored
34 # sequence of shell commands, like setting relevant environment variables.
35 #
36 # $HOME/.jettyrc
33ff505 @xaviershay Remove all trailing whitespace.
xaviershay authored
37 # If it exists, this is read at the start of script. It may perform any
a3fd023 new preflight repo
Steve Conover authored
38 # sequence of shell commands, like setting relevant environment variables.
39 #
40 # /etc/jetty.conf
41 # If found, and no configurations were given on the command line,
33ff505 @xaviershay Remove all trailing whitespace.
xaviershay authored
42 # the file will be used as this script's configuration.
a3fd023 new preflight repo
Steve Conover authored
43 # Each line in the file may contain:
44 # - A comment denoted by the pound (#) sign as first non-blank character.
33ff505 @xaviershay Remove all trailing whitespace.
xaviershay authored
45 # - The path to a regular file, which will be passed to jetty as a
a3fd023 new preflight repo
Steve Conover authored
46 # config.xml file.
47 # - The path to a directory. Each *.xml file in the directory will be
48 # passed to jetty as a config.xml file.
49 #
50 # The files will be checked for existence before being passed to jetty.
51 #
52 # $JETTY_HOME/etc/jetty.xml
53 # If found, used as this script's configuration file, but only if
54 # /etc/jetty.conf was not present. See above.
33ff505 @xaviershay Remove all trailing whitespace.
xaviershay authored
55 #
a3fd023 new preflight repo
Steve Conover authored
56 # Configuration variables
57 #
33ff505 @xaviershay Remove all trailing whitespace.
xaviershay authored
58 # JAVA_HOME
59 # Home of Java installation.
a3fd023 new preflight repo
Steve Conover authored
60 #
61 # JAVA
62 # Command to invoke Java. If not set, $JAVA_HOME/bin/java will be
63 # used.
64 #
65 # JAVA_OPTIONS
66 # Extra options to pass to the JVM
67 #
68 # JETTY_HOME
69 # Where Jetty is installed. If not set, the script will try go
70 # guess it by first looking at the invocation path for the script,
71 # and then by looking in standard locations as $HOME/opt/jetty
72 # and /opt/jetty. The java system property "jetty.home" will be
73 # set to this value for use by configure.xml files, f.e.:
74 #
75 # <Arg><SystemProperty name="jetty.home" default="."/>/webapps/jetty.war</Arg>
91ff28c preflight-specific changes to jetty-init script
Steve Conover & Xavier Shay authored
76 #
6b3df3f @xaviershay More renames.
xaviershay authored
77 # !!! JETPACK NOTE: JETTY_PORT IS IGNORED !!!
91ff28c preflight-specific changes to jetty-init script
Steve Conover & Xavier Shay authored
78 # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ JETTY_PORT
a3fd023 new preflight repo
Steve Conover authored
79 # Override the default port for Jetty servers. If not set then the
80 # default value in the xml configuration file will be used. The java
81 # system property "jetty.port" will be set to this value for use in
82 # configure.xml files. For example, the following idiom is widely
83 # used in the demo config files to respect this property in Listener
84 # configuration elements:
85 #
86 # <Set name="Port"><SystemProperty name="jetty.port" default="8080"/></Set>
87 #
88 # Note: that the config file could ignore this property simply by saying:
89 #
90 # <Set name="Port">8080</Set>
91 #
92 # JETTY_RUN
93 # Where the jetty.pid file should be stored. It defaults to the
94 # first available of /var/run, /usr/var/run, and /tmp if not set.
33ff505 @xaviershay Remove all trailing whitespace.
xaviershay authored
95 #
a3fd023 new preflight repo
Steve Conover authored
96 # JETTY_PID
97 # The Jetty PID file, defaults to $JETTY_RUN/jetty.pid
33ff505 @xaviershay Remove all trailing whitespace.
xaviershay authored
98 #
a3fd023 new preflight repo
Steve Conover authored
99 # JETTY_ARGS
100 # The default arguments to pass to jetty.
101 #
102 # JETTY_USER
103 # if set, then used as a username to run the server as
104 #
105 # Set to 0 if you do not want to use start-stop-daemon (especially on SUSE boxes)
106 START_STOP_DAEMON=1
107
108 usage()
109 {
91ff28c preflight-specific changes to jetty-init script
Steve Conover & Xavier Shay authored
110 echo "Usage: $0 {start|stop|run|restart|check|supervise}"
a3fd023 new preflight repo
Steve Conover authored
111 exit 1
112 }
113
114 [ $# -gt 0 ] || usage
115
116
117 ##################################################
118 # Some utility functions
119 ##################################################
120 findDirectory()
121 {
122 OP=$1
123 shift
124 for L in $* ; do
33ff505 @xaviershay Remove all trailing whitespace.
xaviershay authored
125 [ $OP $L ] || continue
a3fd023 new preflight repo
Steve Conover authored
126 echo $L
127 break
33ff505 @xaviershay Remove all trailing whitespace.
xaviershay authored
128 done
a3fd023 new preflight repo
Steve Conover authored
129 }
130
131 running()
132 {
133 [ -f $1 ] || return 1
134 PID=$(cat $1)
135 ps -p $PID >/dev/null 2>/dev/null || return 1
136 return 0
137 }
138
0821c87 @pascallouisperez Moving the RAILS_ENV is set check to start and restart only. When sto…
pascallouisperez authored
139 ensure_rails_env_set()
140 {
141 if [ -z "$RAILS_ENV" ]; then
142 echo "RAILS_ENV not set" 1>&2
143 exit 1
144 fi
145 }
a3fd023 new preflight repo
Steve Conover authored
146
147
148
149
150
151 ##################################################
152 # Get the action & configs
153 ##################################################
154
155 ACTION=$1
156 shift
157 ARGS="$*"
e0a2413 @xaviershay Rename to jetpack.
xaviershay authored
158 # CONFIGS="" -- Not used in jetpack. Rely on start.ini instead.
a3fd023 new preflight repo
Steve Conover authored
159 NO_START=0
160
161 ##################################################
162 # See if there's a default configuration file
163 ##################################################
33ff505 @xaviershay Remove all trailing whitespace.
xaviershay authored
164 if [ -f /etc/default/jetty6 ] ; then
a3fd023 new preflight repo
Steve Conover authored
165 . /etc/default/jetty6
33ff505 @xaviershay Remove all trailing whitespace.
xaviershay authored
166 elif [ -f /etc/default/jetty ] ; then
a3fd023 new preflight repo
Steve Conover authored
167 . /etc/default/jetty
168 fi
169
170
171 ##################################################
172 # See if there's a user-specific configuration file
173 ##################################################
33ff505 @xaviershay Remove all trailing whitespace.
xaviershay authored
174 if [ -f $HOME/.jettyrc ] ; then
a3fd023 new preflight repo
Steve Conover authored
175 . $HOME/.jettyrc
176 fi
177
178 ##################################################
179 # Set tmp if not already set.
180 ##################################################
181
33ff505 @xaviershay Remove all trailing whitespace.
xaviershay authored
182 if [ -z "$TMP" ]
a3fd023 new preflight repo
Steve Conover authored
183 then
184 TMP=/tmp
185 fi
186
187 ##################################################
188 # Jetty's hallmark
189 ##################################################
190 JETTY_INSTALL_TRACE_FILE="etc/jetty.xml"
191 TMPJ=$TMP/j$$
192
193
194 ##################################################
195 # Try to determine JETTY_HOME if not set
196 ##################################################
33ff505 @xaviershay Remove all trailing whitespace.
xaviershay authored
197 if [ -z "$JETTY_HOME" ]
a3fd023 new preflight repo
Steve Conover authored
198 then
199 JETTY_HOME_1=`dirname "$0"`
200 JETTY_HOME_1=`dirname "$JETTY_HOME_1"`
33ff505 @xaviershay Remove all trailing whitespace.
xaviershay authored
201 if [ -f "${JETTY_HOME_1}/${JETTY_INSTALL_TRACE_FILE}" ] ;
202 then
203 JETTY_HOME=${JETTY_HOME_1}
a3fd023 new preflight repo
Steve Conover authored
204 fi
205 fi
206
207
208 ##################################################
209 # if no JETTY_HOME, search likely locations.
210 ##################################################
211 if [ "$JETTY_HOME" = "" ] ; then
212 STANDARD_LOCATIONS=" \
213 /usr/share \
214 /usr/share/java \
215 $HOME \
216 $HOME/src \
217 ${HOME}/opt/ \
218 /opt \
219 /java \
220 /usr/local \
221 /usr/local/share \
222 /usr/local/share/java \
223 /home \
224 "
225 JETTY_DIR_NAMES=" \
226 jetty-6 \
227 jetty6 \
228 jetty-6.* \
229 jetty \
230 Jetty-6 \
231 Jetty6 \
232 Jetty-6.* \
233 Jetty \
234 "
33ff505 @xaviershay Remove all trailing whitespace.
xaviershay authored
235
a3fd023 new preflight repo
Steve Conover authored
236 JETTY_HOME=
33ff505 @xaviershay Remove all trailing whitespace.
xaviershay authored
237 for L in $STANDARD_LOCATIONS
a3fd023 new preflight repo
Steve Conover authored
238 do
33ff505 @xaviershay Remove all trailing whitespace.
xaviershay authored
239 for N in $JETTY_DIR_NAMES
a3fd023 new preflight repo
Steve Conover authored
240 do
33ff505 @xaviershay Remove all trailing whitespace.
xaviershay authored
241 if [ -d $L/$N ] && [ -f "$L/${N}/${JETTY_INSTALL_TRACE_FILE}" ] ;
242 then
a3fd023 new preflight repo
Steve Conover authored
243 JETTY_HOME="$L/$N"
244 fi
245 done
246 [ ! -z "$JETTY_HOME" ] && break
247 done
248 fi
249
250
251 ##################################################
252 # No JETTY_HOME yet? We're out of luck!
253 ##################################################
254 if [ -z "$JETTY_HOME" ] ; then
33ff505 @xaviershay Remove all trailing whitespace.
xaviershay authored
255 echo "** ERROR: JETTY_HOME not set, you need to set it or install in a standard location"
a3fd023 new preflight repo
Steve Conover authored
256 exit 1
257 fi
258
259 cd $JETTY_HOME
260 JETTY_HOME=`pwd`
261
262
263 #####################################################
264 # Check that jetty is where we think it is
265 #####################################################
33ff505 @xaviershay Remove all trailing whitespace.
xaviershay authored
266 if [ ! -r $JETTY_HOME/$JETTY_INSTALL_TRACE_FILE ]
a3fd023 new preflight repo
Steve Conover authored
267 then
268 echo "** ERROR: Oops! Jetty doesn't appear to be installed in $JETTY_HOME"
269 echo "** ERROR: $JETTY_HOME/$JETTY_INSTALL_TRACE_FILE is not readable!"
270 exit 1
271 fi
272
e0a2413 @xaviershay Rename to jetpack.
xaviershay authored
273 # !!!!!!! Not used in jetpack. Rely on start.ini instead. !!!!!!!!!!
a3fd023 new preflight repo
Steve Conover authored
274 ###########################################################
275 # Get the list of config.xml files from the command line.
276 ###########################################################
91ff28c preflight-specific changes to jetty-init script
Steve Conover & Xavier Shay authored
277 #if [ ! -z "$ARGS" ]
278 #then
279 # for A in $ARGS
280 # do
281 # if [ -f $A ]
282 # then
283 # CONF="$A"
284 # elif [ -f $JETTY_HOME/etc/$A ]
285 # then
286 # CONF="$JETTY_HOME/etc/$A"
287 # elif [ -f ${A}.xml ]
288 # then
289 # CONF="${A}.xml"
290 # elif [ -f $JETTY_HOME/etc/${A}.xml ]
291 # then
292 # CONF="$JETTY_HOME/etc/${A}.xml"
293 # else
294 # echo "** ERROR: Cannot find configuration '$A' specified in the command line."
295 # exit 1
296 # fi
297 # if [ ! -r $CONF ]
298 # then
299 # echo "** ERROR: Cannot read configuration '$A' specified in the command line."
300 # exit 1
301 # fi
302 # CONFIGS="$CONFIGS $CONF"
303 # done
304 #fi
a3fd023 new preflight repo
Steve Conover authored
305
306
307 ##################################################
308 # Try to find this script's configuration file,
309 # but only if no configurations were given on the
310 # command line.
311 ##################################################
33ff505 @xaviershay Remove all trailing whitespace.
xaviershay authored
312 if [ -z "$JETTY_CONF" ]
a3fd023 new preflight repo
Steve Conover authored
313 then
314 if [ -f /etc/jetty.conf ]
315 then
316 JETTY_CONF=/etc/jetty.conf
317 elif [ -f "${JETTY_HOME}/etc/jetty.conf" ]
318 then
319 JETTY_CONF="${JETTY_HOME}/etc/jetty.conf"
320 fi
321 fi
322
e0a2413 @xaviershay Rename to jetpack.
xaviershay authored
323 # -- Not used in jetpack. Rely on start.ini instead.
a3fd023 new preflight repo
Steve Conover authored
324 ##################################################
325 # Read the configuration file if one exists
326 ##################################################
91ff28c preflight-specific changes to jetty-init script
Steve Conover & Xavier Shay authored
327 #CONFIG_LINES=
328 #if [ -z "$CONFIGS" ] && [ -f "$JETTY_CONF" ] && [ -r "$JETTY_CONF" ]
329 #then
330 # CONFIG_LINES=`cat $JETTY_CONF | grep -v "^[:space:]*#" | tr "\n" " "`
331 #fi
a3fd023 new preflight repo
Steve Conover authored
332
333 ##################################################
334 # Get the list of config.xml files from jetty.conf
335 ##################################################
91ff28c preflight-specific changes to jetty-init script
Steve Conover & Xavier Shay authored
336 #if [ ! -z "${CONFIG_LINES}" ]
337 #then
338 # for CONF in ${CONFIG_LINES}
339 # do
340 # if [ ! -r "$CONF" ]
341 # then
342 # echo "** WARNING: Cannot read '$CONF' specified in '$JETTY_CONF'"
343 # elif [ -f "$CONF" ]
344 # then
345 # # assume it's a configure.xml file
346 # CONFIGS="$CONFIGS $CONF"
347 # elif [ -d "$CONF" ]
348 # then
349 # # assume it's a directory with configure.xml files
350 # # for example: /etc/jetty.d/
351 # # sort the files before adding them to the list of CONFIGS
352 # XML_FILES=`ls ${CONF}/*.xml | sort | tr "\n" " "`
353 # for FILE in ${XML_FILES}
354 # do
355 # if [ -r "$FILE" ] && [ -f "$FILE" ]
356 # then
357 # CONFIGS="$CONFIGS $FILE"
358 # else
359 # echo "** WARNING: Cannot read '$FILE' specified in '$JETTY_CONF'"
360 # fi
361 # done
362 # else
363 # echo "** WARNING: Don''t know what to do with '$CONF' specified in '$JETTY_CONF'"
364 # fi
365 # done
366 #fi
a3fd023 new preflight repo
Steve Conover authored
367
368 #####################################################
369 # Run the standard server if there's nothing else to run
370 #####################################################
91ff28c preflight-specific changes to jetty-init script
Steve Conover & Xavier Shay authored
371 #if [ -z "$CONFIGS" ]
372 #then
373 # CONFIGS="${JETTY_HOME}/etc/jetty.xml"
374 #fi
a3fd023 new preflight repo
Steve Conover authored
375
376
377 #####################################################
378 # Find a location for the pid file
379 #####################################################
33ff505 @xaviershay Remove all trailing whitespace.
xaviershay authored
380 if [ -z "$JETTY_RUN" ]
a3fd023 new preflight repo
Steve Conover authored
381 then
382 JETTY_RUN=`findDirectory -w /var/run /usr/var/run /tmp`
383 fi
384
385 #####################################################
386 # Find a PID for the pid file
387 #####################################################
33ff505 @xaviershay Remove all trailing whitespace.
xaviershay authored
388 if [ -z "$JETTY_PID" ]
a3fd023 new preflight repo
Steve Conover authored
389 then
390 JETTY_PID="$JETTY_RUN/jetty.pid"
391 fi
392
393
394 ##################################################
395 # Check for JAVA_HOME
396 ##################################################
397 if [ -z "$JAVA_HOME" ]
398 then
399 # If a java runtime is not defined, search the following
400 # directories for a JVM and sort by version. Use the highest
401 # version number.
402
403 # Java search path
404 JAVA_LOCATIONS="\
405 /usr/java \
406 /usr/bin \
407 /usr/local/bin \
408 /usr/local/java \
409 /usr/local/jdk \
410 /usr/local/jre \
411 /usr/lib/jvm \
412 /opt/java \
413 /opt/jdk \
414 /opt/jre \
33ff505 @xaviershay Remove all trailing whitespace.
xaviershay authored
415 "
a3fd023 new preflight repo
Steve Conover authored
416 JAVA_NAMES="java jdk jre"
417 for N in $JAVA_NAMES ; do
418 for L in $JAVA_LOCATIONS ; do
33ff505 @xaviershay Remove all trailing whitespace.
xaviershay authored
419 [ -d $L ] || continue
a3fd023 new preflight repo
Steve Conover authored
420 find $L -name "$N" ! -type d | grep -v threads | while read J ; do
421 [ -x $J ] || continue
33ff505 @xaviershay Remove all trailing whitespace.
xaviershay authored
422 VERSION=`eval $J -version 2>&1`
a3fd023 new preflight repo
Steve Conover authored
423 [ $? = 0 ] || continue
424 VERSION=`expr "$VERSION" : '.*"\(1.[0-9\.]*\)["_]'`
425 [ "$VERSION" = "" ] && continue
426 expr $VERSION \< 1.2 >/dev/null && continue
427 echo $VERSION:$J
428 done
429 done
430 done | sort | tail -1 > $TMPJ
431 JAVA=`cat $TMPJ | cut -d: -f2`
432 JVERSION=`cat $TMPJ | cut -d: -f1`
433
434 JAVA_HOME=`dirname $JAVA`
435 while [ ! -z "$JAVA_HOME" -a "$JAVA_HOME" != "/" -a ! -f "$JAVA_HOME/lib/tools.jar" ] ; do
436 JAVA_HOME=`dirname $JAVA_HOME`
437 done
438 [ "$JAVA_HOME" = "" ] && JAVA_HOME=
439
440 echo "Found JAVA=$JAVA in JAVA_HOME=$JAVA_HOME"
441 fi
442
443
444 ##################################################
445 # Determine which JVM of version >1.2
446 # Try to use JAVA_HOME
447 ##################################################
448 if [ "$JAVA" = "" -a "$JAVA_HOME" != "" ]
449 then
33ff505 @xaviershay Remove all trailing whitespace.
xaviershay authored
450 if [ ! -z "$JAVACMD" ]
a3fd023 new preflight repo
Steve Conover authored
451 then
33ff505 @xaviershay Remove all trailing whitespace.
xaviershay authored
452 JAVA="$JAVACMD"
a3fd023 new preflight repo
Steve Conover authored
453 else
454 [ -x $JAVA_HOME/bin/jre -a ! -d $JAVA_HOME/bin/jre ] && JAVA=$JAVA_HOME/bin/jre
455 [ -x $JAVA_HOME/bin/java -a ! -d $JAVA_HOME/bin/java ] && JAVA=$JAVA_HOME/bin/java
456 fi
457 fi
458
459 if [ "$JAVA" = "" ]
460 then
461 echo "Cannot find a JRE or JDK. Please set JAVA_HOME to a >=1.2 JRE" 2>&2
462 exit 1
463 fi
464
465 JAVA_VERSION=`expr "$($JAVA -version 2>&1 | head -1)" : '.*1\.\([0-9]\)'`
466
467 #####################################################
468 # See if JETTY_PORT is defined
469 #####################################################
91ff28c preflight-specific changes to jetty-init script
Steve Conover & Xavier Shay authored
470 #
6b3df3f @xaviershay More renames.
xaviershay authored
471 # JETPACK NOTE:
91ff28c preflight-specific changes to jetty-init script
Steve Conover & Xavier Shay authored
472 # We do not allow the init script to set jetty.port
e0a2413 @xaviershay Rename to jetpack.
xaviershay authored
473 # when using jetpack, as jetpack sets this via
91ff28c preflight-specific changes to jetty-init script
Steve Conover & Xavier Shay authored
474 # jetty.xml, and setting port in both places causes
475 # jetty to attempt to bind to the same port.
476 #
477 #if [ "$JETTY_PORT" != "" ]
478 #then
479 # JAVA_OPTIONS="$JAVA_OPTIONS -Djetty.port=$JETTY_PORT"
480 #fi
a3fd023 new preflight repo
Steve Conover authored
481
482 #####################################################
483 # See if JETTY_LOGS is defined
484 #####################################################
485 if [ "$JETTY_LOGS" != "" ]
486 then
487 JAVA_OPTIONS="$JAVA_OPTIONS -Djetty.logs=$JETTY_LOGS"
488 fi
489
490 #####################################################
491 # Are we running on Windows? Could be, with Cygwin/NT.
492 #####################################################
493 case "`uname`" in
494 CYGWIN*) PATH_SEPARATOR=";";;
495 *) PATH_SEPARATOR=":";;
496 esac
497
498
499 #####################################################
500 # Add jetty properties to Java VM options.
501 #####################################################
502 JAVA_OPTIONS="$JAVA_OPTIONS -Djetty.home=$JETTY_HOME -Djava.io.tmpdir=$TMP"
503
504 [ -f $JETTY_HOME/etc/start.config ] && JAVA_OPTIONS="-DSTART=$JETTY_HOME/etc/start.config $JAVA_OPTIONS"
505
506 #####################################################
507 # This is how the Jetty server will be started
508 #####################################################
509
510 JETTY_START=$JETTY_HOME/start.jar
511 [ ! -f $JETTY_START ] && JETTY_START=$JETTY_HOME/lib/start.jar
512
91ff28c preflight-specific changes to jetty-init script
Steve Conover & Xavier Shay authored
513 RUN_ARGS="$JAVA_OPTIONS -jar $JETTY_START $JETTY_ARGS"
a3fd023 new preflight repo
Steve Conover authored
514 RUN_CMD="$JAVA $RUN_ARGS"
515
516 #####################################################
33ff505 @xaviershay Remove all trailing whitespace.
xaviershay authored
517 # Comment these out after you're happy with what
a3fd023 new preflight repo
Steve Conover authored
518 # the script is doing.
519 #####################################################
520 #echo "JETTY_HOME = $JETTY_HOME"
521 #echo "JETTY_CONF = $JETTY_CONF"
522 #echo "JETTY_RUN = $JETTY_RUN"
523 #echo "JETTY_PID = $JETTY_PID"
524 #echo "JETTY_ARGS = $JETTY_ARGS"
525 #echo "CONFIGS = $CONFIGS"
526 #echo "JAVA_OPTIONS = $JAVA_OPTIONS"
527 #echo "JAVA = $JAVA"
528
529
530 ##################################################
531 # Do the action
532 ##################################################
533 case "$ACTION" in
534 start)
0821c87 @pascallouisperez Moving the RAILS_ENV is set check to start and restart only. When sto…
pascallouisperez authored
535 ensure_rails_env_set
536 echo -n "Starting Jetty: "
a3fd023 new preflight repo
Steve Conover authored
537
33ff505 @xaviershay Remove all trailing whitespace.
xaviershay authored
538 if [ "$NO_START" = "1" ]; then
a3fd023 new preflight repo
Steve Conover authored
539 echo "Not starting jetty - NO_START=1 in /etc/default/jetty6";
0821c87 @pascallouisperez Moving the RAILS_ENV is set check to start and restart only. When sto…
pascallouisperez authored
540 exit 0;
a3fd023 new preflight repo
Steve Conover authored
541 fi
542
543
544 if [ "$START_STOP_DAEMON" = "1" ] && type start-stop-daemon > /dev/null 2>&1
545 then
546 [ x$JETTY_USER = x ] && JETTY_USER=$(whoami)
547 [ $UID = 0 ] && CH_USER="-c $JETTY_USER"
33ff505 @xaviershay Remove all trailing whitespace.
xaviershay authored
548 if start-stop-daemon -S -p$JETTY_PID $CH_USER -d $JETTY_HOME -b -m -a $JAVA -- $RUN_ARGS
a3fd023 new preflight repo
Steve Conover authored
549 then
550 sleep 1
551 if running $JETTY_PID
552 then
553 echo OK
554 else
555 echo FAILED
556 fi
557 fi
558
559 else
560
561 if [ -f $JETTY_PID ]
33ff505 @xaviershay Remove all trailing whitespace.
xaviershay authored
562 then
a3fd023 new preflight repo
Steve Conover authored
563 if running $JETTY_PID
564 then
565 echo "Already Running!!"
566 exit 1
567 else
568 # dead pid file - remove
569 rm -f $JETTY_PID
570 fi
571 fi
572
33ff505 @xaviershay Remove all trailing whitespace.
xaviershay authored
573 if [ x$JETTY_USER != x ]
a3fd023 new preflight repo
Steve Conover authored
574 then
575 touch $JETTY_PID
576 chown $JETTY_USER $JETTY_PID
577 su - $JETTY_USER -c "
578 $RUN_CMD &
579 PID=\$!
580 disown \$PID
581 echo \$PID > $JETTY_PID"
582 else
583 $RUN_CMD &
584 PID=$!
585 disown $PID
586 echo $PID > $JETTY_PID
587 fi
588
33ff505 @xaviershay Remove all trailing whitespace.
xaviershay authored
589 echo "STARTED Jetty `date`"
a3fd023 new preflight repo
Steve Conover authored
590 fi
591
592 ;;
593
594 stop)
595 echo -n "Stopping Jetty: "
596 if [ "$START_STOP_DAEMON" = "1" ] && type start-stop-daemon > /dev/null 2>&1; then
33ff505 @xaviershay Remove all trailing whitespace.
xaviershay authored
597 start-stop-daemon -K -p $JETTY_PID -d $JETTY_HOME -a $JAVA -s HUP
a3fd023 new preflight repo
Steve Conover authored
598 sleep 1
599 if running $JETTY_PID
600 then
601 sleep 3
602 if running $JETTY_PID
603 then
604 sleep 30
605 if running $JETTY_PID
606 then
607 start-stop-daemon -K -p $JETTY_PID -d $JETTY_HOME -a $JAVA -s KILL
608 fi
609 fi
610 fi
611
612 rm -f $JETTY_PID
613 echo OK
614 else
615 PID=`cat $JETTY_PID 2>/dev/null`
616 TIMEOUT=30
617 while running $JETTY_PID && [ $TIMEOUT -gt 0 ]
618 do
619 kill $PID 2>/dev/null
620 sleep 1
621 let TIMEOUT=$TIMEOUT-1
622 done
33ff505 @xaviershay Remove all trailing whitespace.
xaviershay authored
623
a3fd023 new preflight repo
Steve Conover authored
624 [ $TIMEOUT -gt 0 ] || kill -9 $PID 2>/dev/null
625
626 rm -f $JETTY_PID
627 echo OK
628 fi
629 ;;
630
631 restart)
0821c87 @pascallouisperez Moving the RAILS_ENV is set check to start and restart only. When sto…
pascallouisperez authored
632 ensure_rails_env_set
a3fd023 new preflight repo
Steve Conover authored
633 JETTY_SH=$0
634 if [ ! -f $JETTY_SH ]; then
635 if [ ! -f $JETTY_HOME/bin/jetty.sh ]; then
636 echo "$JETTY_HOME/bin/jetty.sh does not exist."
637 exit 1
638 fi
639 JETTY_SH=$JETTY_HOME/bin/jetty.sh
640 fi
641 $JETTY_SH stop $*
642 sleep 5
643 $JETTY_SH start $*
644 ;;
645
646 supervise)
647 #
648 # Under control of daemontools supervise monitor which
649 # handles restarts and shutdowns via the svc program.
650 #
651 exec $RUN_CMD
652 ;;
653
654 run|demo)
655 echo "Running Jetty: "
656
657 if [ -f $JETTY_PID ]
658 then
659 if running $JETTY_PID
660 then
661 echo "Already Running!!"
662 exit 1
663 else
664 # dead pid file - remove
665 rm -f $JETTY_PID
666 fi
667 fi
668
669 exec $RUN_CMD
670 ;;
671
672 check)
673 echo "Checking arguments to Jetty: "
674 echo "JETTY_HOME = $JETTY_HOME"
675 echo "JETTY_CONF = $JETTY_CONF"
6148bbc Replacing HTTP connector by HTTPS connector.
Tyler Kovacs + Steve Conover authored
676 echo "JETTY_ARGS = $JETTY_ARGS"
a3fd023 new preflight repo
Steve Conover authored
677 echo "JETTY_RUN = $JETTY_RUN"
678 echo "JETTY_PID = $JETTY_PID"
e0a2413 @xaviershay Rename to jetpack.
xaviershay authored
679 #echo "JETTY_PORT = $JETTY_PORT" JETTY_PORT is not used with jetpack, see note elsewhere in this file.
a3fd023 new preflight repo
Steve Conover authored
680 echo "JETTY_LOGS = $JETTY_LOGS"
e0a2413 @xaviershay Rename to jetpack.
xaviershay authored
681 #echo "CONFIGS = $CONFIGS" -- Not used with jetpack. Rely on start.ini instead.
6148bbc Replacing HTTP connector by HTTPS connector.
Tyler Kovacs + Steve Conover authored
682 echo "RAILS_ENV = $RAILS_ENV"
a3fd023 new preflight repo
Steve Conover authored
683 echo "JAVA_OPTIONS = $JAVA_OPTIONS"
684 echo "JAVA = $JAVA"
685 echo "CLASSPATH = $CLASSPATH"
686 echo "RUN_CMD = $RUN_CMD"
687 echo
33ff505 @xaviershay Remove all trailing whitespace.
xaviershay authored
688
a3fd023 new preflight repo
Steve Conover authored
689 if [ -f $JETTY_RUN/jetty.pid ]
690 then
691 echo "Jetty running pid="`cat $JETTY_RUN/jetty.pid`
692 exit 0
693 fi
694 exit 1
695 ;;
696
697 *)
698 usage
699 ;;
700 esac
701
702 exit 0
703
704
705
706
Something went wrong with that request. Please try again.