3 # The following changes are made for the ArchLinux nexus package
4 # Contributor: Markus M. May <mmay AT javafreedom DOT org>
6 export NEXUS_HOME
=${NEXUS_HOME:=/opt/nexus}
7 export NEXUS_RUN_DIR
=${NEXUS_RUN_DIR:=/var/run/nexus}
8 export PLEXUS_NEXUS_WORK
=${PLEXUS_NEXUS_WORK:=/var/lib/nexus}
11 # Copyright (c) 1999, 2006 Tanuki Software Inc.
13 # Java Service Wrapper sh script. Suitable for starting and stopping
14 # wrapped Java applications on UNIX platforms.
16 #-----------------------------------------------------------------------------
17 # These settings can be modified to fit the needs of your application
19 # Default values for the Application variables, below.
21 # NOTE: The build for specific applications may override this during the resource-copying
22 # phase, to fill in a concrete name and avoid the use of the defaults specified here.
23 DEF_APP_NAME
="testwrapper"
24 DEF_APP_LONG_NAME
="Test Wrapper Sample Application"
27 APP_NAME
="nexus-webapp"
28 APP_LONG_NAME
="Sonatype Nexus Repository Manager"
31 WRAPPER_CMD
="$NEXUS_HOME/bin/wrapper"
32 WRAPPER_CONF
="$NEXUS_HOME/conf/wrapper.conf"
34 # Priority at which to run the wrapper. See "man nice" for valid priorities.
35 # nice is only used if a priority is specified.
38 # Location of the pid file.
39 PIDDIR
="$NEXUS_RUN_DIR"
41 # If uncommented, causes the Wrapper to be shutdown using an anchor file.
42 # When launched with the 'start' command, it will also ignore all INT and
46 # If specified, the Wrapper will be run as the specified user.
47 # IMPORTANT - Make sure that the user has the required privileges to write
48 # the PID file and wrapper.log files. Failure to be able to write the log
49 # file will cause the Wrapper to exit without any way to write out an error
51 # NOTE - This will set the user which is used to run the Wrapper as well as
52 # the JVM and is not useful in situations where a privileged resource or
53 # port needs to be allocated prior to the user being changed.
56 # The following two lines are used by the chkconfig command. Change as is
57 # appropriate for your application. They should remain commented.
58 # chkconfig: 2345 20 80
59 # description: Test Wrapper Sample Application
61 # Do not modify anything beyond this point
62 #-----------------------------------------------------------------------------
64 # Get the fully qualified path to the script
75 # Resolve the true real path without any sym links.
77 while [ "X$CHANGED" != "X" ]
79 # Change spaces to ":" so the tokens can be parsed.
80 SAFESCRIPT
=`echo $SCRIPT | sed -e 's; ;:;g'`
81 # Get the real path to this script, resolving any symbolic links
82 TOKENS
=`echo $SAFESCRIPT | sed -e 's;/; ;g'`
85 # Change any ":" in the token back to a space.
86 C
=`echo $C | sed -e 's;:; ;g'`
87 REALPATH
="$REALPATH/$C"
88 # If REALPATH is a sym link, resolve it. Loop for nested links.
89 while [ -h "$REALPATH" ] ; do
90 LS
="`ls -ld "$REALPATH"`"
91 LINK
="`expr "$LS" : '.*-> \(.*\)$'`"
92 if expr "$LINK" : '/.*' > /dev
/null
; then
97 REALPATH
="`dirname "$REALPATH"`""/$LINK"
102 if [ "$REALPATH" = "$SCRIPT" ]
110 # Change the current directory to the location of the script
111 cd "`dirname "$REALPATH"`"
114 # If the PIDDIR is relative, set its value relative to the full REALPATH to avoid problems if
115 # the working directory is later changed.
116 FIRST_CHAR
=`echo $PIDDIR | cut -c1,1`
117 if [ "$FIRST_CHAR" != "/" ]
119 PIDDIR
=$REALDIR/$PIDDIR
121 # Same test for WRAPPER_CMD
122 FIRST_CHAR
=`echo $WRAPPER_CMD | cut -c1,1`
123 if [ "$FIRST_CHAR" != "/" ]
125 WRAPPER_CMD
=$REALDIR/$WRAPPER_CMD
127 # Same test for WRAPPER_CONF
128 FIRST_CHAR
=`echo $WRAPPER_CONF | cut -c1,1`
129 if [ "$FIRST_CHAR" != "/" ]
131 WRAPPER_CONF
=$REALDIR/$WRAPPER_CONF
135 ANCHORFILE
="$PIDDIR/$APP_NAME.anchor"
136 PIDFILE
="$PIDDIR/$APP_NAME.pid"
137 LOCKDIR
="/var/lock/subsys"
138 LOCKFILE
="$LOCKDIR/$APP_NAME"
141 # Resolve the location of the 'ps' command
148 echo "Unable to locate 'ps'."
149 echo "Please report this message along with the location of the command on your system."
155 DIST_OS
=`uname -s | tr [:upper:] [:lower:] | tr -d [:blank:]`
171 # Resolve the architecture
172 DIST_ARCH
=`uname -p | tr [:upper:] [:lower:] | tr -d [:blank:]`
173 if [ "$DIST_ARCH" = "unknown" ]
175 DIST_ARCH
=`uname -m | tr [:upper:] [:lower:] | tr -d [:blank:]`
178 'amd64' |
'athlon' |
'ia32' |
'ia64' |
'i386' |
'i486' |
'i586' |
'i686' |
'x86_64')
184 'power' |
'powerpc' |
'power_pc' |
'ppc64')
187 'pa_risc' |
'pa-risc')
201 echo " $1 (Found but not executable.)";
207 # Decide on the wrapper binary to use.
208 # If a 32-bit wrapper binary exists then it will work on 32 or 64 bit
209 # platforms, if the 64-bit binary exists then the distribution most
210 # likely wants to use long names. Otherwise, look for the default.
211 # For macosx, we also want to look for universal binaries.
212 WRAPPER_TEST_CMD
="$WRAPPER_CMD-$DIST_OS-$DIST_ARCH-32"
213 if [ -x "$WRAPPER_TEST_CMD" ]
215 WRAPPER_CMD
="$WRAPPER_TEST_CMD"
217 if [ "$DIST_OS" = "macosx" ]
219 WRAPPER_TEST_CMD
="$WRAPPER_CMD-$DIST_OS-universal-32"
220 if [ -x "$WRAPPER_TEST_CMD" ]
222 WRAPPER_CMD
="$WRAPPER_TEST_CMD"
224 WRAPPER_TEST_CMD
="$WRAPPER_CMD-$DIST_OS-$DIST_ARCH-64"
225 if [ -x "$WRAPPER_TEST_CMD" ]
227 WRAPPER_CMD
="$WRAPPER_TEST_CMD"
229 WRAPPER_TEST_CMD
="$WRAPPER_CMD-$DIST_OS-universal-64"
230 if [ -x "$WRAPPER_TEST_CMD" ]
232 WRAPPER_CMD
="$WRAPPER_TEST_CMD"
234 if [ ! -x "$WRAPPER_CMD" ]
236 echo "Unable to locate any of the following binaries:"
237 outputFile
"$WRAPPER_CMD-$DIST_OS-$DIST_ARCH-32"
238 outputFile
"$WRAPPER_CMD-$DIST_OS-universal-32"
239 outputFile
"$WRAPPER_CMD-$DIST_OS-$DIST_ARCH-64"
240 outputFile
"$WRAPPER_CMD-$DIST_OS-universal-64"
241 outputFile
"$WRAPPER_CMD"
248 WRAPPER_TEST_CMD
="$WRAPPER_CMD-$DIST_OS-$DIST_ARCH-64"
249 if [ -x "$WRAPPER_TEST_CMD" ]
251 WRAPPER_CMD
="$WRAPPER_TEST_CMD"
253 if [ ! -x "$WRAPPER_CMD" ]
255 echo "Unable to locate any of the following binaries:"
256 outputFile
"$WRAPPER_CMD-$DIST_OS-$DIST_ARCH-32"
257 outputFile
"$WRAPPER_CMD-$DIST_OS-$DIST_ARCH-64"
258 outputFile
"$WRAPPER_CMD"
265 # Build the nice clause
266 if [ "X$PRIORITY" = "X" ]
270 CMDNICE
="nice -$PRIORITY"
273 # Build the anchor file clause.
274 if [ "X$IGNORE_SIGNALS" = "X" ]
279 ANCHORPROP
=wrapper.anchorfile
=\"$ANCHORFILE\"
280 IGNOREPROP
=wrapper.ignore_signals
=TRUE
283 # Build the lock file clause. Only create a lock file if the lock directory exists on this platform.
289 LOCKPROP
=wrapper.lockfile
=\"$LOCKFILE\"
297 # Check the configured user. If necessary rerun this script as the desired user.
298 if [ "X$RUN_AS_USER" != "X" ]
300 # Resolve the location of the 'id' command
301 IDEXE
="/usr/xpg4/bin/id"
307 echo "Unable to locate 'id'."
308 echo "Please report this message along with the location of the command on your system."
313 if [ "`$IDEXE -u -n`" = "$RUN_AS_USER" ]
315 # Already running as the configured user. Avoid password prompts by not calling su.
319 if [ "X$RUN_AS_USER" != "X" ]
321 # If LOCKPROP and $RUN_AS_USER are defined then the new user will most likely not be
322 # able to create the lock file. The Wrapper will be able to update this file once it
323 # is created but will not be able to delete it on shutdown. If $2 is defined then
324 # the lock file should be created for the current command
325 if [ "X$LOCKPROP" != "X" ]
329 # Resolve the primary group
330 RUN_AS_GROUP
=`groups $RUN_AS_USER | awk '{print $3}' | tail -1`
331 if [ "X$RUN_AS_GROUP" = "X" ]
333 RUN_AS_GROUP
=$RUN_AS_USER
336 chown
$RUN_AS_USER:$RUN_AS_GROUP $LOCKFILE
340 # Still want to change users, recurse. This means that the user will only be
341 # prompted for a password once. Variables shifted by 1
342 su
-m $RUN_AS_USER -c "\"$REALPATH\" $2"
344 # Now that we are the original user again, we may need to clean up the lock file.
345 if [ "X$LOCKPROP" != "X" ]
350 # Wrapper is not running so make sure the lock file is deleted.
351 if [ -f "$LOCKFILE" ]
368 if [ "X$pid" != "X" ]
370 # It is possible that 'a' process with the pid exists but that it is not the
371 # correct process. This can happen in a number of cases, but the most
372 # common is during system startup after an unclean shutdown.
373 # The ps statement below looks for the specific wrapper command running as
374 # the pid. If it is not found then the pid file is considered to be stale.
375 pidtest
=`$PSEXE -p $pid -o args | grep "$WRAPPER_CMD" | tail -1`
376 if [ "X$pidtest" = "X" ]
378 # This is a stale pid file.
380 echo "Removed stale pid file: $PIDFILE"
385 echo "Cannot read $PIDFILE."
392 pid
=`$PSEXE -p $pid | grep $pid | grep -v grep | awk '{print $1}' | tail -1`
395 # Process is gone so remove the pid file.
402 echo "Running $APP_LONG_NAME..."
406 # The string passed to eval must handles spaces in paths correctly.
407 COMMAND_LINE
="$CMDNICE \"$WRAPPER_CMD\" \"$WRAPPER_CONF\" wrapper.syslog.ident=$APP_NAME wrapper.pidfile=\"$PIDFILE\" $ANCHORPROP $LOCKPROP"
410 echo "$APP_LONG_NAME is already running."
416 echo "Starting $APP_LONG_NAME..."
420 # The string passed to eval must handles spaces in paths correctly.
421 COMMAND_LINE
="$CMDNICE \"$WRAPPER_CMD\" \"$WRAPPER_CONF\" wrapper.syslog.ident=$APP_NAME wrapper.pidfile=\"$PIDFILE\" wrapper.daemonize=TRUE $ANCHORPROP $IGNOREPROP $LOCKPROP"
424 echo "$APP_LONG_NAME is already running."
428 if [ "X$pid" != "X" ]
430 echo "Started $APP_LONG_NAME."
432 echo "Failed to start $APP_LONG_NAME."
437 echo "Stopping $APP_LONG_NAME..."
441 echo "$APP_LONG_NAME was not running."
443 if [ "X$IGNORE_SIGNALS" = "X" ]
445 # Running so try to stop it.
449 # An explanation for the failure should have been given
450 echo "Unable to stop $APP_LONG_NAME."
455 if [ -f "$ANCHORFILE" ]
457 # An explanation for the failure should have been given
458 echo "Unable to stop $APP_LONG_NAME."
463 # We can not predict how long it will take for the wrapper to
464 # actually stop as it depends on settings in wrapper.conf.
465 # Loop until it does.
469 while [ "X$pid" != "X" ]
471 # Show a waiting message every 5 seconds.
472 if [ "$CNT" -lt "5" ]
476 echo "Waiting for $APP_LONG_NAME to exit..."
479 TOTCNT
=`expr $TOTCNT + 1`
488 if [ "X$pid" != "X" ]
490 echo "Failed to stop $APP_LONG_NAME."
493 echo "Stopped $APP_LONG_NAME."
502 echo "$APP_LONG_NAME is not running."
505 echo "$APP_LONG_NAME is running ($pid)."
511 echo "Dumping $APP_LONG_NAME..."
515 echo "$APP_LONG_NAME was not running."
522 echo "Failed to dump $APP_LONG_NAME."
525 echo "Dumped $APP_LONG_NAME."
533 checkUser touchlock
$1
538 checkUser touchlock
$1
548 checkUser touchlock
$1
564 echo "Usage: $0 { console | start | stop | restart | status | dump }"