jetpack 0.0.3

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