trinidad_init_services 1.2.3 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,38 +1,31 @@
1
1
  #! /bin/sh
2
2
  # Configuration validation subroutine script.
3
- # Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
4
- # 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010,
5
- # 2011 Free Software Foundation, Inc.
3
+ # Copyright 1992-2013 Free Software Foundation, Inc.
6
4
 
7
- timestamp='2011-03-23'
5
+ timestamp='2013-02-04'
8
6
 
9
- # This file is (in principle) common to ALL GNU software.
10
- # The presence of a machine in this file suggests that SOME GNU software
11
- # can handle that machine. It does not imply ALL GNU software can.
12
- #
13
- # This file is free software; you can redistribute it and/or modify
14
- # it under the terms of the GNU General Public License as published by
15
- # the Free Software Foundation; either version 2 of the License, or
7
+ # This file is free software; you can redistribute it and/or modify it
8
+ # under the terms of the GNU General Public License as published by
9
+ # the Free Software Foundation; either version 3 of the License, or
16
10
  # (at your option) any later version.
17
11
  #
18
- # This program is distributed in the hope that it will be useful,
19
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
20
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21
- # GNU General Public License for more details.
12
+ # This program is distributed in the hope that it will be useful, but
13
+ # WITHOUT ANY WARRANTY; without even the implied warranty of
14
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15
+ # General Public License for more details.
22
16
  #
23
17
  # You should have received a copy of the GNU General Public License
24
- # along with this program; if not, write to the Free Software
25
- # Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA
26
- # 02110-1301, USA.
18
+ # along with this program; if not, see <http://www.gnu.org/licenses/>.
27
19
  #
28
20
  # As a special exception to the GNU General Public License, if you
29
21
  # distribute this file as part of a program that contains a
30
22
  # configuration script generated by Autoconf, you may include it under
31
- # the same distribution terms that you use for the rest of that program.
23
+ # the same distribution terms that you use for the rest of that
24
+ # program. This Exception is an additional permission under section 7
25
+ # of the GNU General Public License, version 3 ("GPLv3").
32
26
 
33
27
 
34
- # Please send patches to <config-patches@gnu.org>. Submit a context
35
- # diff and a properly formatted GNU ChangeLog entry.
28
+ # Please send patches with a ChangeLog entry to config-patches@gnu.org.
36
29
  #
37
30
  # Configuration subroutine to validate and canonicalize a configuration type.
38
31
  # Supply the specified configuration type as an argument.
@@ -75,9 +68,7 @@ Report bugs and patches to <config-patches@gnu.org>."
75
68
  version="\
76
69
  GNU config.sub ($timestamp)
77
70
 
78
- Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000,
79
- 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Free
80
- Software Foundation, Inc.
71
+ Copyright 1992-2013 Free Software Foundation, Inc.
81
72
 
82
73
  This is free software; see the source for copying conditions. There is NO
83
74
  warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE."
@@ -125,13 +116,17 @@ esac
125
116
  maybe_os=`echo $1 | sed 's/^\(.*\)-\([^-]*-[^-]*\)$/\2/'`
126
117
  case $maybe_os in
127
118
  nto-qnx* | linux-gnu* | linux-android* | linux-dietlibc | linux-newlib* | \
128
- linux-uclibc* | uclinux-uclibc* | uclinux-gnu* | kfreebsd*-gnu* | \
119
+ linux-musl* | linux-uclibc* | uclinux-uclibc* | uclinux-gnu* | kfreebsd*-gnu* | \
129
120
  knetbsd*-gnu* | netbsd*-gnu* | \
130
121
  kopensolaris*-gnu* | \
131
122
  storm-chaos* | os2-emx* | rtmk-nova*)
132
123
  os=-$maybe_os
133
124
  basic_machine=`echo $1 | sed 's/^\(.*\)-\([^-]*-[^-]*\)$/\1/'`
134
125
  ;;
126
+ android-linux)
127
+ os=-linux-android
128
+ basic_machine=`echo $1 | sed 's/^\(.*\)-\([^-]*-[^-]*\)$/\1/'`-unknown
129
+ ;;
135
130
  *)
136
131
  basic_machine=`echo $1 | sed 's/-[^-]*$//'`
137
132
  if [ $basic_machine != $1 ]
@@ -154,7 +149,7 @@ case $os in
154
149
  -convergent* | -ncr* | -news | -32* | -3600* | -3100* | -hitachi* |\
155
150
  -c[123]* | -convex* | -sun | -crds | -omron* | -dg | -ultra | -tti* | \
156
151
  -harris | -dolphin | -highlevel | -gould | -cbm | -ns | -masscomp | \
157
- -apple | -axis | -knuth | -cray | -microblaze)
152
+ -apple | -axis | -knuth | -cray | -microblaze*)
158
153
  os=
159
154
  basic_machine=$1
160
155
  ;;
@@ -223,6 +218,12 @@ case $os in
223
218
  -isc*)
224
219
  basic_machine=`echo $1 | sed -e 's/86-.*/86-pc/'`
225
220
  ;;
221
+ -lynx*178)
222
+ os=-lynxos178
223
+ ;;
224
+ -lynx*5)
225
+ os=-lynxos5
226
+ ;;
226
227
  -lynx*)
227
228
  os=-lynxos
228
229
  ;;
@@ -247,20 +248,27 @@ case $basic_machine in
247
248
  # Some are omitted here because they have special meanings below.
248
249
  1750a | 580 \
249
250
  | a29k \
251
+ | aarch64 | aarch64_be \
250
252
  | alpha | alphaev[4-8] | alphaev56 | alphaev6[78] | alphapca5[67] \
251
253
  | alpha64 | alpha64ev[4-8] | alpha64ev56 | alpha64ev6[78] | alpha64pca5[67] \
252
254
  | am33_2.0 \
253
- | arc | arm | arm[bl]e | arme[lb] | armv[2345] | armv[345][lb] | avr | avr32 \
255
+ | arc \
256
+ | arm | arm[bl]e | arme[lb] | armv[2-8] | armv[3-8][lb] | armv7[arm] \
257
+ | avr | avr32 \
258
+ | be32 | be64 \
254
259
  | bfin \
255
260
  | c4x | clipper \
256
261
  | d10v | d30v | dlx | dsp16xx \
262
+ | epiphany \
257
263
  | fido | fr30 | frv \
258
264
  | h8300 | h8500 | hppa | hppa1.[01] | hppa2.0 | hppa2.0[nw] | hppa64 \
265
+ | hexagon \
259
266
  | i370 | i860 | i960 | ia64 | ia64[nw] \
260
267
  | ip2k | iq2000 \
268
+ | le32 | le64 \
261
269
  | lm32 \
262
270
  | m32c | m32r | m32rle | m68000 | m68k | m88k \
263
- | maxq | mb | microblaze | mcore | mep | metag \
271
+ | maxq | mb | microblaze | microblazeel | mcore | mep | metag \
264
272
  | mips | mipsbe | mipseb | mipsel | mipsle \
265
273
  | mips16 \
266
274
  | mips64 | mips64el \
@@ -278,20 +286,21 @@ case $basic_machine in
278
286
  | mipsisa64r2 | mipsisa64r2el \
279
287
  | mipsisa64sb1 | mipsisa64sb1el \
280
288
  | mipsisa64sr71k | mipsisa64sr71kel \
289
+ | mipsr5900 | mipsr5900el \
281
290
  | mipstx39 | mipstx39el \
282
291
  | mn10200 | mn10300 \
283
292
  | moxie \
284
293
  | mt \
285
294
  | msp430 \
286
295
  | nds32 | nds32le | nds32be \
287
- | nios | nios2 \
296
+ | nios | nios2 | nios2eb | nios2el \
288
297
  | ns16k | ns32k \
289
298
  | open8 \
290
299
  | or32 \
291
300
  | pdp10 | pdp11 | pj | pjl \
292
301
  | powerpc | powerpc64 | powerpc64le | powerpcle \
293
302
  | pyramid \
294
- | rx \
303
+ | rl78 | rx \
295
304
  | score \
296
305
  | sh | sh[1234] | sh[24]a | sh[24]aeb | sh[23]e | sh[34]eb | sheb | shbe | shle | sh[1234]le | sh3ele \
297
306
  | sh64 | sh64le \
@@ -300,7 +309,7 @@ case $basic_machine in
300
309
  | spu \
301
310
  | tahoe | tic4x | tic54x | tic55x | tic6x | tic80 | tron \
302
311
  | ubicom32 \
303
- | v850 | v850e \
312
+ | v850 | v850e | v850e1 | v850e2 | v850es | v850e2v3 \
304
313
  | we32k \
305
314
  | x86 | xc16x | xstormy16 | xtensa \
306
315
  | z8k | z80)
@@ -315,8 +324,7 @@ case $basic_machine in
315
324
  c6x)
316
325
  basic_machine=tic6x-unknown
317
326
  ;;
318
- m6811 | m68hc11 | m6812 | m68hc12 | picochip)
319
- # Motorola 68HC11/12.
327
+ m6811 | m68hc11 | m6812 | m68hc12 | m68hcs12x | picochip)
320
328
  basic_machine=$basic_machine-unknown
321
329
  os=-none
322
330
  ;;
@@ -329,7 +337,10 @@ case $basic_machine in
329
337
  strongarm | thumb | xscale)
330
338
  basic_machine=arm-unknown
331
339
  ;;
332
-
340
+ xgate)
341
+ basic_machine=$basic_machine-unknown
342
+ os=-none
343
+ ;;
333
344
  xscaleeb)
334
345
  basic_machine=armeb-unknown
335
346
  ;;
@@ -352,11 +363,13 @@ case $basic_machine in
352
363
  # Recognize the basic CPU types with company name.
353
364
  580-* \
354
365
  | a29k-* \
366
+ | aarch64-* | aarch64_be-* \
355
367
  | alpha-* | alphaev[4-8]-* | alphaev56-* | alphaev6[78]-* \
356
368
  | alpha64-* | alpha64ev[4-8]-* | alpha64ev56-* | alpha64ev6[78]-* \
357
369
  | alphapca5[67]-* | alpha64pca5[67]-* | arc-* \
358
370
  | arm-* | armbe-* | armle-* | armeb-* | armv*-* \
359
371
  | avr-* | avr32-* \
372
+ | be32-* | be64-* \
360
373
  | bfin-* | bs2000-* \
361
374
  | c[123]* | c30-* | [cjt]90-* | c4x-* \
362
375
  | clipper-* | craynv-* | cydra-* \
@@ -365,12 +378,15 @@ case $basic_machine in
365
378
  | f30[01]-* | f700-* | fido-* | fr30-* | frv-* | fx80-* \
366
379
  | h8300-* | h8500-* \
367
380
  | hppa-* | hppa1.[01]-* | hppa2.0-* | hppa2.0[nw]-* | hppa64-* \
381
+ | hexagon-* \
368
382
  | i*86-* | i860-* | i960-* | ia64-* | ia64[nw]-* \
369
383
  | ip2k-* | iq2000-* \
384
+ | le32-* | le64-* \
370
385
  | lm32-* \
371
386
  | m32c-* | m32r-* | m32rle-* \
372
387
  | m68000-* | m680[012346]0-* | m68360-* | m683?2-* | m68k-* \
373
- | m88110-* | m88k-* | maxq-* | mcore-* | metag-* | microblaze-* \
388
+ | m88110-* | m88k-* | maxq-* | mcore-* | metag-* \
389
+ | microblaze-* | microblazeel-* \
374
390
  | mips-* | mipsbe-* | mipseb-* | mipsel-* | mipsle-* \
375
391
  | mips16-* \
376
392
  | mips64-* | mips64el-* \
@@ -388,19 +404,20 @@ case $basic_machine in
388
404
  | mipsisa64r2-* | mipsisa64r2el-* \
389
405
  | mipsisa64sb1-* | mipsisa64sb1el-* \
390
406
  | mipsisa64sr71k-* | mipsisa64sr71kel-* \
407
+ | mipsr5900-* | mipsr5900el-* \
391
408
  | mipstx39-* | mipstx39el-* \
392
409
  | mmix-* \
393
410
  | mt-* \
394
411
  | msp430-* \
395
412
  | nds32-* | nds32le-* | nds32be-* \
396
- | nios-* | nios2-* \
413
+ | nios-* | nios2-* | nios2eb-* | nios2el-* \
397
414
  | none-* | np1-* | ns16k-* | ns32k-* \
398
415
  | open8-* \
399
416
  | orion-* \
400
417
  | pdp10-* | pdp11-* | pj-* | pjl-* | pn-* | power-* \
401
418
  | powerpc-* | powerpc64-* | powerpc64le-* | powerpcle-* \
402
419
  | pyramid-* \
403
- | romp-* | rs6000-* | rx-* \
420
+ | rl78-* | romp-* | rs6000-* | rx-* \
404
421
  | sh-* | sh[1234]-* | sh[24]a-* | sh[24]aeb-* | sh[23]e-* | sh[34]eb-* | sheb-* | shbe-* \
405
422
  | shle-* | sh[1234]le-* | sh3ele-* | sh64-* | sh64le-* \
406
423
  | sparc-* | sparc64-* | sparc64b-* | sparc64v-* | sparc86x-* | sparclet-* \
@@ -408,10 +425,11 @@ case $basic_machine in
408
425
  | sparcv8-* | sparcv9-* | sparcv9b-* | sparcv9v-* | sv1-* | sx?-* \
409
426
  | tahoe-* \
410
427
  | tic30-* | tic4x-* | tic54x-* | tic55x-* | tic6x-* | tic80-* \
411
- | tile-* | tilegx-* \
428
+ | tile*-* \
412
429
  | tron-* \
413
430
  | ubicom32-* \
414
- | v850-* | v850e-* | vax-* \
431
+ | v850-* | v850e-* | v850e1-* | v850es-* | v850e2-* | v850e2v3-* \
432
+ | vax-* \
415
433
  | we32k-* \
416
434
  | x86-* | x86_64-* | xc16x-* | xps100-* \
417
435
  | xstormy16-* | xtensa*-* \
@@ -711,7 +729,6 @@ case $basic_machine in
711
729
  i370-ibm* | ibm*)
712
730
  basic_machine=i370-ibm
713
731
  ;;
714
- # I'm not sure what "Sysv32" means. Should this be sysv3.2?
715
732
  i*86v32)
716
733
  basic_machine=`echo $1 | sed -e 's/86.*/86-pc/'`
717
734
  os=-sysv32
@@ -769,9 +786,13 @@ case $basic_machine in
769
786
  basic_machine=ns32k-utek
770
787
  os=-sysv
771
788
  ;;
772
- microblaze)
789
+ microblaze*)
773
790
  basic_machine=microblaze-xilinx
774
791
  ;;
792
+ mingw64)
793
+ basic_machine=x86_64-pc
794
+ os=-mingw64
795
+ ;;
775
796
  mingw32)
776
797
  basic_machine=i386-pc
777
798
  os=-mingw32
@@ -808,10 +829,18 @@ case $basic_machine in
808
829
  ms1-*)
809
830
  basic_machine=`echo $basic_machine | sed -e 's/ms1-/mt-/'`
810
831
  ;;
832
+ msys)
833
+ basic_machine=i386-pc
834
+ os=-msys
835
+ ;;
811
836
  mvs)
812
837
  basic_machine=i370-ibm
813
838
  os=-mvs
814
839
  ;;
840
+ nacl)
841
+ basic_machine=le32-unknown
842
+ os=-nacl
843
+ ;;
815
844
  ncr3000)
816
845
  basic_machine=i486-ncr
817
846
  os=-sysv4
@@ -992,7 +1021,11 @@ case $basic_machine in
992
1021
  basic_machine=i586-unknown
993
1022
  os=-pw32
994
1023
  ;;
995
- rdos)
1024
+ rdos | rdos64)
1025
+ basic_machine=x86_64-pc
1026
+ os=-rdos
1027
+ ;;
1028
+ rdos32)
996
1029
  basic_machine=i386-pc
997
1030
  os=-rdos
998
1031
  ;;
@@ -1120,13 +1153,8 @@ case $basic_machine in
1120
1153
  basic_machine=t90-cray
1121
1154
  os=-unicos
1122
1155
  ;;
1123
- # This must be matched before tile*.
1124
- tilegx*)
1125
- basic_machine=tilegx-unknown
1126
- os=-linux-gnu
1127
- ;;
1128
1156
  tile*)
1129
- basic_machine=tile-unknown
1157
+ basic_machine=$basic_machine-unknown
1130
1158
  os=-linux-gnu
1131
1159
  ;;
1132
1160
  tx39)
@@ -1324,21 +1352,21 @@ case $os in
1324
1352
  -gnu* | -bsd* | -mach* | -minix* | -genix* | -ultrix* | -irix* \
1325
1353
  | -*vms* | -sco* | -esix* | -isc* | -aix* | -cnk* | -sunos | -sunos[34]*\
1326
1354
  | -hpux* | -unos* | -osf* | -luna* | -dgux* | -auroraux* | -solaris* \
1327
- | -sym* | -kopensolaris* \
1355
+ | -sym* | -kopensolaris* | -plan9* \
1328
1356
  | -amigaos* | -amigados* | -msdos* | -newsos* | -unicos* | -aof* \
1329
1357
  | -aos* | -aros* \
1330
1358
  | -nindy* | -vxsim* | -vxworks* | -ebmon* | -hms* | -mvs* \
1331
1359
  | -clix* | -riscos* | -uniplus* | -iris* | -rtu* | -xenix* \
1332
1360
  | -hiux* | -386bsd* | -knetbsd* | -mirbsd* | -netbsd* \
1333
- | -openbsd* | -solidbsd* \
1361
+ | -bitrig* | -openbsd* | -solidbsd* \
1334
1362
  | -ekkobsd* | -kfreebsd* | -freebsd* | -riscix* | -lynxos* \
1335
1363
  | -bosx* | -nextstep* | -cxux* | -aout* | -elf* | -oabi* \
1336
1364
  | -ptx* | -coff* | -ecoff* | -winnt* | -domain* | -vsta* \
1337
1365
  | -udi* | -eabi* | -lites* | -ieee* | -go32* | -aux* \
1338
1366
  | -chorusos* | -chorusrdb* | -cegcc* \
1339
- | -cygwin* | -pe* | -psos* | -moss* | -proelf* | -rtems* \
1340
- | -mingw32* | -linux-gnu* | -linux-android* \
1341
- | -linux-newlib* | -linux-uclibc* \
1367
+ | -cygwin* | -msys* | -pe* | -psos* | -moss* | -proelf* | -rtems* \
1368
+ | -mingw32* | -mingw64* | -linux-gnu* | -linux-android* \
1369
+ | -linux-newlib* | -linux-musl* | -linux-uclibc* \
1342
1370
  | -uxpv* | -beos* | -mpeix* | -udk* \
1343
1371
  | -interix* | -uwin* | -mks* | -rhapsody* | -darwin* | -opened* \
1344
1372
  | -openstep* | -oskit* | -conix* | -pw32* | -nonstopux* \
@@ -1470,9 +1498,6 @@ case $os in
1470
1498
  -aros*)
1471
1499
  os=-aros
1472
1500
  ;;
1473
- -kaos*)
1474
- os=-kaos
1475
- ;;
1476
1501
  -zvmoe)
1477
1502
  os=-zvmoe
1478
1503
  ;;
@@ -1521,6 +1546,9 @@ case $basic_machine in
1521
1546
  c4x-* | tic4x-*)
1522
1547
  os=-coff
1523
1548
  ;;
1549
+ hexagon-*)
1550
+ os=-elf
1551
+ ;;
1524
1552
  tic54x-*)
1525
1553
  os=-coff
1526
1554
  ;;
@@ -1548,9 +1576,6 @@ case $basic_machine in
1548
1576
  ;;
1549
1577
  m68000-sun)
1550
1578
  os=-sunos3
1551
- # This also exists in the configure program, but was not the
1552
- # default.
1553
- # os=-sunos4
1554
1579
  ;;
1555
1580
  m68*-cisco)
1556
1581
  os=-aout
@@ -7,7 +7,7 @@ end
7
7
 
8
8
  module Trinidad
9
9
  module Daemon
10
-
10
+
11
11
  def init
12
12
  end
13
13
 
@@ -21,9 +21,16 @@ module Trinidad
21
21
  # called from com.msp.jsvc.JRubyDaemon.start
22
22
  # as Trinidad::Daemon#start
23
23
  def start(args = ARGV)
24
- Trinidad::CommandLineParser.parse(args)
25
- Trinidad.configuration.trap = false
26
- @server = Trinidad::Server.new
24
+ if Trinidad.const_defined?(:CLI)
25
+ config = Trinidad::CLI.parse(args)
26
+ config[:trap] = false
27
+ @server = Trinidad::Server.new(config)
28
+ else # backwards (< 1.5) compatibility :
29
+ Trinidad::CommandLineParser.parse(args)
30
+ Trinidad.configuration.trap = false
31
+ @server = Trinidad::Server.new
32
+ end
33
+
27
34
  @server.start
28
35
  end
29
36
 
@@ -1,4 +1,3 @@
1
- require 'erb'
2
1
  require 'java'
3
2
  require 'jruby'
4
3
  require 'fileutils'
@@ -8,7 +7,7 @@ require 'shellwords'
8
7
  module Trinidad
9
8
  module InitServices
10
9
  class Configuration
11
-
10
+
12
11
  def self.windows?
13
12
  RbConfig::CONFIG['host_os'] =~ /mswin|mingw/i
14
13
  end
@@ -16,166 +15,483 @@ module Trinidad
16
15
  def self.macosx?
17
16
  RbConfig::CONFIG['host_os'] =~ /darwin/i
18
17
  end
19
-
18
+
20
19
  def initialize(stdin = STDIN, stdout = STDOUT)
21
20
  @stdin, @stdout = stdin, stdout
22
21
  end
23
22
 
24
- def initialize_paths(jruby_home = default_jruby_home)
25
- @trinidad_daemon_path = File.expand_path('../../trinidad/daemon.rb', __FILE__)
26
- @jars_path = File.expand_path('../../../trinidad-libs', __FILE__)
27
-
28
- @classpath = ['jruby-jsvc.jar', 'commons-daemon.jar'].map { |jar| File.join(@jars_path, jar) }
29
- @classpath << File.join(jruby_home, 'lib', 'jruby.jar')
30
- end
23
+ SERVICE_DESC = 'JRuby on Rails/Rack server'
31
24
 
32
25
  def configure(defaults = {})
33
- @app_path = defaults["app_path"] || ask_path('Application path', false)
34
- @trinidad_options = ["-d #{@app_path}"]
26
+ if ( @app_path = defaults["app_path"] ).nil?
27
+ unless @base_path = defaults["base_path"]
28
+ @app_path = ask_path('Application (base - in case of multiple apps) path', false) do
29
+ raise "application/base path not provided (try . if current directory is the app)"
30
+ end
31
+ end
32
+ end
33
+
35
34
  options_ask = 'Trinidad options?'
36
- options_default = '-e production'
37
- collect_windows_opts(options_ask, defaults) if windows?
38
-
39
- @trinidad_options << (defaults["trinidad_options"] || ask(options_ask, options_default))
40
- @trinidad_options.map! { |opt| Shellwords.shellsplit(opt) }.flatten!
41
- @jruby_home = defaults["jruby_home"] || ask_path('JRuby home', default_jruby_home)
42
- @ruby_compat_version = defaults["ruby_compat_version"] || ask('Ruby 1.8.x or 1.9.x compatibility', default_ruby_compat_version)
43
- @jruby_opts = configure_jruby_opts
35
+
36
+ @service_id = defaults['service_id'] || defaults['trinidad_service_id']
37
+ @service_name = defaults['service_name'] || defaults['trinidad_name']
38
+ @service_desc = defaults['service_desc'] || defaults['trinidad_service_desc']
39
+
40
+ if windows?
41
+ options_ask << ' (separated by `;`)'
42
+
43
+ @service_id ||= ask('Service ID? {alphanumeric and underscores only}', default_service_id)
44
+ name_default = @service_id.gsub('_', ' ')
45
+ @service_name ||= ask('Service (display) name? {alphanumeric and spaces only}', name_default)
46
+ @service_desc ||= ask('Service description? {alphanumeric and spaces only}', SERVICE_DESC)
47
+ else
48
+ @service_id ||= default_service_id
49
+ @service_name ||= @service_id
50
+ @service_desc ||= SERVICE_DESC
51
+ end
52
+
53
+ @trinidad_opts = defaults["trinidad_options"] || defaults["trinidad_opts"]
54
+
55
+ if @trinidad_opts.is_a?(String) # leave 'em as are
56
+ if @app_path && ! @trinidad_opts.index('-d') && ! @trinidad_opts.index('--dir')
57
+ @trinidad_opts = "--dir #{@app_path} #{@trinidad_opts}"
58
+ end
59
+ elsif @trinidad_opts
60
+ if @app_path && ! @trinidad_opts.find { |opt| opt.index('-d') || opt.index('--dir') }
61
+ @trinidad_opts.unshift("--dir #{@app_path}")
62
+ end
63
+ else
64
+ @trinidad_opts = [ ask(options_ask, '-e production') ]
65
+ end
66
+
67
+ if @trinidad_opts.is_a?(Array)
68
+ @trinidad_opts.map! { |opt| Shellwords.shellsplit(opt) }
69
+ @trinidad_opts.flatten! # split: 'opt' -> [ 'opt' ]
70
+ end
71
+
72
+ @jruby_home = defaults['jruby_home'] || ask_path('JRuby home', default_jruby_home)
73
+ @ruby_compat_version = defaults["ruby_compat_version"] || default_ruby_compat_version
74
+ @jruby_opts = configure_jruby_opts(@jruby_home, @ruby_compat_version)
44
75
  initialize_paths(@jruby_home)
45
76
 
46
- message = windows? ? configure_windows_service : configure_unix_daemon(defaults)
77
+ @java_home = defaults['java_home'] || ask_path('Java home', default_java_home)
78
+
79
+ @java_opts = defaults['java_opts'] || []
80
+ @java_opts = @java_opts.strip if @java_opts.is_a?(String)
81
+
82
+ # can be disabled with *configure_memory: false*
83
+ configure_memory_requirements(defaults, @java_home)
84
+
85
+ message = windows? ?
86
+ configure_windows_service(defaults, @java_home) :
87
+ configure_unix_daemon(defaults, @java_home)
47
88
  say message if message.is_a?(String)
48
89
  end
49
90
 
50
- def configure_jruby_opts
91
+ MEMORY_DEFAULT = 720
92
+
93
+ def configure_memory_requirements(defaults, java_home)
94
+ return if defaults.key?('configure_memory') && ! defaults['configure_memory']
95
+
96
+ if defaults['configure_memory'] || ask('Configure JVM memory (JAVA_OPTS)? y/n', 'n') == 'y'
97
+
98
+ total_memory = defaults['total_memory'] ||
99
+ ask('Total (max) memory dedicated to Trinidad? (in MB)', MEMORY_DEFAULT)
100
+ total_memory = total_memory.to_i
101
+ if total_memory <= 0
102
+ warn "changing total_memory to '#{MEMORY_DEFAULT}' default (provided value <= 0)"
103
+ total_memory = MEMORY_DEFAULT
104
+ end
105
+ if total_memory <= 160
106
+ warn "provided total_memory '#{total_memory}' seems low (server migh not start)"
107
+ end
108
+
109
+ if current_java_home?(java_home) && current_java_vendor_sun_or_oracle?
110
+ # 720 total memory: (Max) 144M PermGen, 72M CodeCache, 504M Heap
111
+
112
+ add_java_opt('-XX:+UseCodeCacheFlushing')
113
+ cache_size = total_memory >= 800 ? 80 : ( total_memory / 10 )
114
+ cache_size = 100 if total_memory >= 2000
115
+ cache_size = 120 if total_memory >= 3000
116
+ cache_size = 140 if total_memory >= 4000
117
+ add_java_opt('-XX:ReservedCodeCacheSize=', "#{cache_size}m")
118
+
119
+ heap_size = total_memory - cache_size
120
+
121
+ if ! defaults.key?('hot_deployment') || ! defaults['hot_deployment']
122
+ hot_deploy = ask('Support hot (re-)deployment? y/n', 'n') == 'y'
123
+ else
124
+ hot_deploy = true
125
+ end
126
+
127
+ if hot_deploy && current_java_version_6?
128
+ # on Java 7 G1 sweeps PermGen on full GC
129
+ add_java_opt('-XX:+UseConcMarkSweepGC') if hot_deploy
130
+ add_java_opt('-XX:+CMSClassUnloadingEnabled') if hot_deploy
131
+ end
132
+
133
+ if current_java_version_at_least_8?
134
+ # probably a good idea to limit meta-space size :
135
+ meta_size = heap_size / 5 # 20% (unlimited by default)
136
+ meta_size = min(heap_size / 4, meta_size + 100) if hot_deploy
137
+
138
+ unless defaults['total_memory'] # do not ask if configured
139
+ meta = ask('Confirm meta-space size limit: (-XX:MaxMetaspaceSize in MB)', meta_size)
140
+ meta_size = parse_memory_setting(meta, meta_size)
141
+ end
142
+
143
+ add_java_opt('-XX:MaxMetaspaceSize=', "#{meta_size}m") if meta_size
144
+ heap_size -= meta_size.to_i
145
+ else
146
+ perm_size = heap_size / 5 # 20%
147
+ perm_size = min(heap_size / 4, perm_size + 100) if hot_deploy
148
+
149
+ unless defaults['total_memory'] # do not ask if configured
150
+ perm = ask('Confirm perm-gen size limit: (-XX:MaxPermSize in MB)', perm_size)
151
+ perm_size = parse_memory_setting(perm, perm_size)
152
+ end
153
+
154
+ add_java_opt('-XX:MaxPermSize=', "#{perm_size}m") if perm_size
155
+ heap_size -= perm_size.to_i
156
+ end
157
+
158
+ heap_size = ( heap_size / 10 ) * 10
159
+ add_java_opt('-Xmx', "#{heap_size}m")
160
+ min_heap_size = min(heap_size / 2, 500)
161
+ add_java_opt('-Xms', "#{min_heap_size}m")
162
+
163
+ else # only try to limit heap (vendors such as IBM support it) :
164
+
165
+ heap_size = total_memory - ( total_memory / 15 ) # just a guess
166
+
167
+ heap_size = ( heap_size / 10 ) * 10
168
+ add_java_opt('-Xmx', "#{heap_size}m")
169
+
170
+ end
171
+
172
+ add_java_opt('-XX:+UseCompressedOops') if current_java_version_6? && os_arch =~ /64/
173
+
174
+ end
175
+ end
176
+
177
+ def add_java_opt(java_opt, opt_suffix = nil)
178
+ if @java_opts.is_a?(String)
179
+ return false if @java_opts.index(java_opt)
180
+ @java_opts << ( windows? ? ';' : ' ' ) unless @java_opts.strip.empty?
181
+ else
182
+ return false if @java_opts.find { |opt| opt.index(java_opt) }
183
+ end
184
+ @java_opts << "#{java_opt}#{opt_suffix}"
185
+ end
186
+
187
+ def configure_jruby_opts(jruby_home = @jruby_home, ruby_compat_version = @ruby_compat_version)
51
188
  opts = []
52
- opts << "-Djruby.home=#{@jruby_home}"
53
- opts << "-Djruby.lib=#{File.join(@jruby_home, 'lib')}"
189
+ opts << "-Djruby.home=#{jruby_home}"
190
+ opts << "-Djruby.lib=#{File.join(jruby_home, 'lib')}"
54
191
  opts << "-Djruby.script=jruby"
55
192
  opts << "-Djruby.daemon.module.name=Trinidad"
56
- opts << "-Djruby.compat.version=#{@ruby_compat_version}"
193
+ opts << "-Djruby.compat.version=#{ruby_compat_version}"
57
194
  opts
58
195
  end
59
-
60
- def configure_unix_daemon(defaults)
61
- @java_home = defaults["java_home"] || ask_path('Java home', default_java_home)
196
+
197
+ def initialize_paths(jruby_home = default_jruby_home)
198
+ @trinidad_daemon_path = File.expand_path('../../trinidad/daemon.rb', __FILE__)
199
+ @jars_path = File.expand_path('../../../trinidad-libs', __FILE__)
200
+
201
+ @classpath = ['jruby-jsvc.jar', 'commons-daemon.jar'].map { |jar| File.join(@jars_path, jar) }
202
+ @classpath << File.join(jruby_home, 'lib', 'jruby.jar')
203
+ end
204
+
205
+ def configure_unix_daemon(defaults, java_home = default_java_home)
62
206
  unless @jsvc = defaults["jsvc_path"] || detect_jsvc_path
63
207
  @jsvc = ask_path("path to jsvc binary (leave blank and we'll try to compile)", '')
64
208
  if @jsvc.empty? # unpack and compile :
65
209
  jsvc_unpack_dir = defaults["jsvc_unpack_dir"] || ask_path("dir where jsvc dist should be unpacked", '/usr/local/src')
66
- @jsvc = compile_jsvc(jsvc_unpack_dir, @java_home)
67
- say "jsvc binary available at: #{@jsvc} " +
210
+ @jsvc = compile_jsvc(jsvc_unpack_dir, java_home)
211
+ say "jsvc binary available at: #{@jsvc} " +
68
212
  "(consider adding it to $PATH if you plan to re-run trinidad_init_service)"
69
213
  end
70
214
  end
71
- @output_path = defaults["output_path"] || ask_path('init.d output path', '/etc/init.d')
72
- @pid_file = defaults["pid_file"] || ask_path('pid file', '/var/run/trinidad/trinidad.pid')
73
- @log_file = defaults["log_file"] || ask_path('log file', '/var/log/trinidad/trinidad.log')
74
- @run_user = defaults["run_user"] || ask('run daemon as user (enter a non-root username or leave blank)', '')
75
-
76
- if @run_user != '' && `id -u #{@run_user}` == ''
77
- raise ArgumentError, "user '#{@run_user}' does not exist (leave blank if you're planning to `useradd' later)"
78
- end
79
-
215
+
216
+ @pid_file = defaults['pid_file'] || ask_path('pid file', '/var/run/trinidad/trinidad.pid')
217
+ @out_file = defaults['out_file'] || defaults['log_file'] ||
218
+ ask_path('out file (where system out/err gets redirected)', '/var/log/trinidad/trinidad.out')
219
+
80
220
  @pid_file = File.join(@pid_file, 'trinidad.pid') if File.exist?(@pid_file) && File.directory?(@pid_file)
81
221
  make_path_dir(@pid_file, "could not create dir for '#{@pid_file}', make sure dir exists before running daemon")
82
- @log_file = File.join(@log_file, 'trinidad.log') if File.exist?(@log_file) && File.directory?(@log_file)
83
- make_path_dir(@log_file, "could not create dir for '#{@log_file}', make sure dir exists before running daemon")
84
-
85
- daemon = ERB.new(
222
+ @out_file = File.join(@out_file, 'trinidad.out') if File.exist?(@out_file) && File.directory?(@out_file)
223
+ make_path_dir(@out_file, "could not create dir for '#{@out_file}', make sure dir exists before running daemon")
224
+
225
+ @run_user = defaults['run_user'] || ask('run daemon as user (enter a non-root username or leave blank)', '')
226
+ if ! @run_user.empty? && `id -u #{@run_user}` == ''
227
+ raise ArgumentError, "user '#{@run_user}' does not exist (leave blank if you're planning to `useradd' later)"
228
+ end
229
+
230
+ @output_path = defaults['output_path'] || ask_path('init.d output path', '/etc/init.d')
231
+
232
+ require('erb'); daemon = ERB.new(
86
233
  File.read(
87
234
  File.expand_path('../../init.d/trinidad.erb', File.dirname(__FILE__))
88
- )
235
+ ), nil, '-' # safe_level=nil, trim_mode=nil
89
236
  ).result(binding)
90
237
 
91
- say "moving trinidad to #{@output_path}"
92
- trinidad_file = File.join(@output_path, "trinidad")
93
- File.open(trinidad_file, 'w') { |file| file.write(daemon) }
94
- FileUtils.chmod(@run_user == '' ? 0744 : 0755, trinidad_file)
95
-
96
- "\nNOTE: you might want to: `[sudo] update-rc.d -f #{@output_path} defaults`"
238
+ service_file = File.join(@output_path, @service_id ||= 'trinidad')
239
+ begin
240
+ File.open(service_file, 'w') { |file| file.write(daemon) }
241
+ rescue Errno::EACCES => e
242
+ begin
243
+ service_file = File.basename(service_file) # leave in current WD
244
+ service_file = File.expand_path(service_file)
245
+ File.open(service_file, 'w') { |file| file.write(daemon) }
246
+ warn "#{e.message} left init.d script at #{service_file}"
247
+ rescue
248
+ raise e
249
+ end
250
+ end
251
+ FileUtils.chmod @run_user.empty? ? 0744 : 0755, service_file
252
+
253
+ if chkconfig?
254
+ command = "chkconfig #{@service_id} on"
255
+ else
256
+ command = "update-rc.d -f #{@service_id} remove"
257
+ end
258
+ if service_file.start_with?('/etc')
259
+ unless exec_system(command, :allow_failure)
260
+ warn "\nNOTE: run `#{command}` as a super-used to enable service"
261
+ end
262
+ else
263
+ warn "\nNOTE: run `cp #{service_file} /etc/init.d` and `#{command}` as a super-used to enable service"
264
+ end
97
265
  end
98
266
 
99
- def collect_windows_opts(options_ask, defaults)
100
- options_ask << '(separated by `;`)'
101
- name_ask = 'Service name? {Alphanumeric and spaces only}'
102
- name_default = 'Trinidad'
103
- @trinidad_name = defaults["trinidad_name"] || ask(name_ask, name_default)
267
+ def configure_windows_service(defaults, java_home = default_java_home)
268
+ srv_path = detect_prunsrv_path
104
269
 
105
- id_ask = 'Service ID? {Alphanumeric and underscores only}'
106
- id_default = @trinidad_name.gsub(/\s+/, '_').gsub(/\W/, '')
107
- @trinidad_service_id = defaults["trinidad_service_id"] || ask(id_ask, id_default)
270
+ classpath = escape_windows_options(@classpath)
271
+ trinidad_options = escape_windows_options(@trinidad_opts, :split)
108
272
 
109
- desc_ask = 'Service description? {Alphanumeric and spaces only}'
110
- desc_default = 'Embedded Apache Tomcat running Rack and Rails applications'
111
- @trinidad_service_desc = defaults["trinidad_service_desc"] || ask(desc_ask, desc_default)
273
+ jvm_options = escape_windows_options(@jruby_opts)
274
+ unless @java_opts.empty?
275
+ jvm_options << ';' << escape_windows_options(@java_opts)
276
+ end
277
+
278
+ log_path = defaults['log_path'] || "%SystemRoot%\\System32\\LogFiles\\#{@service_id}"
279
+ @out_file = defaults['out_file'] || defaults['log_file'] ||
280
+ ask_path('out file (where system out/err gets redirected), leave blank for prunsrv default', '')
281
+ @pid_file = defaults['pid_file'] || "#{@service_id}.pid"
282
+
283
+ #stop_timeout = defaults['stop_timeout'] || 5
284
+
285
+ # //TS Run the service as a console application
286
+ # This is the default operation (if no option is provided).
287
+ # //RS Run the service Called only from ServiceManager
288
+ # //ES Start (execute) the service
289
+ # //SS Stop the service
290
+ # //US Update service parameters
291
+ # //IS Install service
292
+ # //DS Delete service Stops the service first if it is currently running
293
+ # //PP[//seconds] Pause Default is 60 seconds
294
+
295
+ if service_listed_windows?(@service_id)
296
+ say "service '#{@service_id}' already installed, will update instead of install"
297
+ command = %Q{//US//#{@service_id} --DisplayName="#{@service_name}"}
298
+ else
299
+ command = %Q{//IS//#{@service_id} --DisplayName="#{@service_name}"}
300
+ end
301
+
302
+ command << " --Description=\"#{@service_desc}\""
303
+ command << " --Install=#{srv_path} --Jvm=auto"
304
+ command << " --JavaHome=\"#{escape_windows_path(java_home)}\""
305
+ command << " --StartMode=jvm --StopMode=jvm"
306
+ command << " --StartClass=com.msp.procrun.JRubyService --StartMethod=start"
307
+ command << " --StartParams=\"#{escape_windows_path(@trinidad_daemon_path)};#{trinidad_options}\""
308
+ command << " --StopClass=com.msp.procrun.JRubyService --StopMethod=stop"
309
+ command << " --Classpath=\"#{classpath}\""
310
+ command << " ++JvmOptions=\"#{jvm_options}\""
311
+ command << " --LogPath=\"#{escape_windows_path(log_path)}\""
312
+ command << " --PidFile=#{@pid_file}" # always assumed log_path relative
313
+
314
+ if @out_file && ! @out_file.empty?
315
+ out_file = escape_windows_path(@out_file)
316
+ command << " --StdOutput=\"#{out_file}\" --StdError=\"#{out_file}\""
317
+ else
318
+ command << " --StdOutput=auto --StdError=auto"
319
+ end
320
+
321
+ exec_system "#{srv_path} #{command}"
322
+
323
+ warn "\nNOTE: service needs to be started manually, to start during boot run:\n" <<
324
+ "#{srv_path} //US//#{@service_id} --Startup=auto"
325
+
326
+ "\nHINT: you may use prunsrv to manage your service, try running:\n#{srv_path} help"
112
327
  end
113
-
114
- def configure_windows_service
115
- srv_path = detect_prunsrv_path
116
328
 
117
- command = %Q{//IS//#{@trinidad_service_id} --DisplayName="#{@trinidad_name}" \
118
- --Description="#{@trinidad_service_desc}" \
119
- --Install=#{srv_path} --Jvm=auto --StartMode=jvm --StopMode=jvm \
120
- --StartClass=com.msp.procrun.JRubyService --StartMethod=start \
121
- --StartParams="#{escape_path(@trinidad_daemon_path)};#{format_options(@trinidad_options)}" \
122
- --StopClass=com.msp.procrun.JRubyService --StopMethod=stop --Classpath="#{format_options(@classpath)}" \
123
- --StdOutput=auto --StdError=auto \
124
- --LogPrefix="#{@trinidad_service_id.downcase}" \
125
- ++JvmOptions="#{format_options(@jruby_opts)}"
126
- }
127
- system "#{srv_path} #{command}"
128
-
129
- "\nNOTE: you may use prunsrv to manage your service, try running:\n" +
130
- "#{srv_path} help"
131
- end
132
-
133
- def uninstall(service)
329
+ def uninstall(service = nil)
330
+ initialize_paths
331
+ service ||= default_service_id
134
332
  windows? ? uninstall_windows_service(service) : uninstall_unix_daemon(service)
135
333
  end
136
-
137
- def uninstall_windows_service(service_name)
334
+
335
+ def uninstall_windows_service(service)
138
336
  srv_path = detect_prunsrv_path
139
- system "#{srv_path} stop #{service_name}"
140
- system "#{srv_path} delete #{service_name}"
337
+ exec_system "#{srv_path} //DS//#{service}" # does stop first if needed
338
+ end
339
+
340
+ def service_listed_windows?(service)
341
+ # *sc* will allow SERVICE_NAME only (DISPLAY_NAME won't work)
342
+ out = `sc queryex type= service state= all | find "#{service}"`
343
+ return false if out.chomp.empty?
344
+ # "SERVICE_NAME: Trinidad\nDISPLAY_NAME: Trinidad\n"
345
+ !! ( out =~ /SERVICE_NAME: #{service}$/i )
141
346
  end
142
347
 
143
348
  def uninstall_unix_daemon(service)
144
- name = File.basename(service) # e.g. /etc/init.d/trinidad
145
- command = "update-rc.d -f #{name} remove"
146
- system command
147
- rescue => e
148
- say "uninstall failed, try `sudo #{command}`"
149
- raise e
150
- ensure
151
349
  unless File.exist?(service)
152
350
  service = File.expand_path(service, '/etc/init.d')
153
351
  end
352
+ name = File.basename(service) # e.g. /etc/init.d/trinidad
353
+
354
+ unless service_listed_unix?(service)
355
+ warn "service '#{service}' seems to be NOT installed/configured"
356
+ end
357
+
358
+ if chkconfig?
359
+ exec_system command = "chkconfig #{name} stop", :allow_failure
360
+ exec_system command = "chkconfig #{name} off"
361
+ else # assuming Debian based
362
+ exec_system command = "service #{name} stop", :allow_failure
363
+ exec_system command = "update-rc.d -f #{name} remove"
364
+ end
365
+ rescue => e
366
+ say "uninstall failed, maybe try running `#{command}` as super-user"
367
+ raise e
368
+ else
154
369
  FileUtils.rm(service) if File.exist?(service)
155
370
  end
156
-
371
+
372
+ def service_listed_unix?(service)
373
+ if chkconfig?
374
+ ! `chkconfig --list | grep #{service}`.chomp.empty?
375
+ else
376
+ ! `service --status-all | grep #{service}`.chomp.empty?
377
+ end
378
+ end
379
+
157
380
  private
158
381
 
159
- def escape_path(path)
382
+ def exec_system(command, allow_failure = nil)
383
+ log_command command
384
+ ok = system command
385
+ unless allow_failure
386
+ raise "could not execute `#{command}`" if ok.nil?
387
+ raise "`#{command}` failed" unless ok
388
+ end
389
+ ok
390
+ end
391
+
392
+ def log_command(command)
393
+ say command
394
+ log && (log.puts "#{command}\n\n"; log.flush)
395
+ end
396
+
397
+ def log
398
+ return @_log || nil if defined?(@_log) && ! @_log.nil?
399
+ ( @_log = File.open('trinidad_init_service.log', 'w') rescue false ) || nil
400
+ end
401
+
402
+ def log?; defined?(@_log) ? !! @_log : nil end
403
+
404
+ def escape_windows_path(path)
160
405
  path.gsub(%r{/}, '\\')
161
406
  end
162
-
163
- def format_options(options)
164
- options.map { |opt| escape_path(opt) }.join(';')
407
+
408
+ def escape_windows_options(options, split = nil)
409
+ if options.is_a?(String)
410
+ return escape_windows_path(options) unless split
411
+ options = options.split(' ')
412
+ end
413
+ options.map { |opt| escape_windows_path(opt) }.join(';')
165
414
  end
166
415
 
167
- def default_jruby_home
416
+ def min(num1, num2); num1 <= num2 ? num1 : num2 end
417
+
418
+ def empty?(arg)
419
+ return true unless arg
420
+ ! arg.respond_to?(:empty) || arg.empty?
421
+ end
422
+
423
+ def parse_memory_setting(memory, default = nil)
424
+ return default if empty?(memory)
425
+ return false if memory == 'n'
426
+ return default if memory == 'y'
427
+ memory = memory[0...-1] if memory.is_a?(String) && memory =~ /m$/i
428
+ memory
429
+ end
430
+
431
+ def chkconfig? # available in RH based distributions
432
+ return @chkconfig unless (@chkconfig ||= nil).nil?
433
+ @chkconfig = ! `which chkconfig`.chomp.empty?
434
+ end
435
+
436
+ def default_service_id; windows? ? 'Trinidad' : 'trinidad' end
437
+
438
+ def default_jruby_home; current_jruby_home end
439
+
440
+ def current_jruby_home
168
441
  Java::JavaLang::System.get_property("jruby.home")
169
442
  end
170
443
 
171
444
  def default_java_home
172
- ENV['JAVA_HOME'] || Java::JavaLang::System.get_property("java.home")
445
+ ENV['JAVA_HOME'] || current_java_home
446
+ end
447
+
448
+ def current_java_home
449
+ ENV_JAVA['java.home']
450
+ end
451
+
452
+ def current_java_home?(java_home)
453
+ java_home == current_java_home || begin
454
+ real_java_home = java.io.File.new(java_home).canonical_path
455
+ real_java_home == current_java_home || "#{real_java_home}/jre" == current_java_home
456
+ end
457
+ end
458
+
459
+ def current_java_vendor_sun_or_oracle?
460
+ ENV_JAVA['java.vendor'] =~ /^(Oracle|Sun)/
461
+ end
462
+
463
+ def current_java_version(split = nil)
464
+ version = ENV_JAVA['java.version']
465
+ return version unless split
466
+ @current_java_version ||= begin
467
+ # e.g. "1.7.0_51" -> [ 1, 7, 0 ]
468
+ # but "1.8.0" -> [ 1, 8, 0 ]
469
+ if i = version.index('_')
470
+ version = version[0, i]
471
+ end
472
+ version.split('.').map(&:to_i)
473
+ end
173
474
  end
174
-
175
- def default_ruby_compat_version
176
- JRuby.runtime.is1_9 ? "RUBY1_9" : "RUBY1_8"
475
+
476
+ def current_java_version_6?
477
+ current_java_version(true)[1] == 6
478
+ end
479
+
480
+ def current_java_version_7?
481
+ current_java_version(true)[1] == 7
482
+ end
483
+
484
+ def current_java_version_at_least_8?
485
+ current_java_version(true)[1] >= 8
486
+ end
487
+
488
+ def default_ruby_compat_version; current_ruby_compat_version end
489
+
490
+ def current_ruby_compat_version
491
+ # deprecated on 9k but still working (returns RUBY2_1)
492
+ JRuby.runtime.getInstanceConfig.getCompatVersion.to_s
177
493
  end
178
-
494
+
179
495
  def windows?
180
496
  self.class.windows?
181
497
  end
@@ -183,11 +499,11 @@ module Trinidad
183
499
  def macosx?
184
500
  self.class.macosx?
185
501
  end
186
-
502
+
187
503
  def bundled_jsvc_path # only called on *nix
188
504
  jsvc = 'jsvc_' + (macosx? ? 'darwin' : 'linux')
189
505
  jsvc_path = File.join(@jars_path, jsvc)
190
- # linux version is no longer bundled - as long as it is not present jsvc
506
+ # linux version is no longer bundled - as long as it is not present jsvc
191
507
  # will be compiled from src (if not installed already #detect_jsvc_path)
192
508
  File.exist?(jsvc_path) ? jsvc_path : nil
193
509
  end
@@ -197,7 +513,7 @@ module Trinidad
197
513
  jsvc_path.chomp!
198
514
  jsvc_path.empty? ? bundled_jsvc_path : jsvc_path
199
515
  end
200
-
516
+
201
517
  def compile_jsvc(jsvc_unpack_dir, java_home = default_java_home)
202
518
  unless File.exist?(jsvc_unpack_dir)
203
519
  begin
@@ -212,10 +528,10 @@ module Trinidad
212
528
  unless File.writable?(jsvc_unpack_dir)
213
529
  raise "specified path: #{jsvc_unpack_dir.inspect} is not writable"
214
530
  end
215
-
531
+
216
532
  jsvc_unix_src = File.expand_path('../../jsvc-unix-src', File.dirname(__FILE__))
217
533
  FileUtils.cp_r(jsvc_unix_src, jsvc_unpack_dir)
218
-
534
+
219
535
  jsvc_dir = File.expand_path('jsvc-unix-src', jsvc_unpack_dir)
220
536
  File.chmod(0755, File.join(jsvc_dir, "configure"))
221
537
  # ./configure
@@ -230,7 +546,7 @@ module Trinidad
230
546
  say command_output
231
547
  raise "`#{command}` failed with status: #{$?.exitstatus}"
232
548
  end
233
-
549
+
234
550
  # make
235
551
  command = "cd #{jsvc_dir} && make"
236
552
  say "compiling jsvc ..."
@@ -239,10 +555,10 @@ module Trinidad
239
555
  say command_output
240
556
  raise "`#{command}` failed with status: #{$?.exitstatus}"
241
557
  end
242
-
558
+
243
559
  File.expand_path('jsvc', jsvc_dir) # return path to compiled jsvc binary
244
560
  end
245
-
561
+
246
562
  def detect_jdk_home(java_home = default_java_home)
247
563
  # JDK has an include directory with headers :
248
564
  if File.directory?(File.join(java_home, 'include'))
@@ -255,26 +571,30 @@ module Trinidad
255
571
  end
256
572
  nil
257
573
  end
258
-
574
+
259
575
  def detect_prunsrv_path # only called on windows
260
576
  prunsrv_path = `for %i in (prunsrv.exe) do @echo.%~$PATH:i` rescue ''
261
577
  # a kind of `which prunsrv.exe` (if not found returns "\n")
262
578
  prunsrv_path.chomp!
263
579
  prunsrv_path.empty? ? bundled_prunsrv_path : prunsrv_path
264
580
  end
265
-
266
- def bundled_prunsrv_path(arch = java.lang.System.getProperty("os.arch"))
581
+
582
+ def bundled_prunsrv_path(arch = os_arch)
267
583
  # "amd64", "i386", "x86", "x86_64"
268
584
  path = 'windows'
269
585
  if arch =~ /amd64/i # amd64
270
- path += '/amd64'
586
+ path << '/amd64'
271
587
  elsif arch =~ /64/i # x86_64
272
- path += '/ia64'
588
+ path << '/ia64'
273
589
  # else "i386", "x86"
274
590
  end
275
591
  File.join(@jars_path, path, 'prunsrv.exe')
276
592
  end
277
593
 
594
+ def os_arch
595
+ ENV_JAVA['os.arch']
596
+ end
597
+
278
598
  def make_path_dir(path, error = nil)
279
599
  dir = File.dirname(path)
280
600
  return if File.exist?(dir)
@@ -285,21 +605,23 @@ module Trinidad
285
605
  say "#{error} (#{e})"
286
606
  end
287
607
  end
288
-
608
+
609
+ public
610
+
289
611
  def ask_path(question, default = nil)
290
- path = ask(question, default)
291
- unless path # nil, false
292
- raise "#{question.inspect} not provided!" if path == false
293
- return path # nil
612
+ unless path = ask(question, default) # nil, false
613
+ return path if path.nil?
614
+ block_given? ? yield : raise("#{question.inspect} not provided!")
294
615
  end
295
616
  path.empty? ? path : File.expand_path(path)
296
617
  end
297
618
 
298
619
  def ask(question, default = nil)
299
- return default if ! @stdin.tty? || @ask == false
300
-
301
- question = "#{question}?" unless question.index('?')
302
- question += " [#{default}]" if default && ! default.empty?
620
+ return default if ! @stdin.tty? || ! ask?
621
+
622
+ question = "#{question}?" if ! question.index('?') || ! question.index(':')
623
+ question += " [#{default}]" if default &&
624
+ ( ! default.is_a?(String) || ! default.empty? )
303
625
 
304
626
  result = nil
305
627
  while result.nil?
@@ -310,29 +632,30 @@ module Trinidad
310
632
 
311
633
  if result
312
634
  result.chomp!
313
- case result
314
- when /^$/
315
- result = default
316
- end
635
+ result = default if result.size == 0
317
636
  end
318
637
  end
319
638
  result
320
639
  end
321
-
322
- def ask=(flag)
323
- @ask = !!flag
640
+
641
+ def ask?
642
+ @ask = true unless defined? @ask; return @ask
324
643
  end
644
+
645
+ def ask=(flag); @ask = !!flag end
325
646
  public :ask=
326
-
647
+
327
648
  def say(msg)
328
- puts msg unless @say == false
649
+ puts msg if say?
329
650
  end
330
-
331
- def say=(flag)
332
- @say = !!flag
651
+
652
+ def say?
653
+ @say = true unless defined? @say; return @say
333
654
  end
655
+
656
+ def say=(flag); @say = !!flag end
334
657
  public :say=
335
-
658
+
336
659
  end
337
660
  end
338
661
  end