4 # Copyright (c) 1999, 2008 Tanuki Software, Inc.
5 # http://www.tanukisoftware.com
8 # This software is the confidential and proprietary information
9 # of Tanuki Software. ("Confidential Information"). You shall
10 # not disclose such Confidential Information and shall use it
11 # only in accordance with the terms of the license agreement you
12 # entered into with Tanuki Software.
14 # Java Service Wrapper sh script. Suitable for starting and stopping
15 # wrapped Java applications on UNIX platforms.
18 # since we have a depencency to java-runtime, one of these files must
20 if [ -f /etc
/profile.d
/jdk.sh
]; then
21 source /etc
/profile.d
/jdk.sh
23 if [ -f /etc
/profile.d
/jre.sh
]; then
24 source /etc
/profile.d
/jre.sh
26 if [ -f /etc
/profile.d
/openjdk6.sh
]; then
27 source /etc
/profile.d
/openjdk6.sh
30 export JAVA_HOME
=${JAVA_HOME:=/opt/java}
32 export SONAR_HOME
=${SONAR_HOME:=/opt/sonar}
33 export SONAR_RUN_DIR
=${SONAR_RUN_DIR:=/var/run/sonar}
34 export SONAR_ETC_DIR
=${SONAR_ETC_DIR:=/etc/sonar}
35 export SONAR_LOG_DIR
=${SONAR_LOG_DIR:=/var/log/sonar}
37 #-----------------------------------------------------------------------------
38 # These settings can be modified to fit the needs of your application
39 # Optimized for use with version 3.3.0 of the Wrapper.
41 # These settings are highly modified for the use of the sonar application
49 WRAPPER_CMD
="$SONAR_HOME/bin/wrapper"
50 WRAPPER_CONF
="$SONAR_ETC_DIR/wrapper.conf"
52 # Priority at which to run the wrapper. See "man nice" for valid priorities.
53 # nice is only used if a priority is specified.
56 # Location of the pid file.
57 PIDDIR
="$SONAR_RUN_DIR"
59 # If uncommented, causes the Wrapper to be shutdown using an anchor file.
60 # When launched with the 'start' command, it will also ignore all INT and
64 # Wrapper will start the JVM asynchronously. Your application may have some
65 # initialization tasks and it may be desirable to wait a few seconds
66 # before returning. For example, to delay the invocation of following
67 # startup scripts. Setting WAIT_AFTER_STARTUP to a positive number will
68 # cause the start command to delay for the indicated period of time
73 # If set, the status, start_msg and stop_msg commands will print out detailed
74 # state information on the Wrapper and Java processes.
77 # If specified, the Wrapper will be run as the specified user.
78 # IMPORTANT - Make sure that the user has the required privileges to write
79 # the PID file and wrapper.log files. Failure to be able to write the log
80 # file will cause the Wrapper to exit without any way to write out an error
82 # NOTE - This will set the user which is used to run the Wrapper as well as
83 # the JVM and is not useful in situations where a privileged resource or
84 # port needs to be allocated prior to the user being changed.
87 # The following two lines are used by the chkconfig command. Change as is
88 # appropriate for your application. They should remain commented.
89 # chkconfig: 2345 20 80
90 # description: "Sonar Server"
92 # Initialization block for the install_initd and remove_initd scripts used by
93 # SUSE linux distributions.
95 # Provides: @app.name@
96 # Required-Start: $local_fs $network $syslog
99 # Default-Start: 2 3 4 5
100 # Default-Stop: 0 1 6
101 # Short-Description: @app.long.name@
102 # Description: @app.description@
105 # Do not modify anything beyond this point
106 #-----------------------------------------------------------------------------
108 # Get the fully qualified path to the script
119 # Resolve the true real path without any sym links.
121 while [ "X$CHANGED" != "X" ]
123 # Change spaces to ":" so the tokens can be parsed.
124 SAFESCRIPT
=`echo $SCRIPT | sed -e 's; ;:;g'`
125 # Get the real path to this script, resolving any symbolic links
126 TOKENS
=`echo $SAFESCRIPT | sed -e 's;/; ;g'`
129 # Change any ":" in the token back to a space.
130 C
=`echo $C | sed -e 's;:; ;g'`
131 REALPATH
="$REALPATH/$C"
132 # If REALPATH is a sym link, resolve it. Loop for nested links.
133 while [ -h "$REALPATH" ] ; do
134 LS
="`ls -ld "$REALPATH"`"
135 LINK
="`expr "$LS" : '.*-> \(.*\)$'`"
136 if expr "$LINK" : '/.*' > /dev
/null
; then
141 REALPATH
="`dirname "$REALPATH"`""/$LINK"
146 if [ "$REALPATH" = "$SCRIPT" ]
154 # Change the current directory to the location of the script
155 cd "`dirname "$REALPATH"`"
158 # If the PIDDIR is relative, set its value relative to the full REALPATH to avoid problems if
159 # the working directory is later changed.
160 FIRST_CHAR
=`echo $PIDDIR | cut -c1,1`
161 if [ "$FIRST_CHAR" != "/" ]
163 PIDDIR
=$REALDIR/$PIDDIR
165 # Same test for WRAPPER_CMD
166 FIRST_CHAR
=`echo $WRAPPER_CMD | cut -c1,1`
167 if [ "$FIRST_CHAR" != "/" ]
169 WRAPPER_CMD
=$REALDIR/$WRAPPER_CMD
171 # Same test for WRAPPER_CONF
172 FIRST_CHAR
=`echo $WRAPPER_CONF | cut -c1,1`
173 if [ "$FIRST_CHAR" != "/" ]
175 WRAPPER_CONF
=$REALDIR/$WRAPPER_CONF
179 ANCHORFILE
="$PIDDIR/$APP_NAME.anchor"
180 STATUSFILE
="$PIDDIR/$APP_NAME.status"
181 JAVASTATUSFILE
="$PIDDIR/$APP_NAME.java.status"
182 PIDFILE
="$PIDDIR/$APP_NAME.pid"
183 LOCKDIR
="/var/lock/subsys"
184 LOCKFILE
="$LOCKDIR/$APP_NAME"
187 # Resolve the location of the 'ps' command
194 echo "Unable to locate 'ps'."
195 echo "Please report this message along with the location of the command on your system."
201 DIST_OS
=`uname -s | tr [:upper:] [:lower:] | tr -d [:blank:]`
207 # HP-UX needs the XPG4 version of ps (for -o args)
220 # Resolve the architecture
221 if [ "$DIST_OS" = "macosx" ]
223 DIST_ARCH
="universal"
226 DIST_ARCH
=`uname -p 2>/dev/null | tr [:upper:] [:lower:] | tr -d [:blank:]`
227 if [ "X$DIST_ARCH" = "X" ]
231 if [ "$DIST_ARCH" = "unknown" ]
233 DIST_ARCH
=`uname -m 2>/dev/null | tr [:upper:] [:lower:] | tr -d [:blank:]`
236 'amd64' |
'athlon' |
'i386' |
'i486' |
'i586' |
'i686' |
'x86_64')
239 'ia32' |
'ia64' |
'ia64n' |
'ia64w')
245 'power' |
'powerpc' |
'power_pc' |
'ppc64')
248 'pa_risc' |
'pa-risc')
260 # OSX always places Java in the same location so we can reliably set JAVA_HOME
261 if [ "$DIST_OS" = "macosx" ]
263 if [ -z "$JAVA_HOME" ]; then
264 JAVA_HOME
="/Library/Java/Home"; export JAVA_HOME
271 echo " $1 (Found but not executable.)";
277 # Decide on the wrapper binary to use.
278 # If a 32-bit wrapper binary exists then it will work on 32 or 64 bit
279 # platforms, if the 64-bit binary exists then the distribution most
280 # likely wants to use long names. Otherwise, look for the default.
281 WRAPPER_TEST_CMD
="$WRAPPER_CMD-$DIST_OS-$DIST_ARCH-32"
282 if [ -x "$WRAPPER_TEST_CMD" ]
284 WRAPPER_CMD
="$WRAPPER_TEST_CMD"
286 WRAPPER_TEST_CMD
="$WRAPPER_CMD-$DIST_OS-$DIST_ARCH-64"
287 if [ -x "$WRAPPER_TEST_CMD" ]
289 WRAPPER_CMD
="$WRAPPER_TEST_CMD"
291 if [ ! -x "$WRAPPER_CMD" ]
293 echo "Unable to locate any of the following binaries:"
294 outputFile
"$WRAPPER_CMD-$DIST_OS-$DIST_ARCH-32"
295 outputFile
"$WRAPPER_CMD-$DIST_OS-$DIST_ARCH-64"
296 outputFile
"$WRAPPER_CMD"
302 # Build the nice clause
303 if [ "X$PRIORITY" = "X" ]
307 CMDNICE
="nice -$PRIORITY"
310 # Build the anchor file clause.
311 if [ "X$IGNORE_SIGNALS" = "X" ]
316 ANCHORPROP
=wrapper.anchorfile
=\"$ANCHORFILE\"
317 IGNOREPROP
=wrapper.ignore_signals
=TRUE
320 # Build the status file clause.
321 if [ "X$DETAIL_STATUS" = "X" ]
325 STATUSPROP
="wrapper.statusfile=\"$STATUSFILE\" wrapper.java.statusfile=\"$JAVASTATUSFILE\""
328 # Build the lock file clause. Only create a lock file if the lock directory exists on this platform.
334 LOCKPROP
=wrapper.lockfile
=\"$LOCKFILE\"
342 # Check the configured user. If necessary rerun this script as the desired user.
343 if [ "X$RUN_AS_USER" != "X" ]
345 # Resolve the location of the 'id' command
346 IDEXE
="/usr/xpg4/bin/id"
352 echo "Unable to locate 'id'."
353 echo "Please report this message along with the location of the command on your system."
358 if [ "`$IDEXE -u -n`" = "$RUN_AS_USER" ]
360 # Already running as the configured user. Avoid password prompts by not calling su.
364 if [ "X$RUN_AS_USER" != "X" ]
366 # If LOCKPROP and $RUN_AS_USER are defined then the new user will most likely not be
367 # able to create the lock file. The Wrapper will be able to update this file once it
368 # is created but will not be able to delete it on shutdown. If $2 is defined then
369 # the lock file should be created for the current command
370 if [ "X$LOCKPROP" != "X" ]
374 # Resolve the primary group
375 RUN_AS_GROUP
=`groups $RUN_AS_USER | awk '{print $3}' | tail -1`
376 if [ "X$RUN_AS_GROUP" = "X" ]
378 RUN_AS_GROUP
=$RUN_AS_USER
381 chown
$RUN_AS_USER:$RUN_AS_GROUP $LOCKFILE
385 # Still want to change users, recurse. This means that the user will only be
386 # prompted for a password once. Variables shifted by 1
388 # Use "runuser" if this exists. runuser should be used on RedHat in preference to su.
390 if test -f "/sbin/runuser"
392 /sbin
/runuser
- $RUN_AS_USER -c "\"$REALPATH\" $2"
394 su
- $RUN_AS_USER -c "\"$REALPATH\" $2"
397 # Now that we are the original user again, we may need to clean up the lock file.
398 if [ "X$LOCKPROP" != "X" ]
403 # Wrapper is not running so make sure the lock file is deleted.
404 if [ -f "$LOCKFILE" ]
422 if [ "X$pid" != "X" ]
424 # It is possible that 'a' process with the pid exists but that it is not the
425 # correct process. This can happen in a number of cases, but the most
426 # common is during system startup after an unclean shutdown.
427 # The ps statement below looks for the specific wrapper command running as
428 # the pid. If it is not found then the pid file is considered to be stale.
431 pidtest
=`$PSEXE -ww -p $pid -o command | grep "$WRAPPER_CMD" | tail -1`
434 pidtest
=`$PSEXE -p $pid -o args | grep "$WRAPPER_CMD" | tail -1`
438 if [ "X$pidtest" = "X" ]
440 # This is a stale pid file.
442 echo "Removed stale pid file: $PIDFILE"
447 echo "Cannot read $PIDFILE."
455 if [ -f "$STATUSFILE" ]
457 if [ -r "$STATUSFILE" ]
459 STATUS
=`cat "$STATUSFILE"`
462 if [ "X$STATUS" = "X" ]
468 if [ -f "$JAVASTATUSFILE" ]
470 if [ -r "$JAVASTATUSFILE" ]
472 JAVASTATUS
=`cat "$JAVASTATUSFILE"`
475 if [ "X$JAVASTATUS" = "X" ]
482 pid
=`$PSEXE -p $pid | grep $pid | grep -v grep | awk '{print $1}' | tail -1`
485 # Process is gone so remove the pid file.
492 echo "Running $APP_LONG_NAME..."
496 # The string passed to eval must handles spaces in paths correctly.
497 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 $LOCKPROP"
500 echo "$APP_LONG_NAME is already running."
506 echo -n "Starting $APP_LONG_NAME..."
510 # The string passed to eval must handles spaces in paths correctly.
511 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 $LOCKPROP"
514 echo "$APP_LONG_NAME is already running."
518 # Sleep for a few seconds to allow for intialization if required
519 # then test to make sure we're still running.
522 while [ $i -lt $WAIT_AFTER_STARTUP ]
528 if [ $WAIT_AFTER_STARTUP -gt 0 ]
533 echo " WARNING: $APP_LONG_NAME may have failed to start."
536 echo " running ($pid)."
544 echo "Stopping $APP_LONG_NAME..."
548 echo "$APP_LONG_NAME was not running."
550 if [ "X$IGNORE_SIGNALS" = "X" ]
552 # Running so try to stop it.
556 # An explanation for the failure should have been given
557 echo "Unable to stop $APP_LONG_NAME."
562 if [ -f "$ANCHORFILE" ]
564 # An explanation for the failure should have been given
565 echo "Unable to stop $APP_LONG_NAME."
570 # We can not predict how long it will take for the wrapper to
571 # actually stop as it depends on settings in wrapper.conf.
572 # Loop until it does.
576 while [ "X$pid" != "X" ]
578 # Show a waiting message every 5 seconds.
579 if [ "$CNT" -lt "5" ]
583 echo "Waiting for $APP_LONG_NAME to exit..."
586 TOTCNT
=`expr $TOTCNT + 1`
595 if [ "X$pid" != "X" ]
597 echo "Failed to stop $APP_LONG_NAME."
600 echo "Stopped $APP_LONG_NAME."
609 echo "$APP_LONG_NAME is not running."
612 if [ "X$DETAIL_STATUS" = "X" ]
614 echo "$APP_LONG_NAME is running (PID:$pid)."
617 echo "$APP_LONG_NAME is running (PID:$pid, Wrapper:$STATUS, Java:$JAVASTATUS)"
624 echo "Dumping $APP_LONG_NAME..."
628 echo "$APP_LONG_NAME was not running."
634 echo "Failed to dump $APP_LONG_NAME."
637 echo "Dumped $APP_LONG_NAME."
642 # Used by HP-UX init scripts.
647 echo "Starting $APP_LONG_NAME... (Wrapper:Stopped)"
649 if [ "X$DETAIL_STATUS" = "X" ]
651 echo "Starting $APP_LONG_NAME... (Wrapper:Running)"
654 echo "Starting $APP_LONG_NAME... (Wrapper:$STATUS, Java:$JAVASTATUS)"
659 # Used by HP-UX init scripts.
664 echo "Stopping $APP_LONG_NAME... (Wrapper:Stopped)"
666 if [ "X$DETAIL_STATUS" = "X" ]
668 echo "Stopping $APP_LONG_NAME... (Wrapper:Running)"
671 echo "Stopping $APP_LONG_NAME... (Wrapper:$STATUS, Java:$JAVASTATUS)"
679 checkUser touchlock
$1
684 checkUser touchlock
$1
694 checkUser touchlock
$1
720 echo "Usage: $0 { console | start | stop | restart | status | dump }"