trinidad_init_services 1.2.3 → 1.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: eba0572bd277127f8bd63d447aa351dc206931e8
4
+ data.tar.gz: 93784996ee1140fa3fd1a1d69f39877079a9d77c
5
+ SHA512:
6
+ metadata.gz: 2b2f768bf987bd52589a4bcc0f00fbfdf1f4310c47405eefb938f2557e7c5bf187318a5136f4f890254f6040be05392d5a95b5e8864b50d60d9cc8c76ba43986
7
+ data.tar.gz: 82739292c9a61af042a06168954deb467f9836b959e8f0ba57b1afa38cc5cc42ed14e2b43f020fb7cebd3a6480f7e69e9f245b1d9c78a52357e403cbe0e1a7d6
data/.travis.yml ADDED
@@ -0,0 +1,12 @@
1
+ language: ruby
2
+ jdk:
3
+ - openjdk6
4
+ - oraclejdk7
5
+ - oraclejdk8
6
+ rvm:
7
+ - jruby
8
+ before_install:
9
+ - ((jruby -v | grep 1.8.7) && jruby --1.9 -S gem update --system 2.1.11) || true
10
+ env:
11
+ - JRUBY_OPTS="--1.8 $JRUBY_OPTS" TRINIDAD_VERSION="~> 1.4.6"
12
+ - JRUBY_OPTS="$JRUBY_OPTS"
data/CHANGELOG.md ADDED
@@ -0,0 +1,123 @@
1
+ ## 1.3.0 (2014-07-03)
2
+
3
+ * `--no-ask` is now known as `--know`
4
+ * (portable) shell sub-string matching without echo
5
+ * do a service update when already installed (on windoze) + better removal
6
+ * include a service trinidad_init_service.log file of commands executed
7
+ * configure out redirection as well as pid file (+ log path) on windoze
8
+ * fix uninstall failing (alwo try supporting RH standarts)
9
+ * revised service id/name/desc configuration (to be 'more' similar on platforms)
10
+ * improved java_home detection and error message
11
+ * align with boot tag script conventions - avoid insserv: warning (#31)
12
+ * support for some detecting of JAVA_OPTS and calculating JVM memory requirements
13
+ * allow to detect 2.x ruby compat mode (JRuby >= 1.7)
14
+ * better init.d compat with other/older shells + support customizing JAVA_OPTS
15
+ * refactor init.d script - make sure -cwd $BASE_DIR happens + warn on missing base
16
+ * do not ask for ruby compat version - simply use the current one
17
+ * refactor log_file to out_file ... as it might be confusing
18
+ * decrease default stack-size 1536k should be still a very 'pessimistic' guess
19
+ * allow to configure jsvc's -wait and -keepstdin in generated init.d script
20
+ * better compatibility for upcoming Trinidad 1.5
21
+ * update commons-daemon to 1.0.15
22
+
23
+ ## 1.2.3 (2013-09-10)
24
+
25
+ * detect if the process is still actually running
26
+ to handle starting the service after the machine was halted and restarted (#36)
27
+ * update to jruby-jsvc 0.5.1
28
+ * update to commons-daemon 1.0.13
29
+ * a better running PID ps check (fix `ps -p` without grep)
30
+
31
+ ## 1.2.2 (2012-10-23)
32
+
33
+ * remove JRUBY_OPTS from init.d script (#28)
34
+ * latest jruby binary compatibility
35
+ - JAVA_MEM accepted in (and converted to) -Xmx format
36
+ - JAVA_STACK accepted in (and converted to) -Xss format
37
+ - added JAVA_MEM_MIN (-Xms format)
38
+
39
+ ## 1.2.1 (2012-09-06)
40
+
41
+ * publicize ask= and say= (used from trinidad_init_service) (#25)
42
+
43
+ ## 1.2.0 (2012-09-03)
44
+
45
+ * add an --uninstall option (requested on Windows) (#22)
46
+ * make ruby binary behave like a "gemtleman" see `trinidad_init_service --help`
47
+ * added possibility to specify service id and service description under windows
48
+ * ensure $PIDFILE_DIR exists and $RUN_USER has access
49
+
50
+ ## 1.1.6 (2012-05-18)
51
+
52
+ * fix windows option formatting with prunsrv's arguments
53
+ * detect prunsrv.exe on windows PATH
54
+
55
+ ## 1.1.5 (2012-03-06)
56
+
57
+ * not working arch detection on Windows + missing 32-bit prunsrv.exe
58
+
59
+ ## 1.1.4 (2012-03-01)
60
+
61
+ * JSVC sources packaged along the gem and compiled on demand (#6)
62
+ * improve JRuby's native path detection in generated init.d script
63
+ * make gem usable with bundler :git => paths
64
+
65
+ ## 1.1.3 (2012-02-20)
66
+
67
+ * do not ask for a path with $RUN_USER
68
+
69
+ ## 1.1.2 (2012-01-17)
70
+
71
+ * revert previous -errfile fix
72
+ * use a better procfile name (#10)
73
+
74
+ ## 1.1.1 (2012-01-16)
75
+
76
+ * issue on with -errfile &1 being misinterpreted (#8)
77
+
78
+ ## 1.1.0 (2012-01-04)
79
+
80
+ * fix bug that didn't allow to create several services with different ids.
81
+ * allow to provide a configuration file to load the options from.
82
+
83
+ ## 1.1.0.pre (2011-09-30)
84
+
85
+ * load prunsrv on Windows according with the architecture
86
+
87
+ ## 1.0.0 (2011-06-11)
88
+
89
+ * rebranded gem
90
+ * fix shutdown compatibility errors with Trinidad 1.2.2 and above
91
+
92
+ ## 0.4.2 (2011-05-17)
93
+
94
+ * fix several minor bugs
95
+
96
+ ## 0.4.1 (2011-01-18)
97
+
98
+ * ensure the unix script is executable by default
99
+
100
+ ## 0.4.0 (2011-01-13)
101
+
102
+ * generate Windows service.
103
+
104
+ ## 0.3.2
105
+
106
+ * remove profile.jar from init script since it's no more bundled with JRuby
107
+
108
+ ## 0.3.1
109
+
110
+ * use absolute path for configuration options
111
+ * start Trinidad from the application path
112
+
113
+ ## 0.3.0
114
+
115
+ * remove init script extension
116
+
117
+ ## 0.2.0
118
+
119
+ * fix several bugs
120
+
121
+ ## 0.1.0
122
+
123
+ * initial release
data/Gemfile CHANGED
@@ -1,2 +1,8 @@
1
1
  source 'https://rubygems.org'
2
- gemspec
2
+ gemspec
3
+
4
+ if version = ENV['TRINIDAD_VERSION']
5
+ gem 'trinidad', version, :require => nil
6
+ end
7
+
8
+ gem 'rake', '~> 10.3', :require => nil
data/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  == Trinidad
2
2
 
3
- Copyright (c) 2012 Team Trinidad and contributors http://github.com/trinidad
3
+ Copyright (c) 2014 Team Trinidad and contributors http://github.com/trinidad
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining
6
6
  a copy of this software and associated documentation files (the
data/README.md CHANGED
@@ -2,13 +2,14 @@
2
2
 
3
3
  Init services based on Apache [Commons Daemon](http://commons.apache.org/daemon/)
4
4
  and [jruby-jsvc](https://github.com/nicobrevin/jruby-jsvc).
5
+
5
6
  Allows you to run Trinidad as an OS daemon, works on Unix and Windows systems.
6
7
 
7
8
  ## Installation
8
9
 
9
- $ jruby -S gem install trinidad_init_services
10
+ $ gem install trinidad_init_services
10
11
 
11
- When the gem is installed the user must launch the installation process:
12
+ When the gem is installed the you launch the installation process :
12
13
 
13
14
  $ jruby -S trinidad_init_service
14
15
 
@@ -16,40 +17,45 @@ This installer guides you through the configuration process and generates a
16
17
  init.d script if you are on a Unix system or creates the service if you are
17
18
  on a Windows box.
18
19
 
19
- You can optionally provide a YAML configuration file with defaults specified
20
+ You can optionally provide a YAML configuration file with defaults specified
20
21
  for the `trinidad_init_service` command. An example configuration file :
21
22
 
22
- app_path: "/home/trinidad/myapp/current"
23
- ruby_compat_version: RUBY1_9
24
- jruby_home: "/opt/jruby"
25
- java_home: "/opt/java"
26
- output_path: "/etc/init.d"
27
- pid_file: "/home/trinidad/myapp/shared/pids/trinidad.pid"
28
- log_file: "/home/trinidad/myapp/shared/log/trinidad.log"
29
- jsvc_path: "/usr/bin/jsvc"
30
- trinidad_options: "-e production"
31
- trinidad_name: Trinidad
32
- trinidad_service_id: Trinidad # on Windows (defaults to :trinidad_name)
33
- trinidad_service_desc: Trinidad Service Description # on Windows (optional)
23
+ ```yaml
24
+ app_path: "/home/trinidad/myapp/current"
25
+ #ruby_compat_version: RUBY1_9
26
+ #service_id: Trinidad # on Windows (defaults to :trinidad_name)
27
+ #service_desc: Trinidad Service Description # on Windows (optional)
28
+ jruby_home: /opt/jruby
29
+ java_home: /opt/java
30
+ output_path: /etc/init.d
31
+ pid_file: /home/trinidad/myapp/shared/pids/trinidad.pid
32
+ out_file: /home/trinidad/myapp/shared/log/trinidad.out # std out/err
33
+ jsvc_path: /usr/bin/jsvc # only used on Unix systems
34
+ trinidad_opts: "-e production --threadsafe"
35
+ java_opts: "-server -Xss1248k -XX:CompileThreshold=8000"
36
+ configure_memory: true # asks you for memory requirements (merges java_opts)
37
+ #total_memory: 720 # total dedicated in mega-bytes (assumes configure_memory)
38
+ #hot_deployment: true # whether using hot-deploys (assumes configure_memory)
39
+ ```
34
40
 
35
41
  You can then run the installer like so:
36
42
 
37
43
  $ trinidad_init_service --defaults trinidad_init_defaults.yml
38
44
 
39
- If any of the required options are not provided in the configuration file, then
40
- the installer will prompt you for them. If you're running this as part of an
41
- environment initialization script than use the *--no-ask* option or provide
45
+ If any of the required options are not provided in the configuration file, then
46
+ the installer will prompt you for them. If you're running this as part of an
47
+ environment initialization script than use the *--know* option or provide
42
48
  only the defaults file path on the command line (make sure all required options
43
49
  are there) :
44
50
 
45
- $ jruby -S trinidad_init_service trinidad_init_defaults.yml
51
+ $ jruby -S trinidad_init_service --know trinidad_init_defaults.yml
46
52
 
47
53
 
48
54
  **NOTE:** Do not confuse the *defaults.yml* "configuration" file with Trinidad's
49
55
  own configuration (*config/trinidad.yml*) file used when setting up the server !
50
56
 
51
57
 
52
- ### Unix
58
+ ### Linux
53
59
 
54
60
  #### Requirements
55
61
 
@@ -63,17 +69,17 @@ you. However please note that to build JSVC on Unix you will need :
63
69
 
64
70
  #### Execution
65
71
 
66
- When the installation process finishes you can use the script generated to launch
72
+ When the installation process finishes you can use the script generated to launch
67
73
  the server as a daemon with the options start|stop|restart, i.e:
68
74
 
69
75
  $ /etc/init.d/trinidad restart
70
76
 
71
77
  #### Running as a Non-Root User
72
78
 
73
- By default, the Trinidad server process will run as the same user that ran the
74
- `/etc/init.d/trinidad start` command. But the service can be configured to run
75
- as a different user. The preferred method for doing this is the `run_user:`
76
- attribute in the configuration YAML (or it's corresponding value at the prompt).
79
+ By default, the Trinidad server process will run as the same user that ran the
80
+ `/etc/init.d/trinidad start` command. But the service can be configured to run
81
+ as a different user. The preferred method for doing this is the `run_user:`
82
+ attribute in the configuration YAML (or it's corresponding value at the prompt).
77
83
  For example:
78
84
 
79
85
  app_path: "/home/trinidad/myapp/current"
@@ -81,7 +87,7 @@ For example:
81
87
  run_user: trinidad
82
88
  # ...
83
89
 
84
- This causes the the server to run with non-root privileges (it essentially executes
90
+ This causes the the server to run with non-root privileges (it essentially executes
85
91
  as `sudo -u run_user jsvc ...`).
86
92
 
87
93
  On some platforms, however, it may be required that you use the JSVC `-user` argument.
@@ -89,12 +95,12 @@ This can be configured with the `JSVC_ARGS_EXTRA` environment variable, like thi
89
95
 
90
96
  JSVC_ARGS_EXTRA="-user myuser" /etc/init.d/trinidad start
91
97
 
92
- It not recommended that you mix the `-user` flag with the `run_user` option !
98
+ It is not recommended that you mix the `-user` flag with the `run_user` option !
93
99
 
94
100
  #### Uninstall
95
101
 
96
- Manage as every other rc.d, assuming `update-rc.d -f /etc/init.d/trinidad defaults`
97
- you can uninstall using :
102
+ manage as every other service (e.g. `update-rc.d -f trinidad defaults` on Ubuntu)
103
+ you can even uninstall (will attempt to delete the script as well) using :
98
104
 
99
105
  $ [sudo] trinidad_init_service --uninstall /etc/init.d/trinidad
100
106
 
@@ -103,17 +109,22 @@ you can uninstall using :
103
109
 
104
110
  #### Execution
105
111
 
106
- Open the **Services** panel under **Administrative Tools** and look for a service
107
- called **Trinidad** (or whatever name you have chosen).
112
+ Open the **Services** panel under **Administrative Tools** and look for a service
113
+ called **Trinidad** (or whatever name you have chosen) then *Start* it.
114
+
115
+ By default the service is not setup to auto start during boot, that can be changed
116
+ from the command-line or using the Windows Services application.
108
117
 
109
118
  #### Uninstall
110
119
 
111
- To remove the service you're going to need the service id (name), than run :
120
+ on Windows uninstallation requires to pass the service name (if not default) :
112
121
 
113
- $ trinidad_init_service --uninstall Trinidad
122
+ $ jruby -S trinidad_init_service --uninstall Trinidad
114
123
 
124
+ Please note that when the service gets uninstalled (on Windows) usually a restart
125
+ is needed for it to be installable again.
115
126
 
116
127
  ## Copyright
117
128
 
118
- Copyright (c) 2012 [Team Trinidad](https://github.com/trinidad).
129
+ Copyright (c) 2012-2014 [Team Trinidad](https://github.com/trinidad).
119
130
  See LICENSE (http://en.wikipedia.org/wiki/MIT_License) for details.
data/Rakefile CHANGED
@@ -5,12 +5,7 @@ rescue LoadError => e
5
5
  raise e
6
6
  end
7
7
  Bundler::GemHelper.install_tasks
8
-
9
- #############################################################################
10
- #
11
- # Standard tasks
12
- #
13
- #############################################################################
8
+ task :gem => :build
14
9
 
15
10
  task :default => :spec
16
11
 
@@ -10,14 +10,14 @@ require 'optparse'
10
10
  defaults = nil
11
11
  configuration = Trinidad::InitServices::Configuration.new
12
12
 
13
- opts = OptionParser.new do |opts|
13
+ options = OptionParser.new do |opts|
14
14
  opts.banner = "Usage: #{File.basename(__FILE__)} [options] [defaults]"
15
-
15
+
16
16
  opts.on('-h', '--help', 'print this help') do
17
17
  puts opts
18
18
  exit
19
19
  end
20
-
20
+
21
21
  opts.on('-v', '--version', 'print version') do
22
22
  begin
23
23
  require 'trinidad'
@@ -28,26 +28,30 @@ opts = OptionParser.new do |opts|
28
28
  exit(0)
29
29
  end
30
30
 
31
- opts.on('-d', '--defaults YAML_FILE', 'use passed file as defaults') do |config|
32
- defaults = config
31
+ opts.on('-d', '--defaults YAML_FILE', 'use passed file as defaults') do |file|
32
+ defaults = file
33
33
  end
34
-
35
- opts.on('-s', '--silent', 'do not print output on console') do
34
+
35
+ opts.on('-s', '--silent', 'do not print any output on console') do
36
36
  configuration.say = false
37
37
  end
38
38
 
39
- opts.on('--no-ask', 'disable interactive (console) mode') do
39
+ opts.on('-k', '--know', "don't ask (disable interactive mode)") do
40
40
  configuration.ask = false
41
41
  end
42
42
 
43
- opts.on('--uninstall NAME', 'remove installed init service') do |name|
43
+ #opts.on('--no-ask', 'disable interactive (console) mode') do
44
+ # configuration.ask = false
45
+ #end
46
+
47
+ opts.on('--uninstall [NAME]', 'remove installed init service') do |name|
44
48
  configuration.uninstall(name)
45
49
  exit(0)
46
50
  end
47
-
51
+
48
52
  end
49
53
 
50
- opts.parse! ARGV
54
+ options.parse! ARGV
51
55
 
52
56
  if ARGV.size > 0 # trinidad_init_service /home/trinidad/defaults.yml
53
57
  defaults = ARGV[0]
data/init.d/trinidad.erb CHANGED
@@ -1,40 +1,60 @@
1
1
  #!/usr/bin/env bash
2
- # Trinidad init.d script using `jsvc` customized from the jsvc-wrapper.sh
2
+ #
3
+ # trinidad init.d script using `jsvc` customized from the jsvc-wrapper.sh
3
4
  # http://github.com/nicobrevin/jruby-jsvc/blob/master/bin/jsvc-wrapper.sh
4
5
  #
5
- # set on a per script/daemon basis (optional) :
6
- # APP_NAME - name of your application (defaults to "trinidad")
6
+ # (c) generated by trinidad_init_services gem on <%= Time.now %>
7
+ #
8
+ ### BEGIN INIT INFO
9
+ # Provides: <%= @service_id || 'trinidad' %>
10
+ # Required-Start: $network $syslog
11
+ # Required-Stop: $network $syslog
12
+ # Default-Start:
13
+ # Default-Stop:
14
+ # Description: <%= @service_desc %>
15
+ # Short-Description: start and stop trinidad
16
+ ### END INIT INFO
17
+
18
+ NAME="<%= @service_name %>"
19
+ DESC="<%= @service_desc %>"
7
20
 
8
21
  # https://github.com/trinidad/trinidad_init_services/wiki/Installing-JSVC
9
22
  JSVC=<%= @jsvc %>
10
- JAVA_HOME=<%= @java_home %>
11
- JRUBY_HOME=<%= @jruby_home %>
12
- APP_PATH=<%= @app_path %>
13
- RUBY_SCRIPT=<%= @trinidad_daemon_path %>
23
+ JAVA_HOME="<%= @java_home %>"
24
+ JRUBY_HOME="<%= @jruby_home %>"
25
+ BASE_PATH="<%= @app_path || @base_path %>"
26
+ RUBY_SCRIPT="<%= @trinidad_daemon_path %>"
14
27
  # The user rights for the running daemon, if you don't bind directly to 80 than
15
28
  # it's always a good idea to run trinidad with non-root user rights.
16
- # Make sure this user has rights on PIDFILE and LOG_FILE paths.
29
+ # Make sure this user has rights on PID_FILE and OUT_FILE paths.
17
30
  # Leaving this empty will cause the daemon to always run as whichever user calls
18
31
  # the script (which during init is equivalent to running it as root).
19
32
  RUN_USER="<%= @run_user %>"
20
33
  # Set this to "1" to echo commands before running them (for troubleshooting) :
21
34
  ECHO_COMMAND=""
22
35
 
23
- # Add here the options that Trinidad needs to run your application,
24
- # but DO NOT delete the -d option, i.e -e production
25
- TRINIDAD_OPTS="<%= @trinidad_options.join(" ") %>"
36
+ # options that Trinidad needs to run your application, e.g. "-e production"
37
+ TRINIDAD_OPTS="<%= @trinidad_opts.is_a?(String) ? @trinidad_opts : @trinidad_opts.join(' ') %>"
38
+
39
+ # a custom (daemon) script will be started (not jruby -S) thus JRUBY_OPTS
40
+ # won't be picked up, however one can hand tune JAVA_OPTS here instead ...
41
+ <% if @java_opts.empty? -%>
42
+ JAVA_OPTS="$JAVA_OPTS"
43
+ <% else -%>
44
+ JAVA_OPTS="<%= @java_opts.is_a?(String) ? @java_opts : @java_opts.join(" \\\n") %>"
45
+ <% end -%>
26
46
 
27
- PIDFILE=<%= @pid_file %>
28
- LOG_FILE=<%= @log_file %>
47
+ PID_FILE="<%= @pid_file %>"
48
+ OUT_FILE="<%= @out_file %>"
29
49
 
30
50
  # Create pidfile directory if missing
31
- # Todo: Remove PIDFILE_DIR creation once jsvc can be started
51
+ # NOTE: Remove PID_FILE_DIR creation once jsvc can be started
32
52
  # as root using the -user option without any issues.
33
- PIDFILE_DIR=$(dirname $PIDFILE)
34
- if [ ! -d "$PIDFILE_DIR" ] ; then
35
- mkdir -p $PIDFILE_DIR
53
+ PID_FILE_DIR=$(dirname $PID_FILE)
54
+ if [ ! -d "$PID_FILE_DIR" ] ; then
55
+ mkdir -p $PID_FILE_DIR
36
56
  if [ ! -z "$RUN_USER" ] ; then
37
- chown -R $RUN_USER $PIDFILE_DIR
57
+ chown -R $RUN_USER $PID_FILE_DIR
38
58
  fi
39
59
  fi
40
60
 
@@ -43,7 +63,16 @@ MAIN_CLASS=com.msp.jsvc.JRubyDaemon
43
63
 
44
64
  CLASSPATH=<%= @classpath.join(":") %>
45
65
 
46
- JRUBY_SHELL=/bin/sh
66
+ if [ ! -z "$BASE_PATH" ] ; then
67
+ if [ ! -d "$BASE_PATH" ]; then
68
+ echo "'$BASE_PATH' is not a directory"
69
+ exit 1
70
+ fi
71
+ fi
72
+
73
+ if [ -z "$JRUBY_SHELL" ] ; then
74
+ JRUBY_SHELL=/bin/sh
75
+ fi
47
76
 
48
77
  JRUBY_NATIVE_PATH=""
49
78
  if [ -d "$JRUBY_HOME/lib/native/" ]; then
@@ -56,39 +85,56 @@ if [ -d "$JRUBY_HOME/lib/native/" ]; then
56
85
  done
57
86
  fi
58
87
 
59
- # JAVA_MEM, JAVA_MEM_MIN & JAVA_STACK are compatible with jruby's binary
88
+ # JAVA_MEM, JAVA_MEM_MIN & JAVA_STACK compatible with JRuby's binary :
60
89
 
61
90
  if [ -z "$JAVA_MEM" ] ; then
62
- JAVA_MEM=-Xmx500m
91
+ JAVA_MEM="-Xmx500m"
63
92
  fi
64
93
  # backwards compatibility we accept the non-full option (e.g. JAVA_MEM=500m)
65
- if [[ "$JAVA_MEM" != "-Xmx"* ]] ; then
94
+ if [ "${JAVA_MEM:0:4}" != "-Xmx" ] ; then
66
95
  JAVA_MEM="-Xmx$JAVA_MEM"
67
96
  fi
68
97
 
69
98
  # we accept the non-full option (e.g. JAVA_MEM_MIN=500m)
70
- if [[ -n "$JAVA_MEM_MIN" && "$JAVA_MEM_MIN" != "-Xms"* ]] ; then
71
- JAVA_MEM_MIN="-Xms$JAVA_MEM_MIN"
72
- fi
73
- if [ -z "$JAVA_MEM_MIN" ] ; then
74
- JAVA_MEM_MIN=""
99
+ if [ -n "$JAVA_MEM_MIN" ] ; then
100
+ if [ "${JAVA_MEM_MIN:0:4}" != "-Xms" ] ; then
101
+ JAVA_MEM_MIN="-Xms$JAVA_MEM_MIN"
102
+ fi
103
+ else
104
+ if [ -z "$JAVA_MEM_MIN" ] ; then
105
+ JAVA_MEM_MIN=""
106
+ fi
75
107
  fi
76
108
 
77
109
  if [ -z "$JAVA_STACK" ] ; then
78
- JAVA_STACK=-Xss2048k
110
+ JAVA_STACK="-Xss1536k"
79
111
  fi
80
112
  # backwards compatibility we accept the non-full option (e.g. JAVA_STACK=2048k)
81
- if [[ "$JAVA_STACK" != "-Xss"* ]] ; then
113
+ if [ "${JAVA_STACK:0:4}" != "-Xss" ] ; then
82
114
  JAVA_STACK="-Xss$JAVA_STACK"
83
115
  fi
84
116
 
85
- # A custom (daemon) script will be started (not jruby -S) thus JRUBY_OPTS
86
- # won't be used here, feel free to hand tune JAVA_OPTS here instead ...
117
+ if [ -z "$JAVA_OPTS" ] ; then
118
+ JAVA_OPTS="$JAVA_MEM $JAVA_MEM_MIN $JAVA_STACK"
119
+ else
120
+ for opt in Xmx Xss; do
121
+ if case ${JAVA_OPTS} in *"-${opt}"*) true;; *) false;; esac ; then
122
+ # JAVA_OPTS contains option - do no thing
123
+ else
124
+ if [ "${opt}" == "Xmx" ] ; then
125
+ JAVA_OPTS="$JAVA_OPTS $JAVA_MEM $JAVA_MEM_MIN"
126
+ fi
127
+ if [ "${opt}" == "Xss" ] ; then
128
+ JAVA_OPTS="$JAVA_OPTS $JAVA_STACK"
129
+ fi
130
+ fi
131
+ done
132
+ fi
87
133
 
88
- JAVA_OPTS="$JAVA_MEM $JAVA_MEM_MIN $JAVA_STACK -Xbootclasspath/a:$JRUBY_HOME/lib/jruby.jar"
134
+ JAVA_OPTS="$JAVA_OPTS -Xbootclasspath/a:$JRUBY_HOME/lib/jruby.jar"
89
135
 
90
- # force file.encoding to UTF-8 :
91
- if [[ -z "$JAVA_ENCODING" ]]; then
136
+ # force file.encoding to UTF-8 (if JAVA_ENCODING specified) :
137
+ if [ -z "$JAVA_ENCODING" ]; then
92
138
  JAVA_OPTS="$JAVA_OPTS -Dfile.encoding=UTF-8"
93
139
  fi
94
140
 
@@ -99,36 +145,59 @@ JAVA_PROPS="$JAVA_PROPS \
99
145
 
100
146
  PROC_NAME=${SCRIPT_NAME:-${APP_NAME:-"trinidad"}}
101
147
 
148
+ # should be multiple of 10 (min=10) :
149
+ if [ -z "$JSVC_WAIT" ] ; then
150
+ JSVC_WAIT="20"
151
+ fi
152
+
102
153
  JSVC_ARGS="-home $JAVA_HOME \
103
154
  $JSVC_ARGS_EXTRA \
104
- -wait 20 \
105
- -pidfile $PIDFILE \
155
+ -wait $JSVC_WAIT \
156
+ -pidfile $PID_FILE \
106
157
  -procname jsvc-$PROC_NAME \
107
- -jvm server
108
- -outfile $LOG_FILE \
109
- -errfile &1"
158
+ -server"
159
+
160
+ if [ -z "$JSVC_CWD" ] ; then
161
+ JSVC_CWD="$BASE_PATH"
162
+ fi
163
+ # NOTE: jsvc -cwd does not handle quoted (' or ") paths
164
+ if [ "$JSVC_CWD" != "false" ] ; then
165
+ JSVC_ARGS="$JSVC_ARGS -cwd $JSVC_CWD"
166
+ else
167
+ if [ ! -z "$BASE_PATH" ] ; then
168
+ cd "$BASE_PATH" || exit 1
169
+ fi
170
+ fi
171
+
172
+ if [ ! -z "$JSVC_STDIN" ] ; then
173
+ if [ "$JSVC_STDIN" != "false" ] ; then
174
+ JSVC_ARGS="$JSVC_ARGS -keepstdin"
175
+ fi
176
+ fi
177
+
178
+ JSVC_ARGS="$JSVC_ARGS -outfile $OUT_FILE -errfile &1"
110
179
 
111
180
  #
112
181
  # Stop/Start
113
182
  #
114
183
 
115
- if [[ -n "$RUN_USER" && $EUID -eq 0 ]]; then
116
- JSVC="sudo -u $RUN_USER $JSVC"
184
+ if [ -n "$RUN_USER" ]; then
185
+ if [ $EUID -eq 0 ]; then
186
+ JSVC="sudo -u $RUN_USER $JSVC"
187
+ fi
117
188
  fi
118
189
 
119
190
  STOP_COMMAND="$JSVC $JSVC_ARGS -stop $MAIN_CLASS"
120
191
  START_COMMAND="$JSVC $JSVC_ARGS -cp $CLASSPATH $JAVA_PROPS $JAVA_OPTS $MAIN_CLASS $RUBY_SCRIPT $TRINIDAD_OPTS"
121
192
 
122
- cd $APP_PATH || exit 1
123
-
124
193
  case "$1" in
125
194
  start)
126
- if [ -e "$PIDFILE" ]; then
127
- CUR_PID=$(<"$PIDFILE")
195
+ if [ -e "$PID_FILE" ]; then
196
+ CUR_PID=$(<"$PID_FILE")
128
197
  COM_NAME=$(ps -p $CUR_PID -o command= | cut -d ' ' -f 1)
129
198
  PROCESS_NAME="jsvc-$PROC_NAME"
130
199
  if [ "$COM_NAME" != "$PROCESS_NAME" ]; then
131
- rm $PIDFILE
200
+ rm $PID_FILE
132
201
  $START_COMMAND
133
202
  else
134
203
  echo "Pidfile already exists for pid $CUR_PID, not starting."
@@ -145,7 +214,7 @@ case "$1" in
145
214
  fi
146
215
  ;;
147
216
  stop)
148
- if [ -e "$PIDFILE" ]; then
217
+ if [ -e "$PID_FILE" ]; then
149
218
  echo "Stopping $PROC_NAME daemon..."
150
219
  if [ -n "$ECHO_COMMAND" ]; then echo $STOP_COMMAND; fi
151
220
  $STOP_COMMAND
@@ -155,12 +224,12 @@ case "$1" in
155
224
  fi
156
225
  ;;
157
226
  restart)
158
- if [ -e "$PIDFILE" ]; then
227
+ if [ -e "$PID_FILE" ]; then
159
228
  echo "Stopping $PROC_NAME daemon..."
160
229
  if [ -n "$ECHO_COMMAND" ]; then echo $STOP_COMMAND; fi
161
230
  $STOP_COMMAND
162
231
  fi
163
- if [ -e "$PIDFILE" ]; then
232
+ if [ -e "$PID_FILE" ]; then
164
233
  echo "Pidfile still present, $PROC_NAME hasn't stopped"
165
234
  exit 1
166
235
  else
@@ -173,8 +242,8 @@ case "$1" in
173
242
  fi
174
243
  ;;
175
244
  status)
176
- if [ "$PIDFILE" ]; then
177
- PID=`cat $PIDFILE`
245
+ if [ "$PID_FILE" ]; then
246
+ PID=`cat $PID_FILE`
178
247
  OUTPUT=`ps -o pid $PID | grep "$PID"`
179
248
  if [ ${#OUTPUT} -gt 0 ]; then
180
249
  echo "Service running with pid: $PID"