├── .gitignore
├── service
├── elasticsearch32
├── elasticsearch64
├── lib
│ ├── wrapper.jar
│ ├── libwrapper-linux-ia-64.so
│ ├── libwrapper-linux-ppc-32.so
│ ├── libwrapper-linux-ppc-64.so
│ ├── libwrapper-linux-x86-32.so
│ ├── libwrapper-linux-x86-64.so
│ ├── wrapper-windows-x86-32.dll
│ ├── libwrapper-freebsd-x86-32.so
│ ├── libwrapper-freebsd-x86-64.so
│ ├── libwrapper-solaris-x86-32.so
│ ├── libwrapper-solaris-x86-64.so
│ ├── libwrapper-solaris-sparc-32.so
│ ├── libwrapper-solaris-sparc-64.so
│ ├── libwrapper-macosx-universal-32.jnilib
│ └── libwrapper-macosx-universal-64.jnilib
├── exec
│ ├── elasticsearch-linux-ia-64
│ ├── elasticsearch-linux-ppc-32
│ ├── elasticsearch-linux-ppc-64
│ ├── elasticsearch-linux-x86-32
│ ├── elasticsearch-linux-x86-64
│ ├── elasticsearch-freebsd-x86-32
│ ├── elasticsearch-freebsd-x86-64
│ ├── elasticsearch-solaris-x86-32
│ ├── elasticsearch-solaris-x86-64
│ ├── elasticsearch-solaris-sparc-32
│ ├── elasticsearch-solaris-sparc-64
│ ├── elasticsearch-macosx-universal-32
│ ├── elasticsearch-macosx-universal-64
│ └── elasticsearch-windows-x86-32.exe
├── elasticsearch.bat
├── elasticsearch.conf
└── elasticsearch
└── README.md
/.gitignore:
--------------------------------------------------------------------------------
1 | .DS_Store
2 |
--------------------------------------------------------------------------------
/service/elasticsearch32:
--------------------------------------------------------------------------------
1 | #! /bin/sh
2 |
3 | export DIST_BITS="32"
4 | `dirname $0`/elasticsearch $1
5 |
--------------------------------------------------------------------------------
/service/elasticsearch64:
--------------------------------------------------------------------------------
1 | #! /bin/sh
2 |
3 | export DIST_BITS="64"
4 | `dirname $0`/elasticsearch $1
5 |
--------------------------------------------------------------------------------
/service/lib/wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hirokith/elasticsearch-servicewrapper/master/service/lib/wrapper.jar
--------------------------------------------------------------------------------
/service/exec/elasticsearch-linux-ia-64:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hirokith/elasticsearch-servicewrapper/master/service/exec/elasticsearch-linux-ia-64
--------------------------------------------------------------------------------
/service/exec/elasticsearch-linux-ppc-32:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hirokith/elasticsearch-servicewrapper/master/service/exec/elasticsearch-linux-ppc-32
--------------------------------------------------------------------------------
/service/exec/elasticsearch-linux-ppc-64:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hirokith/elasticsearch-servicewrapper/master/service/exec/elasticsearch-linux-ppc-64
--------------------------------------------------------------------------------
/service/exec/elasticsearch-linux-x86-32:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hirokith/elasticsearch-servicewrapper/master/service/exec/elasticsearch-linux-x86-32
--------------------------------------------------------------------------------
/service/exec/elasticsearch-linux-x86-64:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hirokith/elasticsearch-servicewrapper/master/service/exec/elasticsearch-linux-x86-64
--------------------------------------------------------------------------------
/service/lib/libwrapper-linux-ia-64.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hirokith/elasticsearch-servicewrapper/master/service/lib/libwrapper-linux-ia-64.so
--------------------------------------------------------------------------------
/service/lib/libwrapper-linux-ppc-32.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hirokith/elasticsearch-servicewrapper/master/service/lib/libwrapper-linux-ppc-32.so
--------------------------------------------------------------------------------
/service/lib/libwrapper-linux-ppc-64.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hirokith/elasticsearch-servicewrapper/master/service/lib/libwrapper-linux-ppc-64.so
--------------------------------------------------------------------------------
/service/lib/libwrapper-linux-x86-32.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hirokith/elasticsearch-servicewrapper/master/service/lib/libwrapper-linux-x86-32.so
--------------------------------------------------------------------------------
/service/lib/libwrapper-linux-x86-64.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hirokith/elasticsearch-servicewrapper/master/service/lib/libwrapper-linux-x86-64.so
--------------------------------------------------------------------------------
/service/lib/wrapper-windows-x86-32.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hirokith/elasticsearch-servicewrapper/master/service/lib/wrapper-windows-x86-32.dll
--------------------------------------------------------------------------------
/service/exec/elasticsearch-freebsd-x86-32:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hirokith/elasticsearch-servicewrapper/master/service/exec/elasticsearch-freebsd-x86-32
--------------------------------------------------------------------------------
/service/exec/elasticsearch-freebsd-x86-64:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hirokith/elasticsearch-servicewrapper/master/service/exec/elasticsearch-freebsd-x86-64
--------------------------------------------------------------------------------
/service/exec/elasticsearch-solaris-x86-32:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hirokith/elasticsearch-servicewrapper/master/service/exec/elasticsearch-solaris-x86-32
--------------------------------------------------------------------------------
/service/exec/elasticsearch-solaris-x86-64:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hirokith/elasticsearch-servicewrapper/master/service/exec/elasticsearch-solaris-x86-64
--------------------------------------------------------------------------------
/service/lib/libwrapper-freebsd-x86-32.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hirokith/elasticsearch-servicewrapper/master/service/lib/libwrapper-freebsd-x86-32.so
--------------------------------------------------------------------------------
/service/lib/libwrapper-freebsd-x86-64.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hirokith/elasticsearch-servicewrapper/master/service/lib/libwrapper-freebsd-x86-64.so
--------------------------------------------------------------------------------
/service/lib/libwrapper-solaris-x86-32.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hirokith/elasticsearch-servicewrapper/master/service/lib/libwrapper-solaris-x86-32.so
--------------------------------------------------------------------------------
/service/lib/libwrapper-solaris-x86-64.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hirokith/elasticsearch-servicewrapper/master/service/lib/libwrapper-solaris-x86-64.so
--------------------------------------------------------------------------------
/service/exec/elasticsearch-solaris-sparc-32:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hirokith/elasticsearch-servicewrapper/master/service/exec/elasticsearch-solaris-sparc-32
--------------------------------------------------------------------------------
/service/exec/elasticsearch-solaris-sparc-64:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hirokith/elasticsearch-servicewrapper/master/service/exec/elasticsearch-solaris-sparc-64
--------------------------------------------------------------------------------
/service/lib/libwrapper-solaris-sparc-32.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hirokith/elasticsearch-servicewrapper/master/service/lib/libwrapper-solaris-sparc-32.so
--------------------------------------------------------------------------------
/service/lib/libwrapper-solaris-sparc-64.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hirokith/elasticsearch-servicewrapper/master/service/lib/libwrapper-solaris-sparc-64.so
--------------------------------------------------------------------------------
/service/exec/elasticsearch-macosx-universal-32:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hirokith/elasticsearch-servicewrapper/master/service/exec/elasticsearch-macosx-universal-32
--------------------------------------------------------------------------------
/service/exec/elasticsearch-macosx-universal-64:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hirokith/elasticsearch-servicewrapper/master/service/exec/elasticsearch-macosx-universal-64
--------------------------------------------------------------------------------
/service/exec/elasticsearch-windows-x86-32.exe:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hirokith/elasticsearch-servicewrapper/master/service/exec/elasticsearch-windows-x86-32.exe
--------------------------------------------------------------------------------
/service/lib/libwrapper-macosx-universal-32.jnilib:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hirokith/elasticsearch-servicewrapper/master/service/lib/libwrapper-macosx-universal-32.jnilib
--------------------------------------------------------------------------------
/service/lib/libwrapper-macosx-universal-64.jnilib:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hirokith/elasticsearch-servicewrapper/master/service/lib/libwrapper-macosx-universal-64.jnilib
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | A service wrapper execution for elasticsearch using [Java Service Wrapper](http://wrapper.tanukisoftware.org/).
2 |
3 | Installation guide
4 | ==================
5 |
6 | **Important**: If you want to use service wrapper with elasticsearch 0.90 (and below), you need to switch to the `0.90` branch of this repository and then follow the installation instructions.
7 |
8 | Simply place the `service` directory under the elasticsearch `bin` directory and edit the `elasticsearch.conf` file to point to the correct elasticsearch home path.
9 |
10 | Elasticsearch can be run as a service using the `elasticsearch` script located under `bin/service` location. The script accepts a single parameter with the following values:
11 |
12 |
13 |
14 | | Parameter |
15 | Description |
16 |
17 |
18 | | console |
19 | Run the elasticsearch in the foreground. |
20 |
21 |
22 | | start |
23 | Run elasticsearch in the background. |
24 |
25 |
26 | | stop |
27 | Stops elasticsearch if its running. |
28 |
29 |
30 | | install |
31 | Install elasticsearch to run on system startup (init.d / service). |
32 |
33 |
34 | | remove |
35 | Removes elasticsearch from system startup (init.d / service). |
36 |
37 |
38 |
39 | The service uses Java Service Wrapper which is a small native wrapper around the Java virtual machine which also monitors it.
40 |
41 | Note, passing JVM level configuration (such as -X parameters) should be set within the `elasticsearch.conf` file.
42 |
43 | The `ES_HEAP_SIZE` environment variable controls the maximum memory allocation for the JVM (set in megabytes). It defaults to `1024`.
44 |
45 | Running on 64-bit Windows
46 | -------------------------
47 |
48 | This requires a commercial license for Java Service Wrapper. Licenses are bound to a specific machine, so make sure you send the correct host id when ordering the license.
49 |
50 | Once you have your license information, paste the extra `wrapper.license.*` lines into the `elasticsearch.conf` file. Then download the corresponding windows x86 64 bit build of the JSW.
51 |
52 | Copy `bin\wrapper.exe` to `bin\service\exec\elasticsearch-windows-x86-64.exe`, and `lib\wrapper.dll` and `lib\wrapper.jar` to `bin\service\lib` in your elasticsearch directory. Also make sure you have a 64-bit JRE installed. The service can then be installed and started as described above.
53 |
--------------------------------------------------------------------------------
/service/elasticsearch.bat:
--------------------------------------------------------------------------------
1 | @echo off
2 | setlocal
3 |
4 | rem Java Service Wrapper command based script.
5 |
6 | rem -----------------------------------------------------------------------------
7 | rem These settings can be modified to fit the needs of your application
8 | rem Optimized for use with version 3.5.6 of the Wrapper.
9 |
10 | rem SET ES_HOME
11 | set ES_HOME=%~dp0\..\..
12 |
13 | rem The base name for the Wrapper binary.
14 | set _WRAPPER_BASE=\exec\elasticsearch
15 |
16 | rem The name and location of the Wrapper configuration file.
17 | rem (Do not remove quotes.)
18 | set _WRAPPER_CONF_DEFAULT="..\elasticsearch.conf"
19 |
20 | rem _PASS_THROUGH tells the script to pass all arguments through to the JVM
21 | rem as is.
22 | rem set _PASS_THROUGH=true
23 |
24 | rem Do not modify anything beyond this point
25 | rem -----------------------------------------------------------------------------
26 |
27 | rem
28 | rem Resolve the real path of the wrapper.exe
29 | rem For non NT systems, the _REALPATH and _WRAPPER_CONF values
30 | rem can be hard-coded below and the following test removed.
31 | rem
32 | if "%OS%"=="Windows_NT" goto nt
33 | echo This script only works with NT-based versions of Windows.
34 | goto :eof
35 |
36 | :nt
37 | rem
38 | rem Find the application home.
39 | rem
40 | rem %~dp0 is location of current script under NT
41 | set _REALPATH=%~dp0
42 |
43 | rem
44 | rem Decide on the specific Wrapper binary to use (See delta-pack)
45 | rem
46 | if "%PROCESSOR_ARCHITECTURE%"=="AMD64" goto amd64
47 | if "%PROCESSOR_ARCHITECTURE%"=="IA64" goto ia64
48 | set _WRAPPER_L_EXE=%_REALPATH%%_WRAPPER_BASE%-windows-x86-32.exe
49 | goto search
50 | :amd64
51 | set _WRAPPER_L_EXE=%_REALPATH%%_WRAPPER_BASE%-windows-x86-64.exe
52 | goto search
53 | :ia64
54 | set _WRAPPER_L_EXE=%_REALPATH%%_WRAPPER_BASE%-windows-ia-64.exe
55 | goto search
56 | :search
57 | set _WRAPPER_EXE=%_WRAPPER_L_EXE%
58 | if exist "%_WRAPPER_EXE%" goto command
59 | set _WRAPPER_EXE=%_REALPATH%%_WRAPPER_BASE%.exe
60 | if exist "%_WRAPPER_EXE%" goto command
61 | echo Unable to locate a Wrapper executable using any of the following names:
62 | echo %_WRAPPER_L_EXE%
63 | echo %_WRAPPER_EXE%
64 | pause
65 | goto :eof
66 |
67 | rem
68 | rem Determine command to run, defaults to console when no parameters are specified
69 | rem
70 | :command
71 | set _COMMAND=%1
72 | if not [%_COMMAND%]==[] (
73 | shift
74 | goto :conf
75 | )
76 | set _COMMAND=console
77 |
78 | rem
79 | rem Find the wrapper.conf
80 | rem
81 | :conf
82 | set _WRAPPER_CONF="%~f1"
83 | if not [%_WRAPPER_CONF%]==[""] (
84 | shift
85 | goto :startup
86 | )
87 | set _WRAPPER_CONF="%_WRAPPER_CONF_DEFAULT%"
88 |
89 | rem
90 | rem Start the Wrapper
91 | rem
92 | :startup
93 |
94 | rem Collect an parameters
95 | :parameters
96 | set _PARAMETERS=%_PARAMETERS% %1
97 | shift
98 | if not [%1]==[] goto :parameters
99 |
100 | if [%_PASS_THROUGH%]==[] (
101 | "%_WRAPPER_EXE%" --%_COMMAND% %_WRAPPER_CONF%
102 | ) else (
103 | "%_WRAPPER_EXE%" --%_COMMAND% %_WRAPPER_CONF% -- %_PARAMETERS%
104 | )
105 | if not errorlevel 1 goto :eof
106 | pause
107 |
108 |
--------------------------------------------------------------------------------
/service/elasticsearch.conf:
--------------------------------------------------------------------------------
1 | set.default.ES_HOME=
2 | set.default.ES_HEAP_SIZE=1024
3 |
4 | #********************************************************************
5 | # Wrapper Timeout Properties
6 | #********************************************************************
7 | # How long to wait for the JVM to start (in seconds)
8 | wrapper.startup.timeout=300
9 | # How long to wait for the JVM to stop (in seconds)
10 | wrapper.shutdown.timeout=300
11 | # When a ping will timeout to consider the JVM hung (in seconds)
12 | wrapper.ping.timeout=300
13 |
14 | #********************************************************************
15 | # Wrapper Java Properties
16 | #********************************************************************
17 | # Java Application
18 | wrapper.java.command=java
19 |
20 | # Tell the Wrapper to log the full generated Java command line.
21 | #wrapper.java.command.loglevel=INFO
22 |
23 | wrapper.java.mainclass=org.tanukisoftware.wrapper.WrapperSimpleApp
24 |
25 | wrapper.working.dir=%ES_HOME%
26 |
27 | # Java Classpath (include wrapper.jar) Add class path elements as
28 | # needed starting from 1
29 | wrapper.java.classpath.1=%ES_HOME%/bin/service/lib/wrapper.jar
30 | wrapper.java.classpath.2=%ES_HOME%/lib/elasticsearch*.jar
31 | wrapper.java.classpath.3=%ES_HOME%/lib/*.jar
32 | wrapper.java.classpath.4=%ES_HOME%/lib/sigar/*.jar
33 |
34 | # Java Library Path (location of Wrapper.DLL or libwrapper.so)
35 | wrapper.java.library.path.1=%ES_HOME%/bin/service/lib
36 |
37 | # Java Bits. On applicable platforms, tells the JVM to run in 32 or 64-bit mode.
38 | wrapper.java.additional.auto_bits=TRUE
39 |
40 | # Java Additional Parameters
41 | wrapper.java.additional.1=-Delasticsearch-service
42 | wrapper.java.additional.2=-Des.path.home=%ES_HOME%
43 | wrapper.java.additional.3=-Xss256k
44 | wrapper.java.additional.4=-XX:+UseParNewGC
45 | wrapper.java.additional.5=-XX:+UseConcMarkSweepGC
46 | wrapper.java.additional.6=-XX:CMSInitiatingOccupancyFraction=75
47 | wrapper.java.additional.7=-XX:+UseCMSInitiatingOccupancyOnly
48 | wrapper.java.additional.8=-XX:+HeapDumpOnOutOfMemoryError
49 | wrapper.java.additional.9=-Djava.awt.headless=true
50 |
51 | # Initial Java Heap Size (in MB)
52 | wrapper.java.initmemory=%ES_HEAP_SIZE%
53 |
54 | # Maximum Java Heap Size (in MB)
55 | wrapper.java.maxmemory=%ES_HEAP_SIZE%
56 |
57 | # Application parameters. Add parameters as needed starting from 1
58 | wrapper.app.parameter.1=org.elasticsearch.bootstrap.ElasticsearchF
59 |
60 | #********************************************************************
61 | # Wrapper Logging Properties
62 | #********************************************************************
63 | # Enables Debug output from the Wrapper.
64 | # wrapper.debug=TRUE
65 |
66 | # Format of output for the console. (See docs for formats)
67 | wrapper.console.format=PM
68 |
69 | # Log Level for console output. (See docs for log levels)
70 | wrapper.console.loglevel=INFO
71 |
72 | # Log file to use for wrapper output logging.
73 | wrapper.logfile=%ES_HOME%/logs/service.log
74 |
75 | # Format of output for the log file. (See docs for formats)
76 | wrapper.logfile.format=LPTM
77 |
78 | # Log Level for log file output. (See docs for log levels)
79 | wrapper.logfile.loglevel=INFO
80 |
81 | # Maximum size that the log file will be allowed to grow to before
82 | # the log is rolled. Size is specified in bytes. The default value
83 | # of 0, disables log rolling. May abbreviate with the 'k' (kb) or
84 | # 'm' (mb) suffix. For example: 10m = 10 megabytes.
85 | wrapper.logfile.maxsize=0
86 |
87 | # Maximum number of rolled log files which will be allowed before old
88 | # files are deleted. The default value of 0 implies no limit.
89 | wrapper.logfile.maxfiles=0
90 |
91 | # Log Level for sys/event log output. (See docs for log levels)
92 | wrapper.syslog.loglevel=NONE
93 |
94 | #********************************************************************
95 | # Wrapper General Properties
96 | #********************************************************************
97 | # Allow for the use of non-contiguous numbered properties
98 | wrapper.ignore_sequence_gaps=TRUE
99 |
100 | # Title to use when running as a console
101 | wrapper.console.title=Elasticsearch
102 |
103 | #********************************************************************
104 | # Wrapper Windows NT/2000/XP Service Properties
105 | #********************************************************************
106 | # WARNING - Do not modify any of these properties when an application
107 | # using this configuration file has been installed as a service.
108 | # Please uninstall the service before modifying this section. The
109 | # service can then be reinstalled.
110 |
111 | # Name of the service
112 | wrapper.name=Elasticsearch
113 |
114 | # Display name of the service
115 | wrapper.displayname=Elasticsearch
116 |
117 | # Description of the service
118 | wrapper.description=Open Source, Distributed, RESTful Search Engine
119 |
120 | # Service dependencies. Add dependencies as needed starting from 1
121 | wrapper.ntservice.dependency.1=
122 |
123 | # Mode in which the service is installed. AUTO_START, DELAY_START or DEMAND_START
124 | wrapper.ntservice.starttype=AUTO_START
125 |
126 | # Allow the service to interact with the desktop.
127 | wrapper.ntservice.interactive=false
128 |
129 |
--------------------------------------------------------------------------------
/service/elasticsearch:
--------------------------------------------------------------------------------
1 | #! /bin/sh
2 |
3 | # RESOLVE and SET $ES_HOME
4 |
5 | SCRIPT="$0"
6 |
7 | # SCRIPT may be an arbitrarily deep series of symlinks. Loop until we have the concrete path.
8 | while [ -h "$SCRIPT" ] ; do
9 | ls=`ls -ld "$SCRIPT"`
10 | # Drop everything prior to ->
11 | link=`expr "$ls" : '.*-> \(.*\)$'`
12 | if expr "$link" : '/.*' > /dev/null; then
13 | SCRIPT="$link"
14 | else
15 | SCRIPT=`dirname "$SCRIPT"`/"$link"
16 | fi
17 | done
18 |
19 | # determine elasticsearch home
20 | ES_HOME=`dirname "$SCRIPT"`/../..
21 |
22 | # make ELASTICSEARCH_HOME absolute
23 | export ES_HOME=`cd $ES_HOME; pwd`
24 |
25 |
26 | # Application
27 | APP_NAME="elasticsearch"
28 | APP_LONG_NAME="Elasticsearch"
29 |
30 | # Wrapper
31 | WRAPPER_CMD="$ES_HOME/bin/service/exec/elasticsearch"
32 | WRAPPER_CONF="$ES_HOME/bin/service/elasticsearch.conf"
33 |
34 | # Priority at which to run the wrapper. See "man nice" for valid priorities.
35 | # nice is only used if a priority is specified.
36 | PRIORITY=
37 |
38 | # Location of the pid file.
39 | PIDDIR="."
40 |
41 | # FIXED_COMMAND tells the script to use a hard coded action rather than
42 | # expecting the first parameter of the command line to be the command.
43 | # By default the command will will be expected to be the first parameter.
44 | #FIXED_COMMAND=console
45 |
46 | # PASS_THROUGH tells the script to pass all arguments through to the JVM
47 | # as is. If FIXED_COMMAND is specified then all arguments will be passed.
48 | # If not set then all arguments starting with the second will be passed.
49 | #PASS_THROUGH=true
50 |
51 | # If uncommented, causes the Wrapper to be shutdown using an anchor file.
52 | # When launched with the 'start' command, it will also ignore all INT and
53 | # TERM signals.
54 | #IGNORE_SIGNALS=true
55 |
56 | # Wrapper will start the JVM asynchronously. Your application may have some
57 | # initialization tasks and it may be desirable to wait a few seconds
58 | # before returning. For example, to delay the invocation of following
59 | # startup scripts. Setting WAIT_AFTER_STARTUP to a positive number will
60 | # cause the start command to delay for the indicated period of time
61 | # (in seconds).
62 | #
63 | WAIT_AFTER_STARTUP=0
64 |
65 | # If set, wait for the wrapper to report that the daemon has started
66 | WAIT_FOR_STARTED_STATUS=true
67 | WAIT_FOR_STARTED_TIMEOUT=120
68 |
69 | # If set, the status, start_msg and stop_msg commands will print out detailed
70 | # state information on the Wrapper and Java processes.
71 | #DETAIL_STATUS=true
72 |
73 | # If set, the 'pause' and 'resume' commands will be enabled. These make it
74 | # possible to pause the JVM or Java application without completely stopping
75 | # the Wrapper. See the wrapper.pausable and wrapper.pausable.stop_jvm
76 | # properties for more information.
77 | #PAUSABLE=true
78 |
79 | # If specified, the Wrapper will be run as the specified user.
80 | # IMPORTANT - Make sure that the user has the required privileges to write
81 | # the PID file and wrapper.log files. Failure to be able to write the log
82 | # file will cause the Wrapper to exit without any way to write out an error
83 | # message.
84 | # NOTE - This will set the user which is used to run the Wrapper as well as
85 | # the JVM and is not useful in situations where a privileged resource or
86 | # port needs to be allocated prior to the user being changed.
87 | #RUN_AS_USER=
88 |
89 | # Specify the number of open files ulimit for the above user
90 | # recommended value: 32000
91 | #ULIMIT_N=
92 |
93 | # By default we show a detailed usage block. Uncomment to show brief usage.
94 | #BRIEF_USAGE=true
95 |
96 | # flag for using upstart when installing (rather than init.d rc.d)
97 | USE_UPSTART=
98 |
99 | # When installing on On Mac OSX platforms, the following domain will be used to
100 | # prefix the plist file name.
101 | PLIST_DOMAIN=org.tanukisoftware.wrapper
102 |
103 | # The following two lines are used by the chkconfig command. Change as is
104 | # appropriate for your application. They should remain commented.
105 | # chkconfig: 2345 20 80
106 | # description: @app.long.name@
107 |
108 | # Initialization block for the install_initd and remove_initd scripts used by
109 | # SUSE linux distributions.
110 | ### BEGIN INIT INFO
111 | # Provides: @app.name@
112 | # Required-Start: $local_fs $network $syslog
113 | # Should-Start:
114 | # Required-Stop:
115 | # Default-Start: 2 3 4 5
116 | # Default-Stop: 0 1 6
117 | # Short-Description: @app.long.name@
118 | # Description: @app.description@
119 | ### END INIT INFO
120 |
121 | # Do not modify anything beyond this point
122 | #-----------------------------------------------------------------------------
123 |
124 | if [ -n "$FIXED_COMMAND" ]
125 | then
126 | COMMAND="$FIXED_COMMAND"
127 | else
128 | COMMAND="$1"
129 | fi
130 |
131 |
132 | # Required for HP-UX Startup
133 | if [ `uname -s` = "HP-UX" -o `uname -s` = "HP-UX64" ] ; then
134 | PATH=$PATH:/usr/bin
135 | fi
136 |
137 | # Get the fully qualified path to the script
138 | case $0 in
139 | /*)
140 | SCRIPT="$0"
141 | ;;
142 | *)
143 | PWD=`pwd`
144 | SCRIPT="$PWD/$0"
145 | ;;
146 | esac
147 |
148 | # Resolve the true real path without any sym links.
149 | CHANGED=true
150 | while [ "X$CHANGED" != "X" ]
151 | do
152 | # Change spaces to ":" so the tokens can be parsed.
153 | SAFESCRIPT=`echo $SCRIPT | sed -e 's; ;:;g'`
154 | # Get the real path to this script, resolving any symbolic links
155 | TOKENS=`echo $SAFESCRIPT | sed -e 's;/; ;g'`
156 | REALPATH=
157 | for C in $TOKENS; do
158 | # Change any ":" in the token back to a space.
159 | C=`echo $C | sed -e 's;:; ;g'`
160 | REALPATH="$REALPATH/$C"
161 | # If REALPATH is a sym link, resolve it. Loop for nested links.
162 | while [ -h "$REALPATH" ] ; do
163 | LS="`ls -ld "$REALPATH"`"
164 | LINK="`expr "$LS" : '.*-> \(.*\)$'`"
165 | if expr "$LINK" : '/.*' > /dev/null; then
166 | # LINK is absolute.
167 | REALPATH="$LINK"
168 | else
169 | # LINK is relative.
170 | REALPATH="`dirname "$REALPATH"`""/$LINK"
171 | fi
172 | done
173 | done
174 |
175 | if [ "$REALPATH" = "$SCRIPT" ]
176 | then
177 | CHANGED=""
178 | else
179 | SCRIPT="$REALPATH"
180 | fi
181 | done
182 |
183 | # Get the location of the script.
184 | REALDIR=`dirname "$REALPATH"`
185 | # Normalize the path
186 | REALDIR=`cd "${REALDIR}"; pwd`
187 |
188 | # If the PIDDIR is relative, set its value relative to the full REALPATH to avoid problems if
189 | # the working directory is later changed.
190 | FIRST_CHAR=`echo $PIDDIR | cut -c1,1`
191 | if [ "$FIRST_CHAR" != "/" ]
192 | then
193 | PIDDIR=$REALDIR/$PIDDIR
194 | fi
195 | # Same test for WRAPPER_CMD
196 | FIRST_CHAR=`echo $WRAPPER_CMD | cut -c1,1`
197 | if [ "$FIRST_CHAR" != "/" ]
198 | then
199 | WRAPPER_CMD=$REALDIR/$WRAPPER_CMD
200 | fi
201 | # Same test for WRAPPER_CONF
202 | FIRST_CHAR=`echo $WRAPPER_CONF | cut -c1,1`
203 | if [ "$FIRST_CHAR" != "/" ]
204 | then
205 | WRAPPER_CONF=$REALDIR/$WRAPPER_CONF
206 | fi
207 |
208 | # Process ID
209 | ANCHORFILE="$PIDDIR/$APP_NAME.anchor"
210 | COMMANDFILE="$PIDDIR/$APP_NAME.command"
211 | STATUSFILE="$PIDDIR/$APP_NAME.status"
212 | JAVASTATUSFILE="$PIDDIR/$APP_NAME.java.status"
213 | PIDFILE="$PIDDIR/$APP_NAME.pid"
214 | LOCKDIR="/var/lock/subsys"
215 | LOCKFILE="$LOCKDIR/$APP_NAME"
216 | pid=""
217 |
218 | # Resolve the location of the 'ps' command
219 | PSEXE="/usr/ucb/ps"
220 | if [ ! -x "$PSEXE" ]
221 | then
222 | PSEXE="/usr/bin/ps"
223 | if [ ! -x "$PSEXE" ]
224 | then
225 | PSEXE="/bin/ps"
226 | if [ ! -x "$PSEXE" ]
227 | then
228 | eval echo `gettext 'Unable to locate "ps".'`
229 | eval echo `gettext 'Please report this message along with the location of the command on your system.'`
230 | exit 1
231 | fi
232 | fi
233 | fi
234 |
235 | TREXE="/usr/bin/tr"
236 | if [ ! -x "$TREXE" ]
237 | then
238 | TREXE="/bin/tr"
239 | if [ ! -x "$TREXE" ]
240 | then
241 | eval echo `gettext 'Unable to locate "tr".'`
242 | eval echo `gettext 'Please report this message along with the location of the command on your system.'`
243 | exit 1
244 | fi
245 | fi
246 | # Resolve the os
247 | DIST_OS=`uname -s | $TREXE "[A-Z]" "[a-z]" | $TREXE -d ' '`
248 | case "$DIST_OS" in
249 | 'sunos')
250 | DIST_OS="solaris"
251 | ;;
252 | 'hp-ux' | 'hp-ux64')
253 | # HP-UX needs the XPG4 version of ps (for -o args)
254 | DIST_OS="hpux"
255 | UNIX95=""
256 | export UNIX95
257 | ;;
258 | 'darwin')
259 | DIST_OS="macosx"
260 | ;;
261 | 'unix_sv')
262 | DIST_OS="unixware"
263 | ;;
264 | 'os/390')
265 | DIST_OS="zos"
266 | ;;
267 | esac
268 |
269 | # Resolve the architecture
270 | if [ "$DIST_OS" = "macosx" ]
271 | then
272 | OS_VER=`sw_vers | grep 'ProductVersion:' | grep -o '[0-9]*\.[0-9]*\.[0-9]*'`
273 | DIST_ARCH="universal"
274 | if [[ "$OS_VER" < "10.5.0" ]]
275 | then
276 | DIST_BITS="32"
277 | else
278 | DIST_BITS="64"
279 | fi
280 | APP_PLIST_BASE=${PLIST_DOMAIN}.${APP_NAME}
281 | APP_PLIST=${APP_PLIST_BASE}.plist
282 | else
283 | DIST_ARCH=
284 | DIST_ARCH=`uname -p 2>/dev/null | $TREXE "[A-Z]" "[a-z]" | $TREXE -d ' '`
285 | if [ "X$DIST_ARCH" = "X" ]
286 | then
287 | DIST_ARCH="unknown"
288 | fi
289 | if [ "$DIST_ARCH" = "unknown" ]
290 | then
291 | DIST_ARCH=`uname -m 2>/dev/null | $TREXE "[A-Z]" "[a-z]" | $TREXE -d ' '`
292 | fi
293 | case "$DIST_ARCH" in
294 | 'athlon' | 'i386' | 'i486' | 'i586' | 'i686')
295 | DIST_ARCH="x86"
296 | if [ "${DIST_OS}" = "solaris" ] ; then
297 | DIST_BITS=`isainfo -b`
298 | else
299 | DIST_BITS="32"
300 | fi
301 | ;;
302 | 'amd64' | 'x86_64')
303 | DIST_ARCH="x86"
304 | DIST_BITS="64"
305 | ;;
306 | 'ia32')
307 | DIST_ARCH="ia"
308 | DIST_BITS="32"
309 | ;;
310 | 'ia64' | 'ia64n' | 'ia64w')
311 | DIST_ARCH="ia"
312 | DIST_BITS="64"
313 | ;;
314 | 'ip27')
315 | DIST_ARCH="mips"
316 | DIST_BITS="32"
317 | ;;
318 | 'power' | 'powerpc' | 'power_pc' | 'ppc64')
319 | if [ "${DIST_ARCH}" = "ppc64" ] ; then
320 | DIST_BITS="64"
321 | else
322 | DIST_BITS="32"
323 | fi
324 | DIST_ARCH="ppc"
325 | if [ "${DIST_OS}" = "aix" ] ; then
326 | if [ `getconf KERNEL_BITMODE` -eq 64 ]; then
327 | DIST_BITS="64"
328 | else
329 | DIST_BITS="32"
330 | fi
331 | fi
332 | ;;
333 | 'pa_risc' | 'pa-risc')
334 | DIST_ARCH="parisc"
335 | if [ `getconf KERNEL_BITS` -eq 64 ]; then
336 | DIST_BITS="64"
337 | else
338 | DIST_BITS="32"
339 | fi
340 | ;;
341 | 'sun4u' | 'sparcv9' | 'sparc')
342 | DIST_ARCH="sparc"
343 | DIST_BITS=`isainfo -b`
344 | ;;
345 | '9000/800' | '9000/785')
346 | DIST_ARCH="parisc"
347 | if [ `getconf KERNEL_BITS` -eq 64 ]; then
348 | DIST_BITS="64"
349 | else
350 | DIST_BITS="32"
351 | fi
352 | ;;
353 | '2064' | '2066' | '2084' | '2086' | '2094' | '2096' | '2097' | '2098' | '2817')
354 | DIST_ARCH="390"
355 | DIST_BITS="64"
356 | ;;
357 | esac
358 | fi
359 |
360 | # OSX always places Java in the same location so we can reliably set JAVA_HOME
361 | if [ "$DIST_OS" = "macosx" ]
362 | then
363 | if [ -z "$JAVA_HOME" ]; then
364 | JAVA_HOME="/Library/Java/Home"; export JAVA_HOME
365 | fi
366 | fi
367 |
368 | # Test Echo
369 | ECHOTEST=`echo -n "x"`
370 | if [ "$ECHOTEST" = "x" ]
371 | then
372 | ECHOOPT="-n "
373 | else
374 | ECHOOPT=""
375 | fi
376 |
377 |
378 | gettext() {
379 | "$WRAPPER_CMD" --translate "$1" "$WRAPPER_CONF" 2>/dev/null
380 | if [ $? != 0 ] ; then
381 | echo "$1"
382 | fi
383 | }
384 |
385 | outputFile() {
386 | if [ -f "$1" ]
387 | then
388 | eval echo `gettext ' $1 Found but not executable.'`;
389 | else
390 | echo " $1"
391 | fi
392 | }
393 |
394 | # Decide on the wrapper binary to use.
395 | # If the bits of the OS could be detected, we will try to look for the
396 | # binary with the correct bits value. If it doesn't exist, fall back
397 | # and look for the 32-bit binary. If that doesn't exist either then
398 | # look for the default.
399 | WRAPPER_TEST_CMD=""
400 | if [ -f "$WRAPPER_CMD-$DIST_OS-$DIST_ARCH-$DIST_BITS" ]
401 | then
402 | WRAPPER_TEST_CMD="$WRAPPER_CMD-$DIST_OS-$DIST_ARCH-$DIST_BITS"
403 | if [ ! -x "$WRAPPER_TEST_CMD" ]
404 | then
405 | chmod +x "$WRAPPER_TEST_CMD" 2>/dev/null
406 | fi
407 | if [ -x "$WRAPPER_TEST_CMD" ]
408 | then
409 | WRAPPER_CMD="$WRAPPER_TEST_CMD"
410 | else
411 | outputFile "$WRAPPER_TEST_CMD"
412 | WRAPPER_TEST_CMD=""
413 | fi
414 | fi
415 | if [ -f "$WRAPPER_CMD-$DIST_OS-$DIST_ARCH-32" -a -z "$WRAPPER_TEST_CMD" ]
416 | then
417 | WRAPPER_TEST_CMD="$WRAPPER_CMD-$DIST_OS-$DIST_ARCH-32"
418 | if [ ! -x "$WRAPPER_TEST_CMD" ]
419 | then
420 | chmod +x "$WRAPPER_TEST_CMD" 2>/dev/null
421 | fi
422 | if [ -x "$WRAPPER_TEST_CMD" ]
423 | then
424 | WRAPPER_CMD="$WRAPPER_TEST_CMD"
425 | else
426 | outputFile "$WRAPPER_TEST_CMD"
427 | WRAPPER_TEST_CMD=""
428 | fi
429 | fi
430 | if [ -f "$WRAPPER_CMD" -a -z "$WRAPPER_TEST_CMD" ]
431 | then
432 | WRAPPER_TEST_CMD="$WRAPPER_CMD"
433 | if [ ! -x "$WRAPPER_TEST_CMD" ]
434 | then
435 | chmod +x "$WRAPPER_TEST_CMD" 2>/dev/null
436 | fi
437 | if [ -x "$WRAPPER_TEST_CMD" ]
438 | then
439 | WRAPPER_CMD="$WRAPPER_TEST_CMD"
440 | else
441 | outputFile "$WRAPPER_TEST_CMD"
442 | WRAPPER_TEST_CMD=""
443 | fi
444 | fi
445 | if [ -z "$WRAPPER_TEST_CMD" ]
446 | then
447 | eval echo `gettext 'Unable to locate any of the following binaries:'`
448 | outputFile "$WRAPPER_CMD-$DIST_OS-$DIST_ARCH-$DIST_BITS"
449 | if [ ! "$DIST_BITS" = "32" ]
450 | then
451 | outputFile "$WRAPPER_CMD-$DIST_OS-$DIST_ARCH-32"
452 | fi
453 | outputFile "$WRAPPER_CMD"
454 |
455 | exit 1
456 | fi
457 |
458 |
459 | # Build the nice clause
460 | if [ "X$PRIORITY" = "X" ]
461 | then
462 | CMDNICE=""
463 | else
464 | CMDNICE="nice -$PRIORITY"
465 | fi
466 |
467 | # Build the anchor file clause.
468 | if [ "X$IGNORE_SIGNALS" = "X" ]
469 | then
470 | ANCHORPROP=
471 | IGNOREPROP=
472 | else
473 | ANCHORPROP=wrapper.anchorfile=\"$ANCHORFILE\"
474 | IGNOREPROP=wrapper.ignore_signals=TRUE
475 | fi
476 |
477 | # Build the status file clause.
478 | if [ "X$DETAIL_STATUS$WAIT_FOR_STARTED_STATUS" = "X" ]
479 | then
480 | STATUSPROP=
481 | else
482 | STATUSPROP="wrapper.statusfile=\"$STATUSFILE\" wrapper.java.statusfile=\"$JAVASTATUSFILE\""
483 | fi
484 |
485 | # Build the command file clause.
486 | if [ -n "$PAUSABLE" ]
487 | then
488 | COMMANDPROP="wrapper.commandfile=\"$COMMANDFILE\" wrapper.pausable=TRUE"
489 | else
490 | COMMANDPROP=
491 | fi
492 |
493 | if [ ! -n "$WAIT_FOR_STARTED_STATUS" ]
494 | then
495 | WAIT_FOR_STARTED_STATUS=true
496 | fi
497 |
498 | if [ $WAIT_FOR_STARTED_STATUS = true ] ; then
499 | DETAIL_STATUS=true
500 | fi
501 |
502 |
503 | # Build the lock file clause. Only create a lock file if the lock directory exists on this platform.
504 | LOCKPROP=
505 | if [ -d $LOCKDIR ]
506 | then
507 | if [ -w $LOCKDIR ]
508 | then
509 | LOCKPROP=wrapper.lockfile=\"$LOCKFILE\"
510 | fi
511 | fi
512 |
513 | prepAdditionalParams() {
514 | ADDITIONAL_PARA=""
515 | if [ -n "$PASS_THROUGH" ] ; then
516 | ADDITIONAL_PARA="--"
517 | fi
518 | while [ -n "$1" ] ; do
519 | ADDITIONAL_PARA="$ADDITIONAL_PARA \"$1\""
520 | shift
521 | done
522 | }
523 |
524 | checkUser() {
525 | # $1 touchLock flag
526 | # $2.. [command] args
527 |
528 | # Check the configured user. If necessary rerun this script as the desired user.
529 | if [ "X$RUN_AS_USER" != "X" ]
530 | then
531 | # Resolve the location of the 'id' command
532 | IDEXE="/usr/xpg4/bin/id"
533 | if [ ! -x "$IDEXE" ]
534 | then
535 | IDEXE="/usr/bin/id"
536 | if [ ! -x "$IDEXE" ]
537 | then
538 | eval echo `gettext 'Unable to locate "id".'`
539 | eval echo `gettext 'Please report this message along with the location of the command on your system.'`
540 | exit 1
541 | fi
542 | fi
543 |
544 | if [ "`$IDEXE -u -n`" = "$RUN_AS_USER" ]
545 | then
546 | # Already running as the configured user. Avoid password prompts by not calling su.
547 | RUN_AS_USER=""
548 | fi
549 | fi
550 | if [ "X$RUN_AS_USER" != "X" ]
551 | then
552 | # If LOCKPROP and $RUN_AS_USER are defined then the new user will most likely not be
553 | # able to create the lock file. The Wrapper will be able to update this file once it
554 | # is created but will not be able to delete it on shutdown. If $1 is set then
555 | # the lock file should be created for the current command
556 | if [ "X$LOCKPROP" != "X" ]
557 | then
558 | if [ "X$1" != "X" ]
559 | then
560 | # Resolve the primary group
561 | RUN_AS_GROUP=`groups $RUN_AS_USER | awk '{print $3}' | tail -1`
562 | if [ "X$RUN_AS_GROUP" = "X" ]
563 | then
564 | RUN_AS_GROUP=$RUN_AS_USER
565 | fi
566 | touch $LOCKFILE
567 | chown $RUN_AS_USER:$RUN_AS_GROUP $LOCKFILE
568 | fi
569 | fi
570 |
571 | # Still want to change users, recurse. This means that the user will only be
572 | # prompted for a password once. Variables shifted by 1
573 | shift
574 |
575 | # Wrap the parameters so they can be passed.
576 | ADDITIONAL_PARA=""
577 | while [ -n "$1" ] ; do
578 | ADDITIONAL_PARA="$ADDITIONAL_PARA \"$1\""
579 | shift
580 | done
581 |
582 | # Set ulimit if specified.
583 | if [ "X$ULIMIT_N" != "X" ]
584 | then
585 | ulimit -n $ULIMIT_N
586 | fi
587 |
588 | # Use "runuser" if this exists. runuser should be used on RedHat in preference to su.
589 | #
590 | if test -f "/sbin/runuser"
591 | then
592 | /sbin/runuser - $RUN_AS_USER -c "\"$REALPATH\" $ADDITIONAL_PARA"
593 | else
594 | su - $RUN_AS_USER -c "\"$REALPATH\" $ADDITIONAL_PARA"
595 | fi
596 | RUN_AS_USER_EXITCODE=$?
597 | # Now that we are the original user again, we may need to clean up the lock file.
598 | if [ "X$LOCKPROP" != "X" ]
599 | then
600 | getpid
601 | if [ "X$pid" = "X" ]
602 | then
603 | # Wrapper is not running so make sure the lock file is deleted.
604 | if [ -f "$LOCKFILE" ]
605 | then
606 | rm "$LOCKFILE"
607 | fi
608 | fi
609 | fi
610 |
611 | exit $RUN_AS_USER_EXITCODE
612 | fi
613 | }
614 |
615 | getpid() {
616 | pid=""
617 | if [ -f "$PIDFILE" ]
618 | then
619 | if [ -r "$PIDFILE" ]
620 | then
621 | pid=`cat "$PIDFILE"`
622 | if [ "X$pid" != "X" ]
623 | then
624 | # It is possible that 'a' process with the pid exists but that it is not the
625 | # correct process. This can happen in a number of cases, but the most
626 | # common is during system startup after an unclean shutdown.
627 | # The ps statement below looks for the specific wrapper command running as
628 | # the pid. If it is not found then the pid file is considered to be stale.
629 | case "$DIST_OS" in
630 | 'freebsd')
631 | pidtest=`$PSEXE -p $pid -o args | tail -1`
632 | if [ "X$pidtest" = "XCOMMAND" ]
633 | then
634 | pidtest=""
635 | fi
636 | ;;
637 | 'macosx')
638 | pidtest=`$PSEXE -ww -p $pid -o command | grep -F "$WRAPPER_CMD" | tail -1`
639 | ;;
640 | 'solaris')
641 | if [ -f "/usr/bin/pargs" ]
642 | then
643 | pidtest=`pargs $pid | fgrep "$WRAPPER_CMD" | tail -1`
644 | else
645 | case "$PSEXE" in
646 | '/usr/ucb/ps')
647 | pidtest=`$PSEXE -auxww $pid | fgrep "$WRAPPER_CMD" | tail -1`
648 | ;;
649 | '/usr/bin/ps')
650 | TRUNCATED_CMD=`$PSEXE -o comm -p $pid | tail -1`
651 | COUNT=`echo $TRUNCATED_CMD | wc -m`
652 | COUNT=`echo ${COUNT}`
653 | COUNT=`expr $COUNT - 1`
654 | TRUNCATED_CMD=`echo $WRAPPER_CMD | cut -c1-$COUNT`
655 | pidtest=`$PSEXE -o comm -p $pid | fgrep "$TRUNCATED_CMD" | tail -1`
656 | ;;
657 | '/bin/ps')
658 | TRUNCATED_CMD=`$PSEXE -o comm -p $pid | tail -1`
659 | COUNT=`echo $TRUNCATED_CMD | wc -m`
660 | COUNT=`echo ${COUNT}`
661 | COUNT=`expr $COUNT - 1`
662 | TRUNCATED_CMD=`echo $WRAPPER_CMD | cut -c1-$COUNT`
663 | pidtest=`$PSEXE -o comm -p $pid | fgrep "$TRUNCATED_CMD" | tail -1`
664 | ;;
665 | *)
666 | echo "Unsupported ps command $PSEXE"
667 | exit 1
668 | ;;
669 | esac
670 | fi
671 | ;;
672 | 'hpux')
673 | pidtest=`$PSEXE -p $pid -x -o args | grep -F "$WRAPPER_CMD" | tail -1`
674 | ;;
675 | *)
676 | pidtest=`$PSEXE -p $pid -o args | grep -F "$WRAPPER_CMD" | tail -1`
677 | ;;
678 | esac
679 |
680 | if [ "X$pidtest" = "X" ]
681 | then
682 | # This is a stale pid file.
683 | rm -f "$PIDFILE"
684 | eval echo `gettext 'Removed stale pid file: $PIDFILE'`
685 | pid=""
686 | fi
687 | fi
688 | else
689 | eval echo `gettext 'Cannot read $PIDFILE.'`
690 | exit 1
691 | fi
692 | fi
693 | }
694 |
695 | getstatus() {
696 | STATUS=
697 | if [ -f "$STATUSFILE" ]
698 | then
699 | if [ -r "$STATUSFILE" ]
700 | then
701 | STATUS=`cat "$STATUSFILE"`
702 | fi
703 | fi
704 | if [ "X$STATUS" = "X" ]
705 | then
706 | STATUS="Unknown"
707 | fi
708 |
709 | JAVASTATUS=
710 | if [ -f "$JAVASTATUSFILE" ]
711 | then
712 | if [ -r "$JAVASTATUSFILE" ]
713 | then
714 | JAVASTATUS=`cat "$JAVASTATUSFILE"`
715 | fi
716 | fi
717 | if [ "X$JAVASTATUS" = "X" ]
718 | then
719 | JAVASTATUS="Unknown"
720 | fi
721 | }
722 |
723 | testpid() {
724 | case "$DIST_OS" in
725 | 'solaris')
726 | case "$PSEXE" in
727 | '/usr/ucb/ps')
728 | pid=`$PSEXE $pid | grep $pid | grep -v grep | awk '{print $1}' | tail -1`
729 | ;;
730 | '/usr/bin/ps')
731 | pid=`$PSEXE -p $pid | grep $pid | grep -v grep | awk '{print $1}' | tail -1`
732 | ;;
733 | '/bin/ps')
734 | pid=`$PSEXE -p $pid | grep $pid | grep -v grep | awk '{print $1}' | tail -1`
735 | ;;
736 | *)
737 | echo "Unsupported ps command $PSEXE"
738 | exit 1
739 | ;;
740 | esac
741 | ;;
742 | *)
743 | pid=`$PSEXE -p $pid | grep $pid | grep -v grep | awk '{print $1}' | tail -1` 2>/dev/null
744 | ;;
745 | esac
746 | if [ "X$pid" = "X" ]
747 | then
748 | # Process is gone so remove the pid file.
749 | rm -f "$PIDFILE"
750 | pid=""
751 | fi
752 | }
753 |
754 | launchdtrap() {
755 | stopit
756 | exit
757 | }
758 |
759 | waitforwrapperstop() {
760 | getpid
761 | while [ "X$pid" != "X" ] ; do
762 | sleep 1
763 | getpid
764 | done
765 | }
766 |
767 | launchinternal() {
768 | getpid
769 | trap launchdtrap TERM
770 | if [ "X$pid" = "X" ]
771 | then
772 | prepAdditionalParams "$@"
773 |
774 | # The string passed to eval must handles spaces in paths correctly.
775 | COMMAND_LINE="$CMDNICE \"$WRAPPER_CMD\" \"$WRAPPER_CONF\" wrapper.syslog.ident=\"$APP_NAME\" wrapper.pidfile=\"$PIDFILE\" wrapper.name=\"$APP_NAME\" wrapper.displayname=\"$APP_LONG_NAME\" wrapper.daemonize=TRUE $ANCHORPROP $IGNOREPROP $STATUSPROP $COMMANDPROP $LOCKPROP wrapper.script.version=3.5.14 $ADDITIONAL_PARA"
776 | eval $COMMAND_LINE
777 | else
778 | eval echo `gettext '$APP_LONG_NAME is already running.'`
779 | exit 1
780 | fi
781 | # launchd expects that this script stay up and running so we need to do our own monitoring of the Wrapper process.
782 | if [ $WAIT_FOR_STARTED_STATUS = true ]
783 | then
784 | waitforwrapperstop
785 | fi
786 | }
787 |
788 | console() {
789 | eval echo `gettext 'Running $APP_LONG_NAME...'`
790 | getpid
791 | if [ "X$pid" = "X" ]
792 | then
793 | trap '' 3
794 |
795 | prepAdditionalParams "$@"
796 |
797 | # The string passed to eval must handles spaces in paths correctly.
798 | COMMAND_LINE="$CMDNICE \"$WRAPPER_CMD\" \"$WRAPPER_CONF\" wrapper.syslog.ident=\"$APP_NAME\" wrapper.pidfile=\"$PIDFILE\" wrapper.name=\"$APP_NAME\" wrapper.displayname=\"$APP_LONG_NAME\" $ANCHORPROP $STATUSPROP $COMMANDPROP $LOCKPROP wrapper.script.version=3.5.14 $ADDITIONAL_PARA"
799 | eval $COMMAND_LINE
800 | else
801 | eval echo `gettext '$APP_LONG_NAME is already running.'`
802 | exit 1
803 | fi
804 | }
805 |
806 | waitforjavastartup() {
807 | getstatus
808 | eval echo $ECHOOPT `gettext 'Waiting for $APP_LONG_NAME...'`
809 |
810 | # Wait until the timeout or we have something besides Unknown.
811 | counter=15
812 | while [ "$JAVASTATUS" = "Unknown" -a $counter -gt 0 -a -n "$JAVASTATUS" ] ; do
813 | echo $ECHOOPT"."
814 | sleep 1
815 | getstatus
816 | counter=`expr $counter - 1`
817 | done
818 |
819 | if [ -n "$WAIT_FOR_STARTED_TIMEOUT" ] ; then
820 | counter=$WAIT_FOR_STARTED_TIMEOUT
821 | else
822 | counter=120
823 | fi
824 | while [ "$JAVASTATUS" != "STARTED" -a "$JAVASTATUS" != "Unknown" -a $counter -gt 0 -a -n "$JAVASTATUS" ] ; do
825 | echo $ECHOOPT"."
826 | sleep 1
827 | getstatus
828 | counter=`expr $counter - 1`
829 | done
830 | if [ "X$ECHOOPT" != "X" ] ; then
831 | echo ""
832 | fi
833 | }
834 |
835 | startwait() {
836 | if [ $WAIT_FOR_STARTED_STATUS = true ]
837 | then
838 | waitforjavastartup
839 | fi
840 | # Sleep for a few seconds to allow for intialization if required
841 | # then test to make sure we're still running.
842 | #
843 | i=0
844 | while [ $i -lt $WAIT_AFTER_STARTUP ]
845 | do
846 | sleep 1
847 | echo $ECHOOPT"."
848 | i=`expr $i + 1`
849 | done
850 | if [ $WAIT_AFTER_STARTUP -gt 0 -o $WAIT_FOR_STARTED_STATUS = true ]
851 | then
852 | getpid
853 | if [ "X$pid" = "X" ]
854 | then
855 | eval echo `gettext ' WARNING: $APP_LONG_NAME may have failed to start.'`
856 | exit 1
857 | else
858 | eval echo `gettext ' running: PID:$pid'`
859 | fi
860 | else
861 | echo ""
862 | fi
863 | }
864 |
865 | macosxstart() {
866 | # The daemon has been installed.
867 | eval echo `gettext 'Starting $APP_LONG_NAME. Detected Mac OSX and installed launchd daemon.'`
868 | if [ `id | sed 's/^uid=//;s/(.*$//'` != "0" ] ; then
869 | eval echo `gettext 'Must be root to perform this action.'`
870 | exit 1
871 | fi
872 |
873 | getpid
874 | if [ "X$pid" != "X" ] ; then
875 | eval echo `gettext '$APP_LONG_NAME is already running.'`
876 | exit 1
877 | fi
878 |
879 | # If the daemon was just installed, it may not be loaded.
880 | LOADED_PLIST=`launchctl list | grep ${APP_PLIST_BASE}`
881 | if [ "X${LOADED_PLIST}" = "X" ] ; then
882 | launchctl load /Library/LaunchDaemons/${APP_PLIST}
883 | fi
884 | # If launchd is set to run the daemon already at Load, we don't need to call start
885 | getpid
886 | if [ "X$pid" == "X" ] ; then
887 | launchctl start ${APP_PLIST_BASE}
888 | fi
889 |
890 | startwait
891 | }
892 |
893 | upstartstart() {
894 | # The daemon has been installed.
895 | eval echo `gettext 'Starting $APP_LONG_NAME. Detected Linux and installed upstart.'`
896 | if [ `id | sed 's/^uid=//;s/(.*$//'` != "0" ] ; then
897 | eval echo `gettext 'Must be root to perform this action.'`
898 | exit 1
899 | fi
900 |
901 | getpid
902 | if [ "X$pid" != "X" ] ; then
903 | eval echo `gettext '$APP_LONG_NAME is already running.'`
904 | exit 1
905 | fi
906 |
907 | /sbin/start ${APP_NAME}
908 |
909 | startwait
910 | }
911 |
912 | start() {
913 | eval echo `gettext 'Starting $APP_LONG_NAME...'`
914 | getpid
915 | if [ "X$pid" = "X" ]
916 | then
917 | prepAdditionalParams "$@"
918 |
919 | # The string passed to eval must handles spaces in paths correctly.
920 | COMMAND_LINE="$CMDNICE \"$WRAPPER_CMD\" \"$WRAPPER_CONF\" wrapper.syslog.ident=\"$APP_NAME\" wrapper.pidfile=\"$PIDFILE\" wrapper.name=\"$APP_NAME\" wrapper.displayname=\"$APP_LONG_NAME\" wrapper.daemonize=TRUE $ANCHORPROP $IGNOREPROP $STATUSPROP $COMMANDPROP $LOCKPROP wrapper.script.version=3.5.14 $ADDITIONAL_PARA"
921 | eval $COMMAND_LINE
922 | else
923 | eval echo `gettext '$APP_LONG_NAME is already running.'`
924 | exit 1
925 | fi
926 |
927 | startwait
928 | }
929 |
930 | stopit() {
931 | # $1 exit if down flag
932 |
933 | eval echo `gettext 'Stopping $APP_LONG_NAME...'`
934 | getpid
935 | if [ "X$pid" = "X" ]
936 | then
937 | eval echo `gettext '$APP_LONG_NAME was not running.'`
938 | if [ "X$1" = "X1" ]
939 | then
940 | exit 1
941 | fi
942 | else
943 | if [ "X$IGNORE_SIGNALS" = "X" ]
944 | then
945 | # Running so try to stop it.
946 | kill $pid
947 | if [ $? -ne 0 ]
948 | then
949 | # An explanation for the failure should have been given
950 | eval echo `gettext 'Unable to stop $APP_LONG_NAME.'`
951 | exit 1
952 | fi
953 | else
954 | rm -f "$ANCHORFILE"
955 | if [ -f "$ANCHORFILE" ]
956 | then
957 | # An explanation for the failure should have been given
958 | eval echo `gettext 'Unable to stop $APP_LONG_NAME.'`
959 | exit 1
960 | fi
961 | fi
962 |
963 | # We can not predict how long it will take for the wrapper to
964 | # actually stop as it depends on settings in wrapper.conf.
965 | # Loop until it does.
966 | savepid=$pid
967 | CNT=0
968 | TOTCNT=0
969 | while [ "X$pid" != "X" ]
970 | do
971 | # Show a waiting message every 5 seconds.
972 | if [ "$CNT" -lt "5" ]
973 | then
974 | CNT=`expr $CNT + 1`
975 | else
976 | eval echo `gettext 'Waiting for $APP_LONG_NAME to exit...'`
977 | CNT=0
978 | fi
979 | TOTCNT=`expr $TOTCNT + 1`
980 |
981 | sleep 1
982 |
983 | testpid
984 | done
985 |
986 | pid=$savepid
987 | testpid
988 | if [ "X$pid" != "X" ]
989 | then
990 | eval echo `gettext 'Failed to stop $APP_LONG_NAME.'`
991 | exit 1
992 | else
993 | eval echo `gettext 'Stopped $APP_LONG_NAME.'`
994 | fi
995 | fi
996 | }
997 |
998 | pause() {
999 | eval echo `gettext 'Pausing $APP_LONG_NAME.'`
1000 | }
1001 |
1002 | resume() {
1003 | eval echo `gettext 'Resuming $APP_LONG_NAME.'`
1004 | }
1005 |
1006 | status() {
1007 | getpid
1008 | if [ "X$pid" = "X" ]
1009 | then
1010 | eval echo `gettext '$APP_LONG_NAME is not running.'`
1011 | exit 1
1012 | else
1013 | if [ "X$DETAIL_STATUS" = "X" ]
1014 | then
1015 | eval echo `gettext '$APP_LONG_NAME is running: PID:$pid'`
1016 | else
1017 | getstatus
1018 | eval echo `gettext '$APP_LONG_NAME is running: PID:$pid, Wrapper:$STATUS, Java:$JAVASTATUS'`
1019 | fi
1020 | exit 0
1021 | fi
1022 | }
1023 |
1024 | installUpstart() {
1025 | eval echo `gettext ' Installing the $APP_LONG_NAME daemon using upstart..'`
1026 | if [ -f "${REALDIR}/${APP_NAME}.install" ] ; then
1027 | eval echo `gettext ' a custom upstart conf file ${APP_NAME}.install found'`
1028 | cp "${REALDIR}/${APP_NAME}.install" "/etc/init/${APP_NAME}.conf"
1029 | else
1030 | eval echo `gettext ' creating default upstart conf file..'`
1031 | echo "# ${APP_NAME} - ${APP_LONG_NAME}" > "/etc/init/${APP_NAME}.conf"
1032 | echo "description \"${APP_LONG_NAME}\"" >> "/etc/init/${APP_NAME}.conf"
1033 | echo "author \"Tanuki Software Ltd. \"" >> "/etc/init/${APP_NAME}.conf"
1034 | echo "start on runlevel [2345]" >> "/etc/init/${APP_NAME}.conf"
1035 | echo "stop on runlevel [!2345]" >> "/etc/init/${APP_NAME}.conf"
1036 | echo "env LANG=${LANG}" >> "/etc/init/${APP_NAME}.conf"
1037 | echo "exec \"${REALPATH}\" upstartinternal" >> "/etc/init/${APP_NAME}.conf"
1038 | fi
1039 | }
1040 |
1041 | installdaemon() {
1042 | if [ `id | sed 's/^uid=//;s/(.*$//'` != "0" ] ; then
1043 | eval echo `gettext 'Must be root to perform this action.'`
1044 | exit 1
1045 | else
1046 | APP_NAME_LOWER=`echo "$APP_NAME" | $TREXE "[A-Z]" "[a-z]"`
1047 | if [ "$DIST_OS" = "solaris" ] ; then
1048 | eval echo `gettext 'Detected Solaris:'`
1049 | if [ -f /etc/init.d/$APP_NAME ] ; then
1050 | eval echo `gettext ' The $APP_LONG_NAME daemon is already installed.'`
1051 | exit 1
1052 | else
1053 | eval echo `gettext ' Installing the $APP_LONG_NAME daemon..'`
1054 | ln -s "$REALPATH" "/etc/init.d/$APP_NAME"
1055 | ln -s "/etc/init.d/$APP_NAME" "/etc/rc3.d/K20$APP_NAME_LOWER"
1056 | ln -s "/etc/init.d/$APP_NAME" "/etc/rc3.d/S20$APP_NAME_LOWER"
1057 | fi
1058 | elif [ "$DIST_OS" = "linux" ] ; then
1059 | if [ -f /etc/redhat-release -o -f /etc/redhat_version -o -f /etc/fedora-release ] ; then
1060 | eval echo `gettext 'Detected RHEL or Fedora:'`
1061 | if [ -f "/etc/init.d/$APP_NAME" -o -f "/etc/init/${APP_NAME}.conf" ] ; then
1062 | eval echo `gettext ' The $APP_LONG_NAME daemon is already installed.'`
1063 | exit 1
1064 | else
1065 | if [ -n "$USE_UPSTART" -a -d "/etc/init" ] ; then
1066 | installUpstart
1067 | else
1068 | eval echo `gettext ' Installing the $APP_LONG_NAME daemon..'`
1069 | ln -s "$REALPATH" "/etc/init.d/$APP_NAME"
1070 | /sbin/chkconfig --add "$APP_NAME"
1071 | /sbin/chkconfig "$APP_NAME" on
1072 | fi
1073 | fi
1074 | elif [ -f /etc/SuSE-release ] ; then
1075 | eval echo `gettext 'Detected SuSE or SLES:'`
1076 | if [ -f "/etc/init.d/$APP_NAME" ] ; then
1077 | eval echo `gettext ' The $APP_LONG_NAME daemon is already installed.'`
1078 | exit 1
1079 | else
1080 | eval echo `gettext ' Installing the $APP_LONG_NAME daemon..'`
1081 | ln -s "$REALPATH" "/etc/init.d/$APP_NAME"
1082 | insserv "/etc/init.d/$APP_NAME"
1083 | fi
1084 | elif [ -f /etc/lsb-release ] ; then
1085 | eval echo `gettext 'Detected Ubuntu:'`
1086 | if [ -f "/etc/init.d/$APP_NAME" -o -f "/etc/init/${APP_NAME}.conf" ] ; then
1087 | eval echo `gettext ' The $APP_LONG_NAME daemon is already installed.'`
1088 | exit 1
1089 | else
1090 | if [ -n "$USE_UPSTART" -a -d "/etc/init" ] ; then
1091 | installUpstart
1092 | else
1093 | eval echo `gettext ' Installing the $APP_LONG_NAME daemon using init.d..'`
1094 | ln -s "$REALPATH" "/etc/init.d/$APP_NAME"
1095 | update-rc.d "$APP_NAME" defaults
1096 | fi
1097 | fi
1098 | else
1099 | eval echo `gettext 'Detected Linux:'`
1100 | if [ -f "/etc/init.d/$APP_NAME" ] ; then
1101 | eval echo `gettext ' The $APP_LONG_NAME daemon is already installed.'`
1102 | exit 1
1103 | else
1104 | eval echo `gettext ' Installing the $APP_LONG_NAME daemon..'`
1105 | ln -s "$REALPATH" /etc/init.d/$APP_NAME
1106 | ln -s "/etc/init.d/$APP_NAME" "/etc/rc3.d/K20$APP_NAME_LOWER"
1107 | ln -s "/etc/init.d/$APP_NAME" "/etc/rc3.d/S20$APP_NAME_LOWER"
1108 | ln -s "/etc/init.d/$APP_NAME" "/etc/rc5.d/S20$APP_NAME_LOWER"
1109 | ln -s "/etc/init.d/$APP_NAME" "/etc/rc5.d/K20$APP_NAME_LOWER"
1110 | fi
1111 | fi
1112 | elif [ "$DIST_OS" = "hpux" ] ; then
1113 | eval echo `gettext 'Detected HP-UX:'`
1114 | if [ -f "/sbin/init.d/$APP_NAME" ] ; then
1115 | eval echo `gettext ' The $APP_LONG_NAME daemon is already installed.'`
1116 | exit 1
1117 | else
1118 | eval echo `gettext ' Installing the $APP_LONG_NAME daemon..'`
1119 | ln -s "$REALPATH" "/sbin/init.d/$APP_NAME"
1120 | ln -s "/sbin/init.d/$APP_NAME" "/sbin/rc3.d/K20$APP_NAME_LOWER"
1121 | ln -s "/sbin/init.d/$APP_NAME" "/sbin/rc3.d/S20$APP_NAME_LOWER"
1122 | fi
1123 | elif [ "$DIST_OS" = "aix" ] ; then
1124 | eval echo `gettext 'Detected AIX:'`
1125 | if [ -f "/etc/rc.d/init.d/$APP_NAME" ] ; then
1126 | eval echo `gettext ' The $APP_LONG_NAME daemon is already installed as rc.d script.'`
1127 | exit 1
1128 | elif [ -n "`/usr/sbin/lsitab $APP_NAME`" -a -n "`/usr/bin/lssrc -S -s $APP_NAME`" ] ; then
1129 | eval echo `gettext ' The $APP_LONG_NAME daemon is already installed as SRC service.'`
1130 | exit 1
1131 | else
1132 | eval echo `gettext ' Installing the $APP_LONG_NAME daemon..'`
1133 | if [ -n "`/usr/sbin/lsitab install_assist`" ] ; then
1134 | eval echo `gettext ' The task /usr/sbin/install_assist was found in the inittab, this might cause problems for all subsequent tasks to launch at this process is known to block the init task. Please make sure this task is not needed anymore and remove/deactivate it.'`
1135 | fi
1136 | /usr/bin/mkssys -s "$APP_NAME" -p "$REALPATH" -a "launchdinternal" -u 0 -f 9 -n 15 -S
1137 | /usr/sbin/mkitab "$APP_NAME":2:once:"/usr/bin/startsrc -s \"${APP_NAME}\" >/dev/console 2>&1"
1138 |
1139 | fi
1140 | elif [ "$DIST_OS" = "freebsd" ] ; then
1141 | eval echo `gettext 'Detected FreeBSD:'`
1142 | if [ -f "/etc/rc.d/$APP_NAME" ] ; then
1143 | eval echo `gettext ' The $APP_LONG_NAME daemon is already installed.'`
1144 | exit 1
1145 | else
1146 | eval echo `gettext ' Installing the $APP_LONG_NAME daemon..'`
1147 | sed -i .bak "/${APP_NAME}_enable=\"YES\"/d" /etc/rc.conf
1148 | if [ -f "${REALDIR}/${APP_NAME}.install" ] ; then
1149 | ln -s "${REALDIR}/${APP_NAME}.install" "/etc/rc.d/$APP_NAME"
1150 | else
1151 | echo '#!/bin/sh' > "/etc/rc.d/$APP_NAME"
1152 | echo "#" >> "/etc/rc.d/$APP_NAME"
1153 | echo "# PROVIDE: $APP_NAME" >> "/etc/rc.d/$APP_NAME"
1154 | echo "# REQUIRE: NETWORKING" >> "/etc/rc.d/$APP_NAME"
1155 | echo "# KEYWORD: shutdown" >> "/etc/rc.d/$APP_NAME"
1156 | echo ". /etc/rc.subr" >> "/etc/rc.d/$APP_NAME"
1157 | echo "name=\"$APP_NAME\"" >> "/etc/rc.d/$APP_NAME"
1158 | echo "rcvar=\`set_rcvar\`" >> "/etc/rc.d/$APP_NAME"
1159 | echo "command=\"${REALPATH}\"" >> "/etc/rc.d/$APP_NAME"
1160 | echo 'start_cmd="${name}_start"' >> "/etc/rc.d/$APP_NAME"
1161 | echo 'load_rc_config $name' >> "/etc/rc.d/$APP_NAME"
1162 | echo 'status_cmd="${name}_status"' >> "/etc/rc.d/$APP_NAME"
1163 | echo 'stop_cmd="${name}_stop"' >> "/etc/rc.d/$APP_NAME"
1164 | echo "${APP_NAME}_status() {" >> "/etc/rc.d/$APP_NAME"
1165 | echo '${command} status' >> "/etc/rc.d/$APP_NAME"
1166 | echo '}' >> "/etc/rc.d/$APP_NAME"
1167 | echo "${APP_NAME}_stop() {" >> "/etc/rc.d/$APP_NAME"
1168 | echo '${command} stop' >> "/etc/rc.d/$APP_NAME"
1169 | echo '}' >> "/etc/rc.d/$APP_NAME"
1170 | echo "${APP_NAME}_start() {" >> "/etc/rc.d/$APP_NAME"
1171 | echo '${command} start' >> "/etc/rc.d/$APP_NAME"
1172 | echo '}' >> "/etc/rc.d/$APP_NAME"
1173 | echo 'run_rc_command "$1"' >> "/etc/rc.d/$APP_NAME"
1174 | fi
1175 | echo "${APP_NAME}_enable=\"YES\"" >> /etc/rc.conf
1176 | chmod 555 "/etc/rc.d/$APP_NAME"
1177 | fi
1178 | elif [ "$DIST_OS" = "macosx" ] ; then
1179 | eval echo `gettext 'Detected Mac OSX:'`
1180 | if [ -f "/Library/LaunchDaemons/${APP_PLIST}" ] ; then
1181 | eval echo `gettext ' The $APP_LONG_NAME daemon is already installed.'`
1182 | exit 1
1183 | else
1184 | eval echo `gettext ' Installing the $APP_LONG_NAME daemon..'`
1185 | if [ -f "${REALDIR}/${APP_PLIST}" ] ; then
1186 | ln -s "${REALDIR}/${APP_PLIST}" "/Library/LaunchDaemons/${APP_PLIST}"
1187 | else
1188 | echo "" > "/Library/LaunchDaemons/${APP_PLIST}"
1189 | echo "> "/Library/LaunchDaemons/${APP_PLIST}"
1190 | echo "\"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">" >> "/Library/LaunchDaemons/${APP_PLIST}"
1191 | echo "" >> "/Library/LaunchDaemons/${APP_PLIST}"
1192 | echo " " >> "/Library/LaunchDaemons/${APP_PLIST}"
1193 | echo " Label" >> "/Library/LaunchDaemons/${APP_PLIST}"
1194 | echo " ${APP_PLIST_BASE}" >> "/Library/LaunchDaemons/${APP_PLIST}"
1195 | echo " ProgramArguments" >> "/Library/LaunchDaemons/${APP_PLIST}"
1196 | echo " " >> "/Library/LaunchDaemons/${APP_PLIST}"
1197 | echo " ${REALPATH}" >> "/Library/LaunchDaemons/${APP_PLIST}"
1198 | echo " launchdinternal" >> "/Library/LaunchDaemons/${APP_PLIST}"
1199 | echo " " >> "/Library/LaunchDaemons/${APP_PLIST}"
1200 | echo " OnDemand" >> "/Library/LaunchDaemons/${APP_PLIST}"
1201 | echo " " >> "/Library/LaunchDaemons/${APP_PLIST}"
1202 | echo " RunAtLoad" >> "/Library/LaunchDaemons/${APP_PLIST}"
1203 | echo " " >> "/Library/LaunchDaemons/${APP_PLIST}"
1204 | if [ "X$RUN_AS_USER" != "X" ] ; then
1205 | echo " UserName" >> "/Library/LaunchDaemons/${APP_PLIST}"
1206 | echo " ${RUN_AS_USER}" >> "/Library/LaunchDaemons/${APP_PLIST}"
1207 | fi
1208 | echo " " >> "/Library/LaunchDaemons/${APP_PLIST}"
1209 | echo "" >> "/Library/LaunchDaemons/${APP_PLIST}"
1210 | fi
1211 | chmod 555 "/Library/LaunchDaemons/${APP_PLIST}"
1212 | fi
1213 | elif [ "$DIST_OS" = "zos" ] ; then
1214 | eval echo `gettext 'Detected z/OS:'`
1215 | if [ -f /etc/rc.bak ] ; then
1216 | eval echo `gettext ' The $APP_LONG_NAME daemon is already installed.'`
1217 | exit 1
1218 | else
1219 | eval echo `gettext ' Installing the $APP_LONG_NAME daemon..'`
1220 | cp /etc/rc /etc/rc.bak
1221 | sed "s:echo /etc/rc script executed, \`date\`::g" /etc/rc.bak > /etc/rc
1222 | echo "_BPX_JOBNAME='${APP_NAME}' \"${REALDIR}/${APP_NAME}\" start" >>/etc/rc
1223 | echo '/etc/rc script executed, `date`' >>/etc/rc
1224 | fi
1225 | else
1226 | eval echo `gettext 'Install not currently supported for $DIST_OS'`
1227 | exit 1
1228 | fi
1229 | fi
1230 | }
1231 |
1232 | removedaemon() {
1233 | if [ `id | sed 's/^uid=//;s/(.*$//'` != "0" ] ; then
1234 | eval echo `gettext 'Must be root to perform this action.'`
1235 | exit 1
1236 | else
1237 | APP_NAME_LOWER=`echo "$APP_NAME" | $TREXE "[A-Z]" "[a-z]"`
1238 | if [ "$DIST_OS" = "solaris" ] ; then
1239 | eval echo `gettext 'Detected Solaris:'`
1240 | if [ -f "/etc/init.d/$APP_NAME" ] ; then
1241 | stopit "0"
1242 | eval echo `gettext ' Removing $APP_LONG_NAME daemon...'`
1243 | for i in "/etc/rc3.d/S20$APP_NAME_LOWER" "/etc/rc3.d/K20$APP_NAME_LOWER" "/etc/init.d/$APP_NAME"
1244 | do
1245 | rm -f $i
1246 | done
1247 | else
1248 | eval echo `gettext ' The $APP_LONG_NAME daemon is not currently installed.'`
1249 | exit 1
1250 | fi
1251 | elif [ "$DIST_OS" = "linux" ] ; then
1252 | if [ -f /etc/redhat-release -o -f /etc/redhat_version -o -f /etc/fedora-release ] ; then
1253 | eval echo `gettext 'Detected RHEL or Fedora:'`
1254 | if [ -f "/etc/init.d/$APP_NAME" ] ; then
1255 | stopit "0"
1256 | eval echo `gettext ' Removing $APP_LONG_NAME daemon...'`
1257 | /sbin/chkconfig "$APP_NAME" off
1258 | /sbin/chkconfig --del "$APP_NAME"
1259 | rm -f "/etc/init.d/$APP_NAME"
1260 | elif [ -f "/etc/init/${APP_NAME}.conf" ] ; then
1261 | stopit "0"
1262 | eval echo `gettext ' Removing $APP_LONG_NAME daemon from upstart...'`
1263 | rm "/etc/init/${APP_NAME}.conf"
1264 | else
1265 | eval echo `gettext ' The $APP_LONG_NAME daemon is not currently installed.'`
1266 | exit 1
1267 | fi
1268 | elif [ -f /etc/SuSE-release ] ; then
1269 | eval echo `gettext 'Detected SuSE or SLES:'`
1270 | if [ -f "/etc/init.d/$APP_NAME" ] ; then
1271 | stopit "0"
1272 | eval echo `gettext ' Removing $APP_LONG_NAME daemon...'`
1273 | insserv -r "/etc/init.d/$APP_NAME"
1274 | rm -f "/etc/init.d/$APP_NAME"
1275 | else
1276 | eval echo `gettext ' The $APP_LONG_NAME daemon is not currently installed.'`
1277 | exit 1
1278 | fi
1279 | elif [ -f /etc/lsb-release ] ; then
1280 | eval echo `gettext 'Detected Ubuntu:'`
1281 | if [ -f "/etc/init.d/$APP_NAME" ] ; then
1282 | stopit "0"
1283 | eval echo `gettext ' Removing $APP_LONG_NAME daemon from init.d...'`
1284 | update-rc.d -f "$APP_NAME" remove
1285 | rm -f "/etc/init.d/$APP_NAME"
1286 | elif [ -f "/etc/init/${APP_NAME}.conf" ] ; then
1287 | stopit "0"
1288 | eval echo `gettext ' Removing $APP_LONG_NAME daemon from upstart...'`
1289 | rm "/etc/init/${APP_NAME}.conf"
1290 | else
1291 | eval echo `gettext ' The $APP_LONG_NAME daemon is not currently installed.'`
1292 | exit 1
1293 | fi
1294 | else
1295 | eval echo `gettext 'Detected Linux:'`
1296 | if [ -f "/etc/init.d/$APP_NAME" ] ; then
1297 | stopit "0"
1298 | eval echo `gettext ' Removing $APP_LONG_NAME daemon...'`
1299 | for i in "/etc/rc3.d/K20$APP_NAME_LOWER" "/etc/rc5.d/K20$APP_NAME_LOWER" "/etc/rc3.d/S20$APP_NAME_LOWER" "/etc/init.d/$APP_NAME" "/etc/rc5.d/S20$APP_NAME_LOWER"
1300 | do
1301 | rm -f $i
1302 | done
1303 | else
1304 | eval echo `gettext ' The $APP_LONG_NAME daemon is not currently installed.'`
1305 | exit 1
1306 | fi
1307 | fi
1308 | elif [ "$DIST_OS" = "hpux" ] ; then
1309 | eval echo `gettext 'Detected HP-UX:'`
1310 | if [ -f "/sbin/init.d/$APP_NAME" ] ; then
1311 | stopit "0"
1312 | eval echo `gettext ' Removing $APP_LONG_NAME daemon...'`
1313 | for i in "/sbin/rc3.d/K20$APP_NAME_LOWER" "/sbin/rc3.d/S20$APP_NAME_LOWER" "/sbin/init.d/$APP_NAME"
1314 | do
1315 | rm -f $i
1316 | done
1317 | else
1318 | eval echo `gettext ' The $APP_LONG_NAME daemon is not currently installed.'`
1319 | exit 1
1320 | fi
1321 | elif [ "$DIST_OS" = "aix" ] ; then
1322 | eval echo `gettext 'Detected AIX:'`
1323 | if [ -f "/etc/rc.d/init.d/$APP_NAME" -o -n "`/usr/sbin/lsitab $APP_NAME`" -o -n "`/usr/bin/lssrc -S -s $APP_NAME`" ] ; then
1324 | stopit "0"
1325 | eval echo `gettext ' Removing $APP_LONG_NAME daemon...'`
1326 | if [ -f "/etc/rc.d/init.d/$APP_NAME" ] ; then
1327 | for i in "/etc/rc.d/rc2.d/S20$APP_NAME_LOWER" "/etc/rc.d/rc2.d/K20$APP_NAME_LOWER" "/etc/rc.d/init.d/$APP_NAME"
1328 | do
1329 | rm -f $i
1330 | done
1331 | fi
1332 | if [ -n "`/usr/sbin/lsitab $APP_NAME`" -o -n "`/usr/bin/lssrc -S -s $APP_NAME`" ] ; then
1333 | /usr/sbin/rmitab $APP_NAME
1334 | /usr/bin/rmssys -s $APP_NAME
1335 | fi
1336 | else
1337 | eval echo `gettext ' The $APP_LONG_NAME daemon is not currently installed.'`
1338 | exit 1
1339 | fi
1340 | elif [ "$DIST_OS" = "freebsd" ] ; then
1341 | eval echo `gettext 'Detected FreeBSD:'`
1342 | if [ -f "/etc/rc.d/$APP_NAME" ] ; then
1343 | stopit "0"
1344 | eval echo `gettext ' Removing $APP_LONG_NAME daemon...'`
1345 | for i in "/etc/rc.d/$APP_NAME"
1346 | do
1347 | rm -f $i
1348 | done
1349 | sed -i .bak "/${APP_NAME}_enable=\"YES\"/d" /etc/rc.conf
1350 | else
1351 | eval echo `gettext ' The $APP_LONG_NAME daemon is not currently installed.'`
1352 | exit 1
1353 | fi
1354 | elif [ "$DIST_OS" = "macosx" ] ; then
1355 | eval echo `gettext 'Detected Mac OSX:'`
1356 | if [ -f "/Library/LaunchDaemons/${APP_PLIST}" ] ; then
1357 | stopit "0"
1358 | eval echo `gettext ' Removing $APP_LONG_NAME daemon...'`
1359 | # Make sure the plist is installed
1360 | LOADED_PLIST=`launchctl list | grep ${APP_PLIST_BASE}`
1361 | if [ "X${LOADED_PLIST}" != "X" ] ; then
1362 | launchctl unload "/Library/LaunchDaemons/${APP_PLIST}"
1363 | fi
1364 | rm -f "/Library/LaunchDaemons/${APP_PLIST}"
1365 | else
1366 | eval echo `gettext ' The $APP_LONG_NAME daemon is not currently installed.'`
1367 | exit 1
1368 | fi
1369 | elif [ "$DIST_OS" = "zos" ] ; then
1370 | eval echo `gettext 'Detected z/OS:'`
1371 | if [ -f /etc/rc.bak ] ; then
1372 | stopit "0"
1373 | eval echo `gettext ' Removing $APP_LONG_NAME daemon...'`
1374 | cp /etc/rc /etc/rc.bak
1375 | sed "s/_BPX_JOBNAME=\'APP_NAME\'.*//g" /etc/rc.bak > /etc/rc
1376 | rm /etc/rc.bak
1377 | else
1378 | eval echo `gettext ' The $APP_LONG_NAME daemon is not currently installed.'`
1379 | exit 1
1380 | fi
1381 | else
1382 | eval echo `gettext 'Remove not currently supported for $DIST_OS'`
1383 | exit 1
1384 | fi
1385 | fi
1386 | }
1387 |
1388 | dump() {
1389 | eval echo `gettext 'Dumping $APP_LONG_NAME...'`
1390 | getpid
1391 | if [ "X$pid" = "X" ]
1392 | then
1393 | eval echo `gettext '$APP_LONG_NAME was not running.'`
1394 | else
1395 | kill -3 $pid
1396 |
1397 | if [ $? -ne 0 ]
1398 | then
1399 | eval echo `gettext 'Failed to dump $APP_LONG_NAME.'`
1400 | exit 1
1401 | else
1402 | eval echo `gettext 'Dumped $APP_LONG_NAME.'`
1403 | fi
1404 | fi
1405 | }
1406 |
1407 | # Used by HP-UX init scripts.
1408 | startmsg() {
1409 | getpid
1410 | if [ "X$pid" = "X" ]
1411 | then
1412 | eval echo `gettext 'Starting $APP_LONG_NAME... Wrapper:Stopped'`
1413 | else
1414 | if [ "X$DETAIL_STATUS" = "X" ]
1415 | then
1416 | eval echo `gettext 'Starting $APP_LONG_NAME... Wrapper:Running'`
1417 | else
1418 | getstatus
1419 | eval echo `gettext 'Starting $APP_LONG_NAME... Wrapper:$STATUS, Java:$JAVASTATUS'`
1420 | fi
1421 | fi
1422 | }
1423 |
1424 | # Used by HP-UX init scripts.
1425 | stopmsg() {
1426 | getpid
1427 | if [ "X$pid" = "X" ]
1428 | then
1429 | eval echo `gettext 'Stopping $APP_LONG_NAME... Wrapper:Stopped'`
1430 | else
1431 | if [ "X$DETAIL_STATUS" = "X" ]
1432 | then
1433 | eval echo `gettext 'Stopping $APP_LONG_NAME... Wrapper:Running'`
1434 | else
1435 | getstatus
1436 | eval echo `gettext 'Stopping $APP_LONG_NAME... Wrapper:$STATUS, Java:$JAVASTATUS'`
1437 | fi
1438 | fi
1439 | }
1440 |
1441 | showUsage() {
1442 | # $1 bad command
1443 |
1444 | if [ -n "$1" ]
1445 | then
1446 | eval echo `gettext 'Unexpected command: $1'`
1447 | echo "";
1448 | fi
1449 |
1450 | eval MSG=`gettext 'Usage: '`
1451 | if [ -n "$FIXED_COMMAND" ] ; then
1452 | if [ -n "$PASS_THROUGH" ] ; then
1453 | echo "${MSG} $0 {JavaAppArgs}"
1454 | else
1455 | echo "${MSG} $0"
1456 | fi
1457 | else
1458 | if [ -n "$PAUSABLE" ] ; then
1459 | if [ -n "$PASS_THROUGH" ] ; then
1460 | echo "${MSG} $0 [ console {JavaAppArgs} | start {JavaAppArgs} | stop | restart {JavaAppArgs} | condrestart {JavaAppArgs} | pause | resume | status | install | remove | dump ]"
1461 | else
1462 | echo "${MSG} $0 [ console | start | stop | restart | condrestart | pause | resume | status | install | remove | dump ]"
1463 | fi
1464 | else
1465 | if [ -n "$PASS_THROUGH" ] ; then
1466 | echo "${MSG} $0 [ console {JavaAppArgs} | start {JavaAppArgs} | stop | restart {JavaAppArgs} | condrestart {JavaAppArgs} | status | install | remove | dump ]"
1467 | else
1468 | echo "${MSG} $0 [ console | start | stop | restart | condrestart | status | install | remove | dump ]"
1469 | fi
1470 | fi
1471 | fi
1472 |
1473 | if [ ! -n "$BRIEF_USAGE" ]
1474 | then
1475 | echo "";
1476 | if [ ! -n "$FIXED_COMMAND" ] ; then
1477 | echo "`gettext 'Commands:'`"
1478 | echo "`gettext ' console Launch in the current console.'`"
1479 | echo "`gettext ' start Start in the background as a daemon process.'`"
1480 | echo "`gettext ' stop Stop if running as a daemon or in another console.'`"
1481 | echo "`gettext ' restart Stop if running and then start.'`"
1482 | echo "`gettext ' condrestart Restart only if already running.'`"
1483 | if [ -n "$PAUSABLE" ] ; then
1484 | echo "`gettext ' pause Pause if running.'`"
1485 | echo "`gettext ' resume Resume if paused.'`"
1486 | fi
1487 | echo "`gettext ' status Query the current status.'`"
1488 | echo "`gettext ' install Install to start automatically when system boots.'`"
1489 | echo "`gettext ' remove Uninstall.'`"
1490 | echo "`gettext ' dump Request a Java thread dump if running.'`"
1491 | echo "";
1492 | fi
1493 | if [ -n "$PASS_THROUGH" ] ; then
1494 | echo "`gettext 'JavaAppArgs: Zero or more arguments which will be passed to the Java application.'`"
1495 | echo "";
1496 | fi
1497 | fi
1498 |
1499 | exit 1
1500 | }
1501 |
1502 | docommand() {
1503 | case "$COMMAND" in
1504 | 'console')
1505 | checkUser touchlock "$@"
1506 | if [ ! -n "$FIXED_COMMAND" ] ; then
1507 | shift
1508 | fi
1509 | console "$@"
1510 | ;;
1511 |
1512 | 'start')
1513 | if [ "$DIST_OS" = "macosx" -a -f "/Library/LaunchDaemons/${APP_PLIST}" ] ; then
1514 | macosxstart
1515 | elif [ "$DIST_OS" = "linux" -a -f "/etc/init/${APP_NAME}.conf" ] ; then
1516 | upstartstart
1517 | else
1518 | checkUser touchlock "$@"
1519 | if [ ! -n "$FIXED_COMMAND" ] ; then
1520 | shift
1521 | fi
1522 | start "$@"
1523 | fi
1524 | ;;
1525 |
1526 | 'stop')
1527 | checkUser "" "$COMMAND"
1528 | stopit "0"
1529 | ;;
1530 |
1531 | 'restart')
1532 | checkUser touchlock "$COMMAND"
1533 | if [ ! -n "$FIXED_COMMAND" ] ; then
1534 | shift
1535 | fi
1536 | stopit "0"
1537 | start "$@"
1538 | ;;
1539 |
1540 | 'condrestart')
1541 | checkUser touchlock "$COMMAND"
1542 | if [ ! -n "$FIXED_COMMAND" ] ; then
1543 | shift
1544 | fi
1545 | stopit "1"
1546 | start "$@"
1547 | ;;
1548 |
1549 | 'pause')
1550 | if [ -n "$PAUSABLE" ]
1551 | then
1552 | pause
1553 | else
1554 | showUsage "$COMMAND"
1555 | fi
1556 | ;;
1557 |
1558 | 'resume')
1559 | if [ -n "$PAUSABLE" ]
1560 | then
1561 | resume
1562 | else
1563 | showUsage "$COMMAND"
1564 | fi
1565 | ;;
1566 |
1567 | 'status')
1568 | status
1569 | ;;
1570 |
1571 | 'install')
1572 | installdaemon
1573 | ;;
1574 |
1575 | 'remove')
1576 | removedaemon
1577 | ;;
1578 |
1579 | 'dump')
1580 | checkUser "" "$COMMAND"
1581 | dump
1582 | ;;
1583 |
1584 | 'start_msg')
1585 | # Internal command called by launchd on HP-UX.
1586 | checkUser "" "$COMMAND"
1587 | startmsg
1588 | ;;
1589 |
1590 | 'stop_msg')
1591 | # Internal command called by launchd on HP-UX.
1592 | checkUser "" "$COMMAND"
1593 | stopmsg
1594 | ;;
1595 |
1596 | 'launchdinternal' | 'upstartinternal')
1597 | if [ ! "$DIST_OS" = "macosx" -o ! -f "/Library/LaunchDaemons/${APP_PLIST}" ] ; then
1598 | checkUser touchlock "$@"
1599 | fi
1600 | # Internal command called by launchd on Max OSX.
1601 | # We do not want to call checkUser here as it is handled in the launchd plist file. Doing it here would confuse launchd.
1602 | if [ ! -n "$FIXED_COMMAND" ] ; then
1603 | shift
1604 | fi
1605 | launchinternal "$@"
1606 | ;;
1607 |
1608 | *)
1609 | showUsage "$COMMAND"
1610 | ;;
1611 | esac
1612 | }
1613 |
1614 | docommand "$@"
1615 |
1616 | exit 0
1617 |
--------------------------------------------------------------------------------