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 #-----------------------------------------------------------------------------
19 # These settings can be modified to fit the needs of your application
20 # Optimized for use with version 3.3.0 of the Wrapper.
22 # These settings are highly modified for the use of the sonar application
25 # Linux czf00srv002 2.6.27-14-server #1 SMP Mon Aug 31 13:57:10 UTC 2009 i686 GNU/Linux
26 # Linux athene 2.6.31-ARCH #1 SMP PREEMPT Tue Oct 13 11:33:39 CEST 2009 x86_64 Intel(R) Core(TM)2 Duo CPU T9400 @ 2.53GHz GenuineIntel GNU/Linux
33 WRAPPER_CMD
="/opt/sonar/bin/wrapper"
34 WRAPPER_CONF
="/etc/sonar/wrapper.conf"
36 # Priority at which to run the wrapper. See "man nice" for valid priorities.
37 # nice is only used if a priority is specified.
40 # Location of the pid file.
43 # If uncommented, causes the Wrapper to be shutdown using an anchor file.
44 # When launched with the 'start' command, it will also ignore all INT and
48 # Wrapper will start the JVM asynchronously. Your application may have some
49 # initialization tasks and it may be desirable to wait a few seconds
50 # before returning. For example, to delay the invocation of following
51 # startup scripts. Setting WAIT_AFTER_STARTUP to a positive number will
52 # cause the start command to delay for the indicated period of time
57 # If set, the status, start_msg and stop_msg commands will print out detailed
58 # state information on the Wrapper and Java processes.
61 # If specified, the Wrapper will be run as the specified user.
62 # IMPORTANT - Make sure that the user has the required privileges to write
63 # the PID file and wrapper.log files. Failure to be able to write the log
64 # file will cause the Wrapper to exit without any way to write out an error
66 # NOTE - This will set the user which is used to run the Wrapper as well as
67 # the JVM and is not useful in situations where a privileged resource or
68 # port needs to be allocated prior to the user being changed.
71 # The following two lines are used by the chkconfig command. Change as is
72 # appropriate for your application. They should remain commented.
73 # chkconfig: 2345 20 80
74 # description: "Sonar Server"
76 # Initialization block for the install_initd and remove_initd scripts used by
77 # SUSE linux distributions.
79 # Provides: @app.name@
80 # Required-Start: $local_fs $network $syslog
83 # Default-Start: 2 3 4 5
85 # Short-Description: @app.long.name@
86 # Description: @app.description@
89 # Do not modify anything beyond this point
90 #-----------------------------------------------------------------------------
92 # Get the fully qualified path to the script
103 # Resolve the true real path without any sym links.
105 while [ "X$CHANGED" != "X" ]
107 # Change spaces to ":" so the tokens can be parsed.
108 SAFESCRIPT
=`echo $SCRIPT | sed -e 's; ;:;g'`
109 # Get the real path to this script, resolving any symbolic links
110 TOKENS
=`echo $SAFESCRIPT | sed -e 's;/; ;g'`
113 # Change any ":" in the token back to a space.
114 C
=`echo $C | sed -e 's;:; ;g'`
115 REALPATH
="$REALPATH/$C"
116 # If REALPATH is a sym link, resolve it. Loop for nested links.
117 while [ -h "$REALPATH" ] ; do
118 LS
="`ls -ld "$REALPATH"`"
119 LINK
="`expr "$LS" : '.*-> \(.*\)$'`"
120 if expr "$LINK" : '/.*' > /dev
/null
; then
125 REALPATH
="`dirname "$REALPATH"`""/$LINK"
130 if [ "$REALPATH" = "$SCRIPT" ]
138 # Change the current directory to the location of the script
139 cd "`dirname "$REALPATH"`"
142 # If the PIDDIR is relative, set its value relative to the full REALPATH to avoid problems if
143 # the working directory is later changed.
144 FIRST_CHAR
=`echo $PIDDIR | cut -c1,1`
145 if [ "$FIRST_CHAR" != "/" ]
147 PIDDIR
=$REALDIR/$PIDDIR
149 # Same test for WRAPPER_CMD
150 FIRST_CHAR
=`echo $WRAPPER_CMD | cut -c1,1`
151 if [ "$FIRST_CHAR" != "/" ]
153 WRAPPER_CMD
=$REALDIR/$WRAPPER_CMD
155 # Same test for WRAPPER_CONF
156 FIRST_CHAR
=`echo $WRAPPER_CONF | cut -c1,1`
157 if [ "$FIRST_CHAR" != "/" ]
159 WRAPPER_CONF
=$REALDIR/$WRAPPER_CONF
163 ANCHORFILE
="$PIDDIR/$APP_NAME.anchor"
164 STATUSFILE
="$PIDDIR/$APP_NAME.status"
165 JAVASTATUSFILE
="$PIDDIR/$APP_NAME.java.status"
166 PIDFILE
="$PIDDIR/$APP_NAME.pid"
167 LOCKDIR
="/var/lock/subsys"
168 LOCKFILE
="$LOCKDIR/$APP_NAME"
171 # Resolve the location of the 'ps' command
178 echo "Unable to locate 'ps'."
179 echo "Please report this message along with the location of the command on your system."
185 DIST_OS
=`uname -s | tr [:upper:] [:lower:] | tr -d [:blank:]`
191 # HP-UX needs the XPG4 version of ps (for -o args)
204 # Resolve the architecture
205 if [ "$DIST_OS" = "macosx" ]
207 DIST_ARCH
="universal"
210 DIST_ARCH
=`uname -p 2>/dev/null | tr [:upper:] [:lower:] | tr -d [:blank:]`
211 if [ "X$DIST_ARCH" = "X" ]
215 if [ "$DIST_ARCH" = "unknown" ]
217 DIST_ARCH
=`uname -m 2>/dev/null | tr [:upper:] [:lower:] | tr -d [:blank:]`
220 'amd64' |
'athlon' |
'i386' |
'i486' |
'i586' |
'i686' |
'x86_64')
223 'ia32' |
'ia64' |
'ia64n' |
'ia64w')
229 'power' |
'powerpc' |
'power_pc' |
'ppc64')
232 'pa_risc' |
'pa-risc')
244 # OSX always places Java in the same location so we can reliably set JAVA_HOME
245 if [ "$DIST_OS" = "macosx" ]
247 if [ -z "$JAVA_HOME" ]; then
248 JAVA_HOME
="/Library/Java/Home"; export JAVA_HOME
255 echo " $1 (Found but not executable.)";
261 # Decide on the wrapper binary to use.
262 # If a 32-bit wrapper binary exists then it will work on 32 or 64 bit
263 # platforms, if the 64-bit binary exists then the distribution most
264 # likely wants to use long names. Otherwise, look for the default.
265 WRAPPER_TEST_CMD
="$WRAPPER_CMD-$DIST_OS-$DIST_ARCH-32"
266 if [ -x "$WRAPPER_TEST_CMD" ]
268 WRAPPER_CMD
="$WRAPPER_TEST_CMD"
270 WRAPPER_TEST_CMD
="$WRAPPER_CMD-$DIST_OS-$DIST_ARCH-64"
271 if [ -x "$WRAPPER_TEST_CMD" ]
273 WRAPPER_CMD
="$WRAPPER_TEST_CMD"
275 if [ ! -x "$WRAPPER_CMD" ]
277 echo "Unable to locate any of the following binaries:"
278 outputFile
"$WRAPPER_CMD-$DIST_OS-$DIST_ARCH-32"
279 outputFile
"$WRAPPER_CMD-$DIST_OS-$DIST_ARCH-64"
280 outputFile
"$WRAPPER_CMD"
286 # Build the nice clause
287 if [ "X$PRIORITY" = "X" ]
291 CMDNICE
="nice -$PRIORITY"
294 # Build the anchor file clause.
295 if [ "X$IGNORE_SIGNALS" = "X" ]
300 ANCHORPROP
=wrapper.anchorfile
=\"$ANCHORFILE\"
301 IGNOREPROP
=wrapper.ignore_signals
=TRUE
304 # Build the status file clause.
305 if [ "X$DETAIL_STATUS" = "X" ]
309 STATUSPROP
="wrapper.statusfile=\"$STATUSFILE\" wrapper.java.statusfile=\"$JAVASTATUSFILE\""
312 # Build the lock file clause. Only create a lock file if the lock directory exists on this platform.
318 LOCKPROP
=wrapper.lockfile
=\"$LOCKFILE\"
326 # Check the configured user. If necessary rerun this script as the desired user.
327 if [ "X$RUN_AS_USER" != "X" ]
329 # Resolve the location of the 'id' command
330 IDEXE
="/usr/xpg4/bin/id"
336 echo "Unable to locate 'id'."
337 echo "Please report this message along with the location of the command on your system."
342 if [ "`$IDEXE -u -n`" = "$RUN_AS_USER" ]
344 # Already running as the configured user. Avoid password prompts by not calling su.
348 if [ "X$RUN_AS_USER" != "X" ]
350 # If LOCKPROP and $RUN_AS_USER are defined then the new user will most likely not be
351 # able to create the lock file. The Wrapper will be able to update this file once it
352 # is created but will not be able to delete it on shutdown. If $2 is defined then
353 # the lock file should be created for the current command
354 if [ "X$LOCKPROP" != "X" ]
358 # Resolve the primary group
359 RUN_AS_GROUP
=`groups $RUN_AS_USER | awk '{print $3}' | tail -1`
360 if [ "X$RUN_AS_GROUP" = "X" ]
362 RUN_AS_GROUP
=$RUN_AS_USER
365 chown
$RUN_AS_USER:$RUN_AS_GROUP $LOCKFILE
369 # Still want to change users, recurse. This means that the user will only be
370 # prompted for a password once. Variables shifted by 1
372 # Use "runuser" if this exists. runuser should be used on RedHat in preference to su.
374 if test -f "/sbin/runuser"
376 /sbin
/runuser
- $RUN_AS_USER -c "\"$REALPATH\" $2"
378 su
- $RUN_AS_USER -c "\"$REALPATH\" $2"
381 # Now that we are the original user again, we may need to clean up the lock file.
382 if [ "X$LOCKPROP" != "X" ]
387 # Wrapper is not running so make sure the lock file is deleted.
388 if [ -f "$LOCKFILE" ]
406 if [ "X$pid" != "X" ]
408 # It is possible that 'a' process with the pid exists but that it is not the
409 # correct process. This can happen in a number of cases, but the most
410 # common is during system startup after an unclean shutdown.
411 # The ps statement below looks for the specific wrapper command running as
412 # the pid. If it is not found then the pid file is considered to be stale.
415 pidtest
=`$PSEXE -ww -p $pid -o command | grep "$WRAPPER_CMD" | tail -1`
418 pidtest
=`$PSEXE -p $pid -o args | grep "$WRAPPER_CMD" | tail -1`
422 if [ "X$pidtest" = "X" ]
424 # This is a stale pid file.
426 echo "Removed stale pid file: $PIDFILE"
431 echo "Cannot read $PIDFILE."
439 if [ -f "$STATUSFILE" ]
441 if [ -r "$STATUSFILE" ]
443 STATUS
=`cat "$STATUSFILE"`
446 if [ "X$STATUS" = "X" ]
452 if [ -f "$JAVASTATUSFILE" ]
454 if [ -r "$JAVASTATUSFILE" ]
456 JAVASTATUS
=`cat "$JAVASTATUSFILE"`
459 if [ "X$JAVASTATUS" = "X" ]
466 pid
=`$PSEXE -p $pid | grep $pid | grep -v grep | awk '{print $1}' | tail -1`
469 # Process is gone so remove the pid file.
476 echo "Running $APP_LONG_NAME..."
480 # The string passed to eval must handles spaces in paths correctly.
481 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"
484 echo "$APP_LONG_NAME is already running."
490 echo -n "Starting $APP_LONG_NAME..."
494 # The string passed to eval must handles spaces in paths correctly.
495 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"
498 echo "$APP_LONG_NAME is already running."
502 # Sleep for a few seconds to allow for intialization if required
503 # then test to make sure we're still running.
506 while [ $i -lt $WAIT_AFTER_STARTUP ]
512 if [ $WAIT_AFTER_STARTUP -gt 0 ]
517 echo " WARNING: $APP_LONG_NAME may have failed to start."
520 echo " running ($pid)."
528 echo "Stopping $APP_LONG_NAME..."
532 echo "$APP_LONG_NAME was not running."
534 if [ "X$IGNORE_SIGNALS" = "X" ]
536 # Running so try to stop it.
540 # An explanation for the failure should have been given
541 echo "Unable to stop $APP_LONG_NAME."
546 if [ -f "$ANCHORFILE" ]
548 # An explanation for the failure should have been given
549 echo "Unable to stop $APP_LONG_NAME."
554 # We can not predict how long it will take for the wrapper to
555 # actually stop as it depends on settings in wrapper.conf.
556 # Loop until it does.
560 while [ "X$pid" != "X" ]
562 # Show a waiting message every 5 seconds.
563 if [ "$CNT" -lt "5" ]
567 echo "Waiting for $APP_LONG_NAME to exit..."
570 TOTCNT
=`expr $TOTCNT + 1`
579 if [ "X$pid" != "X" ]
581 echo "Failed to stop $APP_LONG_NAME."
584 echo "Stopped $APP_LONG_NAME."
593 echo "$APP_LONG_NAME is not running."
596 if [ "X$DETAIL_STATUS" = "X" ]
598 echo "$APP_LONG_NAME is running (PID:$pid)."
601 echo "$APP_LONG_NAME is running (PID:$pid, Wrapper:$STATUS, Java:$JAVASTATUS)"
608 echo "Dumping $APP_LONG_NAME..."
612 echo "$APP_LONG_NAME was not running."
618 echo "Failed to dump $APP_LONG_NAME."
621 echo "Dumped $APP_LONG_NAME."
626 # Used by HP-UX init scripts.
631 echo "Starting $APP_LONG_NAME... (Wrapper:Stopped)"
633 if [ "X$DETAIL_STATUS" = "X" ]
635 echo "Starting $APP_LONG_NAME... (Wrapper:Running)"
638 echo "Starting $APP_LONG_NAME... (Wrapper:$STATUS, Java:$JAVASTATUS)"
643 # Used by HP-UX init scripts.
648 echo "Stopping $APP_LONG_NAME... (Wrapper:Stopped)"
650 if [ "X$DETAIL_STATUS" = "X" ]
652 echo "Stopping $APP_LONG_NAME... (Wrapper:Running)"
655 echo "Stopping $APP_LONG_NAME... (Wrapper:$STATUS, Java:$JAVASTATUS)"
663 checkUser touchlock
$1
668 checkUser touchlock
$1
678 checkUser touchlock
$1
704 echo "Usage: $0 { console | start | stop | restart | status | dump }"