updated on Thu Jan 26 00:18:00 UTC 2012
[aur-mirror.git] / hudson / hudson
blobdca211dbd10a1c48368029241f20d4060161c00e
1 #! /bin/sh
4 # Copyright (c) 1999, 2010 Tanuki Software, Ltd.
5 # http://www.tanukisoftware.com
6 # All rights reserved.
8 # This software is the proprietary information of Tanuki Software.
9 # You shall use it only in accordance with the terms of the
10 # license agreement you entered into with Tanuki Software.
11 # http://wrapper.tanukisoftware.org/doc/english/licenseOverview.html
13 # Java Service Wrapper sh script. Suitable for starting and stopping
14 # wrapped Java applications on UNIX platforms.
17 #-----------------------------------------------------------------------------
18 # These settings can be modified to fit the needs of your application
19 # Optimized for use with version 3.4.1 of the Wrapper.
21 . /etc/profile
23 # Application
24 APP_NAME="Hudson"
25 APP_LONG_NAME="Hudson Continuous build server"
27 # Wrapper
28 WRAPPER_CMD="/opt/hudson/bin/wrapper"
29 WRAPPER_CONF="/opt/hudson/conf/wrapper.conf"
31 # Priority at which to run the wrapper. See "man nice" for valid priorities.
32 # nice is only used if a priority is specified.
33 PRIORITY=
35 # Location of the pid file.
36 PIDDIR="/var/run/hudson"
38 # If uncommented, causes the Wrapper to be shutdown using an anchor file.
39 # When launched with the 'start' command, it will also ignore all INT and
40 # TERM signals.
41 #IGNORE_SIGNALS=true
43 # Wrapper will start the JVM asynchronously. Your application may have some
44 # initialization tasks and it may be desirable to wait a few seconds
45 # before returning. For example, to delay the invocation of following
46 # startup scripts. Setting WAIT_AFTER_STARTUP to a positive number will
47 # cause the start command to delay for the indicated period of time
48 # (in seconds).
50 WAIT_AFTER_STARTUP=0
52 # If set, wait for the wrapper to report that the daemon has started
53 WAIT_FOR_STARTED_STATUS=true
54 WAIT_FOR_STARTED_TIMEOUT=120
56 # If set, the status, start_msg and stop_msg commands will print out detailed
57 # state information on the Wrapper and Java processes.
58 #DETAIL_STATUS=true
60 # If specified, the Wrapper will be run as the specified user.
61 # IMPORTANT - Make sure that the user has the required privileges to write
62 # the PID file and wrapper.log files. Failure to be able to write the log
63 # file will cause the Wrapper to exit without any way to write out an error
64 # message.
65 # NOTE - This will set the user which is used to run the Wrapper as well as
66 # the JVM and is not useful in situations where a privileged resource or
67 # port needs to be allocated prior to the user being changed.
68 RUN_AS_USER=hudson
70 # The following two lines are used by the chkconfig command. Change as is
71 # appropriate for your application. They should remain commented.
72 # chkconfig: 2345 20 80
73 # description: @app.long.name@
75 # When installing on On Mac OSX platforms, the following domain will be used to
76 # prefix the plist file name.
77 PLIST_DOMAIN=org.tanukisoftware.wrapper
79 # Initialization block for the install_initd and remove_initd scripts used by
80 # SUSE linux distributions.
81 ### BEGIN INIT INFO
82 # Provides: @app.name@
83 # Required-Start: $local_fs $network $syslog
84 # Should-Start:
85 # Required-Stop:
86 # Default-Start: 2 3 4 5
87 # Default-Stop: 0 1 6
88 # Short-Description: @app.long.name@
89 # Description: @app.description@
90 ### END INIT INFO
92 # Do not modify anything beyond this point
93 #-----------------------------------------------------------------------------
95 # Required for HP-UX Startup
96 if [ `uname -s` = "HP-UX" -o `uname -s` = "HP-UX64" ] ; then
97 PATH=$PATH:/usr/bin
100 # Get the fully qualified path to the script
101 case $0 in
103 SCRIPT="$0"
106 PWD=`pwd`
107 SCRIPT="$PWD/$0"
109 esac
111 # Resolve the true real path without any sym links.
112 CHANGED=true
113 while [ "X$CHANGED" != "X" ]
115 # Change spaces to ":" so the tokens can be parsed.
116 SAFESCRIPT=`echo $SCRIPT | sed -e 's; ;:;g'`
117 # Get the real path to this script, resolving any symbolic links
118 TOKENS=`echo $SAFESCRIPT | sed -e 's;/; ;g'`
119 REALPATH=
120 for C in $TOKENS; do
121 # Change any ":" in the token back to a space.
122 C=`echo $C | sed -e 's;:; ;g'`
123 REALPATH="$REALPATH/$C"
124 # If REALPATH is a sym link, resolve it. Loop for nested links.
125 while [ -h "$REALPATH" ] ; do
126 LS="`ls -ld "$REALPATH"`"
127 LINK="`expr "$LS" : '.*-> \(.*\)$'`"
128 if expr "$LINK" : '/.*' > /dev/null; then
129 # LINK is absolute.
130 REALPATH="$LINK"
131 else
132 # LINK is relative.
133 REALPATH="`dirname "$REALPATH"`""/$LINK"
135 done
136 done
138 if [ "$REALPATH" = "$SCRIPT" ]
139 then
140 CHANGED=""
141 else
142 SCRIPT="$REALPATH"
144 done
146 # Change the current directory to the location of the script
147 cd "`dirname "$REALPATH"`"
148 REALDIR=`pwd`
150 # If the PIDDIR is relative, set its value relative to the full REALPATH to avoid problems if
151 # the working directory is later changed.
152 FIRST_CHAR=`echo $PIDDIR | cut -c1,1`
153 if [ "$FIRST_CHAR" != "/" ]
154 then
155 PIDDIR=$REALDIR/$PIDDIR
157 # Same test for WRAPPER_CMD
158 FIRST_CHAR=`echo $WRAPPER_CMD | cut -c1,1`
159 if [ "$FIRST_CHAR" != "/" ]
160 then
161 WRAPPER_CMD=$REALDIR/$WRAPPER_CMD
163 # Same test for WRAPPER_CONF
164 FIRST_CHAR=`echo $WRAPPER_CONF | cut -c1,1`
165 if [ "$FIRST_CHAR" != "/" ]
166 then
167 WRAPPER_CONF=$REALDIR/$WRAPPER_CONF
170 # Process ID
171 ANCHORFILE="$PIDDIR/$APP_NAME.anchor"
172 STATUSFILE="$PIDDIR/$APP_NAME.status"
173 JAVASTATUSFILE="$PIDDIR/$APP_NAME.java.status"
174 PIDFILE="$PIDDIR/$APP_NAME.pid"
175 LOCKDIR="/var/lock/subsys"
176 LOCKFILE="$LOCKDIR/$APP_NAME"
177 pid=""
179 # Resolve the location of the 'ps' command
180 PSEXE="/usr/ucb/ps"
181 if [ ! -x "$PSEXE" ]
182 then
183 PSEXE="/usr/bin/ps"
184 if [ ! -x "$PSEXE" ]
185 then
186 PSEXE="/bin/ps"
187 if [ ! -x "$PSEXE" ]
188 then
189 echo "Unable to locate 'ps'."
190 echo "Please report this message along with the location of the command on your system."
191 exit 1
196 # Resolve the os
197 DIST_OS=`uname -s | tr [A-Z] [a-z] | tr -d ' '`
198 case "$DIST_OS" in
199 'sunos')
200 DIST_OS="solaris"
202 'hp-ux' | 'hp-ux64')
203 # HP-UX needs the XPG4 version of ps (for -o args)
204 DIST_OS="hpux"
205 UNIX95=""
206 export UNIX95
208 'darwin')
209 DIST_OS="macosx"
211 'unix_sv')
212 DIST_OS="unixware"
214 'os/390')
215 DIST_OS="zos"
217 esac
219 # Resolve the architecture
220 if [ "$DIST_OS" = "macosx" ]
221 then
222 DIST_ARCH="universal"
223 APP_PLIST_BASE=${PLIST_DOMAIN}.${APP_NAME}
224 APP_PLIST=${APP_PLIST_BASE}.plist
225 else
226 DIST_ARCH=
227 DIST_ARCH=`uname -p 2>/dev/null | tr [A-Z] [a-z] | tr -d ' '`
228 if [ "X$DIST_ARCH" = "X" ]
229 then
230 DIST_ARCH="unknown"
232 if [ "$DIST_ARCH" = "unknown" ]
233 then
234 DIST_ARCH=`uname -m 2>/dev/null | tr [A-Z] [a-z] | tr -d ' '`
236 case "$DIST_ARCH" in
237 'athlon' | 'i386' | 'i486' | 'i586' | 'i686')
238 DIST_ARCH="x86"
239 if [ "${DIST_OS}" = "solaris" ] ; then
240 DIST_BITS=`isainfo -b`
241 else
242 DIST_BITS="32"
245 'amd64' | 'x86_64')
246 DIST_ARCH="x86"
247 DIST_BITS="64"
249 'ia32')
250 DIST_ARCH="ia"
251 DIST_BITS="32"
253 'ia64' | 'ia64n' | 'ia64w')
254 DIST_ARCH="ia"
255 DIST_BITS="64"
257 'ip27')
258 DIST_ARCH="mips"
259 DIST_BITS="32"
261 'power' | 'powerpc' | 'power_pc' | 'ppc64')
262 if [ "${DIST_ARCH}" = "ppc64" ] ; then
263 DIST_BITS="64"
264 else
265 DIST_BITS="32"
267 DIST_ARCH="ppc"
268 if [ "${DIST_OS}" = "aix" ] ; then
269 if [ `getconf KERNEL_BITMODE` -eq 64 ]; then
270 DIST_BITS="64"
271 else
272 DIST_BITS="32"
276 'pa_risc' | 'pa-risc')
277 DIST_ARCH="parisc"
278 if [ `getconf KERNEL_BITS` -eq 64 ]; then
279 DIST_BITS="64"
280 else
281 DIST_BITS="32"
284 'sun4u' | 'sparcv9' | 'sparc')
285 DIST_ARCH="sparc"
286 DIST_BITS=`isainfo -b`
287 if [ ! -f /usr/lib/libm.so.2 -a "${DIST_BITS}" = "32" ]; then
288 ln -s /usr/lib/libm.so.1 /usr/lib/libm.so.2
289 elif [ ! -f /usr/lib/sparcv9/libm.so.2 -a "${DIST_BITS}" = "64" ]; then
290 ln -s /usr/lib/sparcv9/libm.so.1 /usr/lib/sparcv9/libm.so.2
293 '9000/800' | '9000/785')
294 DIST_ARCH="parisc"
295 if [ `getconf KERNEL_BITS` -eq 64 ]; then
296 DIST_BITS="64"
297 else
298 DIST_BITS="32"
301 '2097')
302 DIST_ARCH="390"
303 DIST_BITS="32"
305 esac
308 # OSX always places Java in the same location so we can reliably set JAVA_HOME
309 if [ "$DIST_OS" = "macosx" ]
310 then
311 if [ -z "$JAVA_HOME" ]; then
312 JAVA_HOME="/Library/Java/Home"; export JAVA_HOME
316 # Test Echo
317 ECHOTEST=`echo -n "x"`
318 if [ "$ECHOTEST" = "x" ]
319 then
320 ECHOOPT="-n "
321 else
322 ECHOOPT=""
325 outputFile() {
326 if [ -f "$1" ]
327 then
328 echo " $1 (Found but not executable.)";
329 else
330 echo " $1"
334 # Decide on the wrapper binary to use.
335 # If the bits of the OS could be detected, we will try to look for the
336 # binary with the correct bits value. If it doesn't exist, fall back
337 # and look for the 32-bit binary. If that doesn't exist either then
338 # look for the default.
339 WRAPPER_TEST_CMD="$WRAPPER_CMD-$DIST_OS-$DIST_ARCH-$DIST_BITS"
340 if [ -x "$WRAPPER_TEST_CMD" ]
341 then
342 WRAPPER_CMD="$WRAPPER_TEST_CMD"
343 else
344 WRAPPER_TEST_CMD="$WRAPPER_CMD-$DIST_OS-$DIST_ARCH-32"
345 if [ -x "$WRAPPER_TEST_CMD" ]
346 then
347 WRAPPER_CMD="$WRAPPER_TEST_CMD"
348 else
349 if [ ! -x "$WRAPPER_CMD" ]
350 then
351 echo "Unable to locate any of the following binaries:"
352 outputFile "$WRAPPER_CMD-$DIST_OS-$DIST_ARCH-$DIST_BITS"
353 if [ ! "$DIST_BITS" = "32" ]
354 then
355 outputFile "$WRAPPER_CMD-$DIST_OS-$DIST_ARCH-32"
357 outputFile "$WRAPPER_CMD"
358 exit 1
363 # Build the nice clause
364 if [ "X$PRIORITY" = "X" ]
365 then
366 CMDNICE=""
367 else
368 CMDNICE="nice -$PRIORITY"
371 # Build the anchor file clause.
372 if [ "X$IGNORE_SIGNALS" = "X" ]
373 then
374 ANCHORPROP=
375 IGNOREPROP=
376 else
377 ANCHORPROP=wrapper.anchorfile=\"$ANCHORFILE\"
378 IGNOREPROP=wrapper.ignore_signals=TRUE
381 # Build the status file clause.
382 if [ "X$DETAIL_STATUS$WAIT_FOR_STARTED_STATUS" = "X" ]
383 then
384 STATUSPROP=
385 else
386 STATUSPROP="wrapper.statusfile=\"$STATUSFILE\" wrapper.java.statusfile=\"$JAVASTATUSFILE\""
389 if [ ! -n "$WAIT_FOR_STARTED_STATUS" ]
390 then
391 WAIT_FOR_STARTED_STATUS=true
394 if [ $WAIT_FOR_STARTED_STATUS = true ] ; then
395 DETAIL_STATUS=true
399 # Build the lock file clause. Only create a lock file if the lock directory exists on this platform.
400 LOCKPROP=
401 if [ -d $LOCKDIR ]
402 then
403 if [ -w $LOCKDIR ]
404 then
405 LOCKPROP=wrapper.lockfile=\"$LOCKFILE\"
409 checkUser() {
410 # $1 touchLock flag
411 # $2 command
413 # Check the configured user. If necessary rerun this script as the desired user.
414 if [ "X$RUN_AS_USER" != "X" ]
415 then
416 # Resolve the location of the 'id' command
417 IDEXE="/usr/xpg4/bin/id"
418 if [ ! -x "$IDEXE" ]
419 then
420 IDEXE="/usr/bin/id"
421 if [ ! -x "$IDEXE" ]
422 then
423 echo "Unable to locate 'id'."
424 echo "Please report this message along with the location of the command on your system."
425 exit 1
429 if [ "`$IDEXE -u -n`" = "$RUN_AS_USER" ]
430 then
431 # Already running as the configured user. Avoid password prompts by not calling su.
432 RUN_AS_USER=""
435 if [ "X$RUN_AS_USER" != "X" ]
436 then
437 # If LOCKPROP and $RUN_AS_USER are defined then the new user will most likely not be
438 # able to create the lock file. The Wrapper will be able to update this file once it
439 # is created but will not be able to delete it on shutdown. If $2 is defined then
440 # the lock file should be created for the current command
441 if [ "X$LOCKPROP" != "X" ]
442 then
443 if [ "X$1" != "X" ]
444 then
445 # Resolve the primary group
446 RUN_AS_GROUP=`groups $RUN_AS_USER | awk '{print $3}' | tail -1`
447 if [ "X$RUN_AS_GROUP" = "X" ]
448 then
449 RUN_AS_GROUP=$RUN_AS_USER
451 touch $LOCKFILE
452 chown $RUN_AS_USER:$RUN_AS_GROUP $LOCKFILE
456 # Still want to change users, recurse. This means that the user will only be
457 # prompted for a password once. Variables shifted by 1
459 # Use "runuser" if this exists. runuser should be used on RedHat in preference to su.
461 if test -f "/sbin/runuser"
462 then
463 /sbin/runuser - $RUN_AS_USER -c "\"$REALPATH\" $2"
464 else
465 su - $RUN_AS_USER -c "\"$REALPATH\" $2"
468 # Now that we are the original user again, we may need to clean up the lock file.
469 if [ "X$LOCKPROP" != "X" ]
470 then
471 getpid
472 if [ "X$pid" = "X" ]
473 then
474 # Wrapper is not running so make sure the lock file is deleted.
475 if [ -f "$LOCKFILE" ]
476 then
477 rm "$LOCKFILE"
482 exit 0
486 getpid() {
487 pid=""
488 if [ -f "$PIDFILE" ]
489 then
490 if [ -r "$PIDFILE" ]
491 then
492 pid=`cat "$PIDFILE"`
493 if [ "X$pid" != "X" ]
494 then
495 # It is possible that 'a' process with the pid exists but that it is not the
496 # correct process. This can happen in a number of cases, but the most
497 # common is during system startup after an unclean shutdown.
498 # The ps statement below looks for the specific wrapper command running as
499 # the pid. If it is not found then the pid file is considered to be stale.
500 case "$DIST_OS" in
501 'freebsd')
502 pidtest=`$PSEXE -p $pid -o args | tail -1`
503 if [ "X$pidtest" = "XCOMMAND" ]
504 then
505 pidtest=""
508 'macosx')
509 pidtest=`$PSEXE -ww -p $pid -o command | grep "$WRAPPER_CMD" | tail -1`
511 'solaris')
512 if [ -f "/usr/bin/pargs" ]
513 then
514 pidtest=`pargs $pid | grep "$WRAPPER_CMD" | tail -1`
515 else
516 case "$PSEXE" in
517 '/usr/ucb/ps')
518 pidtest=`$PSEXE -auxww $pid | grep "$WRAPPER_CMD" | tail -1`
520 '/usr/bin/ps')
521 TRUNCATED_CMD=`$PSEXE -o comm -p $pid | tail -1`
522 COUNT=`echo $TRUNCATED_CMD | wc -m`
523 COUNT=`echo ${COUNT}`
524 COUNT=`expr $COUNT - 1`
525 TRUNCATED_CMD=`echo $WRAPPER_CMD | cut -c1-$COUNT`
526 pidtest=`$PSEXE -o comm -p $pid | grep "$TRUNCATED_CMD" | tail -1`
528 '/bin/ps')
529 TRUNCATED_CMD=`$PSEXE -o comm -p $pid | tail -1`
530 COUNT=`echo $TRUNCATED_CMD | wc -m`
531 COUNT=`echo ${COUNT}`
532 COUNT=`expr $COUNT - 1`
533 TRUNCATED_CMD=`echo $WRAPPER_CMD | cut -c1-$COUNT`
534 pidtest=`$PSEXE -o comm -p $pid | grep "$TRUNCATED_CMD" | tail -1`
537 echo "Unsupported ps command $PSEXE"
538 exit 1
540 esac
543 'hpux')
544 pidtest=`$PSEXE -p $pid -x -o args | grep "$WRAPPER_CMD" | tail -1`
547 pidtest=`$PSEXE -p $pid -o args | grep "$WRAPPER_CMD" | tail -1`
549 esac
551 if [ "X$pidtest" = "X" ]
552 then
553 # This is a stale pid file.
554 rm -f "$PIDFILE"
555 echo "Removed stale pid file: $PIDFILE"
556 pid=""
559 else
560 echo "Cannot read $PIDFILE."
561 exit 1
566 getstatus() {
567 STATUS=
568 if [ -f "$STATUSFILE" ]
569 then
570 if [ -r "$STATUSFILE" ]
571 then
572 STATUS=`cat "$STATUSFILE"`
575 if [ "X$STATUS" = "X" ]
576 then
577 STATUS="Unknown"
580 JAVASTATUS=
581 if [ -f "$JAVASTATUSFILE" ]
582 then
583 if [ -r "$JAVASTATUSFILE" ]
584 then
585 JAVASTATUS=`cat "$JAVASTATUSFILE"`
588 if [ "X$JAVASTATUS" = "X" ]
589 then
590 JAVASTATUS="Unknown"
594 testpid() {
595 case "$DIST_OS" in
596 'solaris')
597 case "$PSEXE" in
598 '/usr/ucb/ps')
599 pid=`$PSEXE $pid | grep $pid | grep -v grep | awk '{print $1}' | tail -1`
601 '/usr/bin/ps')
602 pid=`$PSEXE -p $pid | grep $pid | grep -v grep | awk '{print $1}' | tail -1`
604 '/bin/ps')
605 pid=`$PSEXE -p $pid | grep $pid | grep -v grep | awk '{print $1}' | tail -1`
608 echo "Unsupported ps command $PSEXE"
609 exit 1
611 esac
614 pid=`$PSEXE -p $pid | grep $pid | grep -v grep | awk '{print $1}' | tail -1` 2>/dev/null
616 esac
617 if [ "X$pid" = "X" ]
618 then
619 # Process is gone so remove the pid file.
620 rm -f "$PIDFILE"
621 pid=""
625 launchdtrap() {
626 stopit
627 exit
630 waitforwrapperstop() {
631 getpid
632 while [ "X$pid" != "X" ] ; do
633 sleep 1
634 getpid
635 done
638 launchdinternal() {
639 getpid
640 trap launchdtrap TERM
641 if [ "X$pid" = "X" ]
642 then
643 # The string passed to eval must handles spaces in paths correctly.
644 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"
645 eval $COMMAND_LINE
646 else
647 echo "$APP_LONG_NAME is already running."
648 exit 1
650 # launchd expects that this script stay up and running so we need to do our own monitoring of the Wrapper process.
651 if [ $WAIT_FOR_STARTED_STATUS = true ]
652 then
653 waitforwrapperstop
657 console() {
658 echo "Running $APP_LONG_NAME..."
659 getpid
660 if [ "X$pid" = "X" ]
661 then
662 trap '' 3
663 # The string passed to eval must handles spaces in paths correctly.
664 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"
665 eval $COMMAND_LINE
666 else
667 echo "$APP_LONG_NAME is already running."
668 exit 1
672 waitforjavastartup() {
673 getstatus
674 echo $ECHOOPT"Waiting for $APP_LONG_NAME..."
676 # Wait until the timeout or we have something besides Unknown.
677 counter=15
678 while [ "$JAVASTATUS" = "Unknown" -a $counter -gt 0 -a -n "$JAVASTATUS" ] ; do
679 echo $ECHOOPT"."
680 sleep 1
681 getstatus
682 counter=`expr $counter - 1`
683 done
685 if [ -n "$WAIT_FOR_STARTED_TIMEOUT" ] ; then
686 counter=$WAIT_FOR_STARTED_TIMEOUT
687 else
688 counter=120
690 while [ "$JAVASTATUS" != "STARTED" -a "$JAVASTATUS" != "Unknown" -a $counter -gt 0 -a -n "$JAVASTATUS" ] ; do
691 echo $ECHOOPT"."
692 sleep 1
693 getstatus
694 counter=`expr $counter - 1`
695 done
696 if [ "X$ECHOOPT" != "X" ] ; then
697 echo ""
699 echo "$APP_LONG_NAME started."
702 startwait() {
703 if [ $WAIT_FOR_STARTED_STATUS = true ]
704 then
705 waitforjavastartup
707 # Sleep for a few seconds to allow for intialization if required
708 # then test to make sure we're still running.
711 while [ $i -lt $WAIT_AFTER_STARTUP ]
713 sleep 1
714 echo $ECHOOPT"."
715 i=`expr $i + 1`
716 done
717 if [ $WAIT_AFTER_STARTUP -gt 0 ]
718 then
719 getpid
720 if [ "X$pid" = "X" ]
721 then
722 echo " WARNING: $APP_LONG_NAME may have failed to start."
723 exit 1
724 else
725 echo " running ($pid)."
727 else
728 echo ""
732 macosxstart() {
733 # The daemon has been installed.
734 echo "Starting $APP_LONG_NAME. Detected Mac OSX and installed launchd daemon."
735 if [ `id | sed 's/^uid=//;s/(.*$//'` != "0" ] ; then
736 echo "Must be root to perform this action."
737 exit 1
740 getpid
741 if [ "X$pid" != "X" ] ; then
742 echo "$APP_LONG_NAME is already running."
743 exit 1
746 # If the daemon was just installed, it may not be loaded.
747 LOADED_PLIST=`launchctl list | grep ${APP_PLIST_BASE}`
748 if [ "X${LOADED_PLIST}" = "X" ] ; then
749 launchctl load /Library/LaunchDaemons/${APP_PLIST}
751 # If launchd is set to run the daemon already at Load, we don't need to call start
752 getpid
753 if [ "X$pid" == "X" ] ; then
754 launchctl start ${APP_PLIST_BASE}
757 startwait
760 start() {
761 echo $ECHOOPT"Starting $APP_LONG_NAME..."
762 getpid
763 if [ "X$pid" = "X" ]
764 then
765 # The string passed to eval must handles spaces in paths correctly.
766 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"
767 eval $COMMAND_LINE
768 else
769 echo "$APP_LONG_NAME is already running."
770 exit 1
773 startwait
776 stopit() {
777 # $1 exit if down flag
779 echo "Stopping $APP_LONG_NAME..."
780 getpid
781 if [ "X$pid" = "X" ]
782 then
783 echo "$APP_LONG_NAME was not running."
784 if [ "X$1" = "X1" ]
785 then
786 exit 1
788 else
789 if [ "X$IGNORE_SIGNALS" = "X" ]
790 then
791 # Running so try to stop it.
792 kill $pid
793 if [ $? -ne 0 ]
794 then
795 # An explanation for the failure should have been given
796 echo "Unable to stop $APP_LONG_NAME."
797 exit 1
799 else
800 rm -f "$ANCHORFILE"
801 if [ -f "$ANCHORFILE" ]
802 then
803 # An explanation for the failure should have been given
804 echo "Unable to stop $APP_LONG_NAME."
805 exit 1
809 # We can not predict how long it will take for the wrapper to
810 # actually stop as it depends on settings in wrapper.conf.
811 # Loop until it does.
812 savepid=$pid
813 CNT=0
814 TOTCNT=0
815 while [ "X$pid" != "X" ]
817 # Show a waiting message every 5 seconds.
818 if [ "$CNT" -lt "5" ]
819 then
820 CNT=`expr $CNT + 1`
821 else
822 echo "Waiting for $APP_LONG_NAME to exit..."
823 CNT=0
825 TOTCNT=`expr $TOTCNT + 1`
827 sleep 1
829 testpid
830 done
832 pid=$savepid
833 testpid
834 if [ "X$pid" != "X" ]
835 then
836 echo "Failed to stop $APP_LONG_NAME."
837 exit 1
838 else
839 echo "Stopped $APP_LONG_NAME."
844 status() {
845 getpid
846 if [ "X$pid" = "X" ]
847 then
848 echo "$APP_LONG_NAME is not running."
849 exit 1
850 else
851 if [ "X$DETAIL_STATUS" = "X" ]
852 then
853 echo "$APP_LONG_NAME is running (PID:$pid)."
854 else
855 getstatus
856 echo "$APP_LONG_NAME is running (PID:$pid, Wrapper:$STATUS, Java:$JAVASTATUS)"
858 exit 0
862 installdaemon() {
863 if [ `id | sed 's/^uid=//;s/(.*$//'` != "0" ] ; then
864 echo "Must be root to perform this action."
865 exit 1
866 else
867 if [ "$DIST_OS" = "solaris" ] ; then
868 echo "Detected Solaris:"
869 if [ -f /etc/init.d/$APP_NAME ] ; then
870 echo " The $APP_LONG_NAME daemon is already installed."
871 exit 1
872 else
873 echo " Installing the $APP_LONG_NAME daemon.."
874 ln -s $REALPATH /etc/init.d/$APP_NAME
875 ln -s /etc/init.d/$APP_NAME /etc/rc3.d/K20$APP_NAME
876 ln -s /etc/init.d/$APP_NAME /etc/rc3.d/S20$APP_NAME
878 elif [ "$DIST_OS" = "linux" ] ; then
879 if [ -f /etc/redhat-release -o -f /etc/redhat_version -o -f /etc/fedora-release ] ; then
880 echo "Detected RHEL or Fedora:"
881 if [ -f /etc/init.d/$APP_NAME ] ; then
882 echo " The $APP_LONG_NAME daemon is already installed."
883 exit 1
884 else
885 echo " Installing the $APP_LONG_NAME daemon.."
886 ln -s $REALPATH /etc/init.d/$APP_NAME
887 /sbin/chkconfig --add $APP_NAME
888 /sbin/chkconfig $APP_NAME on
890 elif [ -f /etc/SuSE-release ] ; then
891 echo "Detected SuSE or SLES:"
892 if [ -f /etc/init.d/$APP_NAME ] ; then
893 echo " The $APP_LONG_NAME daemon is already installed."
894 exit 1
895 else
896 echo " Installing the $APP_LONG_NAME daemon.."
897 ln -s $REALPATH /etc/init.d/$APP_NAME
898 insserv /etc/init.d/$APP_NAME
900 elif [ -f /etc/lsb-release ] ; then
901 echo "Detected Ubuntu:"
902 if [ -f /etc/init.d/$APP_NAME ] ; then
903 echo " The $APP_LONG_NAME daemon is already installed."
904 exit 1
905 else
906 echo " Installing the $APP_LONG_NAME daemon.."
907 ln -s $REALPATH /etc/init.d/$APP_NAME
908 update-rc.d $APP_NAME defaults
910 else
911 echo "Detected Linux:"
912 if [ -f /etc/init.d/$APP_NAME ] ; then
913 echo " The $APP_LONG_NAME daemon is already installed."
914 exit 1
915 else
916 echo " Installing the $APP_LONG_NAME daemon.."
917 ln -s $REALPATH /etc/init.d/$APP_NAME
918 ln -s /etc/init.d/$APP_NAME /etc/rc3.d/K20$APP_NAME
919 ln -s /etc/init.d/$APP_NAME /etc/rc3.d/S20$APP_NAME
920 ln -s /etc/init.d/$APP_NAME /etc/rc5.d/S20$APP_NAME
921 ln -s /etc/init.d/$APP_NAME /etc/rc5.d/K20$APP_NAME
924 elif [ "$DIST_OS" = "hpux" ] ; then
925 echo "Detected HP-UX:"
926 if [ -f /sbin/init.d/$APP_NAME ] ; then
927 echo " The $APP_LONG_NAME daemon is already installed."
928 exit 1
929 else
930 echo " Installing the $APP_LONG_NAME daemon.."
931 ln -s $REALPATH /sbin/init.d/$APP_NAME
932 ln -s /sbin/init.d/$APP_NAME /sbin/rc3.d/K20$APP_NAME
933 ln -s /sbin/init.d/$APP_NAME /sbin/rc3.d/S20$APP_NAME
935 elif [ "$DIST_OS" = "aix" ] ; then
936 echo "Detected AIX:"
937 if [ -f /etc/rc.d/init.d/$APP_NAME ] ; then
938 echo " The $APP_LONG_NAME daemon is already installed."
939 exit 1
940 else
941 echo " Installing the $APP_LONG_NAME daemon.."
942 ln -s $REALPATH /etc/rc.d/init.d/$APP_NAME
943 ln -s /etc/rc.d/init.d/$APP_NAME /etc/rc.d/rc2.d/S20$APP_NAME
944 ln -s /etc/rc.d/init.d/$APP_NAME /etc/rc.d/rc2.d/K20$APP_NAME
946 elif [ "$DIST_OS" = "freebsd" ] ; then
947 echo "Detected FreeBSD:"
948 if [ -f /etc/rc.d/$APP_NAME ] ; then
949 echo " The $APP_LONG_NAME daemon is already installed."
950 exit 1
951 else
952 echo " Installing the $APP_LONG_NAME daemon.."
953 sed -i .bak "/${APP_NAME}_enable=\"YES\"/d" /etc/rc.conf
954 if [ -f ${REALDIR}/${APP_NAME}.install ] ; then
955 ln -s ${REALDIR}/${APP_NAME}.install /etc/rc.d/$APP_NAME
956 else
957 echo '#!/bin/sh' > /etc/rc.d/$APP_NAME
958 echo "#" >> /etc/rc.d/$APP_NAME
959 echo "# PROVIDE: $APP_NAME" >> /etc/rc.d/$APP_NAME
960 echo "# REQUIRE: NETWORKING" >> /etc/rc.d/$APP_NAME
961 echo "# KEYWORD: shutdown" >> /etc/rc.d/$APP_NAME
962 echo ". /etc/rc.subr" >> /etc/rc.d/$APP_NAME
963 echo "name=\"$APP_NAME\"" >> /etc/rc.d/$APP_NAME
964 echo "rcvar=\`set_rcvar\`" >> /etc/rc.d/$APP_NAME
965 echo "command=\"${REALDIR}/${APP_NAME}\"" >> /etc/rc.d/$APP_NAME
966 echo 'start_cmd="${name}_start"' >> /etc/rc.d/$APP_NAME
967 echo 'load_rc_config $name' >> /etc/rc.d/$APP_NAME
968 echo 'status_cmd="${name}_status"' >> /etc/rc.d/$APP_NAME
969 echo 'stop_cmd="${name}_stop"' >> /etc/rc.d/$APP_NAME
970 echo "${APP_NAME}_status() {" >> /etc/rc.d/$APP_NAME
971 echo '${command} status' >> /etc/rc.d/$APP_NAME
972 echo '}' >> /etc/rc.d/$APP_NAME
973 echo "${APP_NAME}_stop() {" >> /etc/rc.d/$APP_NAME
974 echo '${command} stop' >> /etc/rc.d/$APP_NAME
975 echo '}' >> /etc/rc.d/$APP_NAME
976 echo "${APP_NAME}_start() {" >> /etc/rc.d/$APP_NAME
977 echo '${command} start' >> /etc/rc.d/$APP_NAME
978 echo '}' >> /etc/rc.d/$APP_NAME
979 echo 'run_rc_command "$1"' >> /etc/rc.d/$APP_NAME
981 echo "${APP_NAME}_enable=\"YES\"" >> /etc/rc.conf
982 chmod 555 /etc/rc.d/$APP_NAME
984 elif [ "$DIST_OS" = "macosx" ] ; then
985 echo "Detected Mac OSX:"
986 if [ -f /Library/LaunchDaemons/${APP_PLIST} ] ; then
987 echo " The $APP_LONG_NAME daemon is already installed."
988 exit 1
989 else
990 echo " Installing the $APP_LONG_NAME daemon.."
991 if [ -f ${REALDIR}/${APP_PLIST} ] ; then
992 ln -s ${REALDIR}/${APP_PLIST} /Library/LaunchDaemons/${APP_PLIST}
993 else
994 echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" > /Library/LaunchDaemons/${APP_PLIST}
995 echo "<!DOCTYPE plist PUBLIC \"-//Apple Computer//DTD PLIST 1.0//EN\"" >> /Library/LaunchDaemons/${APP_PLIST}
996 echo "\"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">" >> /Library/LaunchDaemons/${APP_PLIST}
997 echo "<plist version=\"1.0\">" >> /Library/LaunchDaemons/${APP_PLIST}
998 echo " <dict>" >> /Library/LaunchDaemons/${APP_PLIST}
999 echo " <key>Label</key>" >> /Library/LaunchDaemons/${APP_PLIST}
1000 echo " <string>${APP_PLIST_BASE}</string>" >> /Library/LaunchDaemons/${APP_PLIST}
1001 echo " <key>ProgramArguments</key>" >> /Library/LaunchDaemons/${APP_PLIST}
1002 echo " <array>" >> /Library/LaunchDaemons/${APP_PLIST}
1003 echo " <string>${REALDIR}/${APP_NAME}</string>" >> /Library/LaunchDaemons/${APP_PLIST}
1004 echo " <string>launchdinternal</string>" >> /Library/LaunchDaemons/${APP_PLIST}
1005 echo " </array>" >> /Library/LaunchDaemons/${APP_PLIST}
1006 echo " <key>OnDemand</key>" >> /Library/LaunchDaemons/${APP_PLIST}
1007 echo " <true/>" >> /Library/LaunchDaemons/${APP_PLIST}
1008 echo " <key>RunAtLoad</key>" >> /Library/LaunchDaemons/${APP_PLIST}
1009 echo " <true/>" >> /Library/LaunchDaemons/${APP_PLIST}
1010 if [ "X$RUN_AS_USER" != "X" ] ; then
1011 echo " <key>UserName</key>" >> /Library/LaunchDaemons/${APP_PLIST}
1012 echo " <string>${RUN_AS_USER}</string>" >> /Library/LaunchDaemons/${APP_PLIST}
1014 echo " </dict>" >> /Library/LaunchDaemons/${APP_PLIST}
1015 echo "</plist>" >> /Library/LaunchDaemons/${APP_PLIST}
1017 chmod 555 /Library/LaunchDaemons/${APP_PLIST}
1019 elif [ "$DIST_OS" = "zos" ] ; then
1020 echo "Detected z/OS:"
1021 if [ -f /etc/rc.bak ] ; then
1022 echo " The $APP_LONG_NAME daemon is already installed."
1023 exit 1
1024 else
1025 echo " Installing the $APP_LONG_NAME daemon.."
1026 cp /etc/rc /etc/rc.bak
1027 sed "s:echo /etc/rc script executed, \`date\`::g" /etc/rc.bak > /etc/rc
1028 echo "_BPX_JOBNAME='${APP_NAME}' ${REALDIR}/${APP_NAME} start" >>/etc/rc
1029 echo '/etc/rc script executed, `date`' >>/etc/rc
1031 else
1032 echo "Install not currently supported for $DIST_OS"
1033 exit 1
1038 removedaemon() {
1039 if [ `id | sed 's/^uid=//;s/(.*$//'` != "0" ] ; then
1040 echo "Must be root to perform this action."
1041 exit 1
1042 else
1043 stopit "0"
1044 if [ "$DIST_OS" = "solaris" ] ; then
1045 echo "Detected Solaris:"
1046 if [ -f /etc/init.d/$APP_NAME ] ; then
1047 echo " Removing $APP_LONG_NAME daemon..."
1048 for i in /etc/rc3.d/S20$APP_NAME /etc/rc3.d/K20$APP_NAME /etc/init.d/$APP_NAME
1050 rm -f $i
1051 done
1052 else
1053 echo " The $APP_LONG_NAME daemon is not currently installed."
1054 exit 1
1056 elif [ "$DIST_OS" = "linux" ] ; then
1057 if [ -f /etc/redhat-release -o -f /etc/redhat_version -o -f /etc/fedora-release ] ; then
1058 echo "Detected RHEL or Fedora:"
1059 if [ -f /etc/init.d/$APP_NAME ] ; then
1060 echo " Removing $APP_LONG_NAME daemon..."
1061 /sbin/chkconfig $APP_NAME off
1062 /sbin/chkconfig --del $APP_NAME
1063 rm -f /etc/init.d/$APP_NAME
1064 else
1065 echo " The $APP_LONG_NAME daemon is not currently installed."
1066 exit 1
1068 elif [ -f /etc/SuSE-release ] ; then
1069 echo "Detected SuSE or SLES:"
1070 if [ -f /etc/init.d/$APP_NAME ] ; then
1071 echo " Removing $APP_LONG_NAME daemon..."
1072 insserv -r /etc/init.d/$APP_NAME
1073 rm -f /etc/init.d/$APP_NAME
1074 else
1075 echo " The $APP_LONG_NAME daemon is not currently installed."
1076 exit 1
1078 elif [ -f /etc/lsb-release ] ; then
1079 echo "Detected Ubuntu:"
1080 if [ -f /etc/init.d/$APP_NAME ] ; then
1081 echo " Removing $APP_LONG_NAME daemon..."
1082 update-rc.d -f $APP_NAME remove
1083 rm -f /etc/init.d/$APP_NAME
1084 else
1085 echo " The $APP_LONG_NAME daemon is not currently installed."
1086 exit 1
1088 else
1089 echo "Detected Linux:"
1090 if [ -f /etc/init.d/$APP_NAME ] ; then
1091 echo " Removing $APP_LONG_NAME daemon..."
1092 for i in /etc/rc3.d/K20$APP_NAME /etc/rc5.d/K20$APP_NAME /etc/rc3.d/S20$APP_NAME /etc/init.d/$APP_NAME /etc/rc5.d/S20$APP_NAME
1094 rm -f $i
1095 done
1096 else
1097 echo " The $APP_LONG_NAME daemon is not currently installed."
1098 exit 1
1101 elif [ "$DIST_OS" = "hpux" ] ; then
1102 echo "Detected HP-UX:"
1103 if [ -f /sbin/init.d/$APP_NAME ] ; then
1104 echo " Removing $APP_LONG_NAME daemon..."
1105 for i in /sbin/rc3.d/K20$APP_NAME /sbin/rc3.d/S20$APP_NAME /sbin/init.d/$APP_NAME
1107 rm -f $i
1108 done
1109 else
1110 echo " The $APP_LONG_NAME daemon is not currently installed."
1111 exit 1
1113 elif [ "$DIST_OS" = "aix" ] ; then
1114 echo "Detected AIX:"
1115 if [ -f /etc/rc.d/init.d/$APP_NAME ] ; then
1116 echo " Removing $APP_LONG_NAME daemon..."
1117 for i in /etc/rc.d/rc2.d/S20$APP_NAME /etc/rc.d/rc2.d/K20$APP_NAME /etc/rc.d/init.d/$APP_NAME
1119 rm -f $i
1120 done
1121 else
1122 echo " The $APP_LONG_NAME daemon is not currently installed."
1123 exit 1
1125 elif [ "$DIST_OS" = "freebsd" ] ; then
1126 echo "Detected FreeBSD:"
1127 if [ -f /etc/rc.d/$APP_NAME ] ; then
1128 echo " Removing $APP_LONG_NAME daemon..."
1129 for i in /etc/rc.d/$APP_NAME
1131 rm -f $i
1132 done
1133 sed -i .bak "/${APP_NAME}_enable=\"YES\"/d" /etc/rc.conf
1134 else
1135 echo " The $APP_LONG_NAME daemon is not currently installed."
1136 exit 1
1138 elif [ "$DIST_OS" = "macosx" ] ; then
1139 echo "Detected Mac OSX:"
1140 if [ -f "/Library/LaunchDaemons/${APP_PLIST}" ] ; then
1141 echo " Removing $APP_LONG_NAME daemon..."
1142 # Make sure the plist is installed
1143 LOADED_PLIST=`launchctl list | grep ${APP_PLIST_BASE}`
1144 if [ "X${LOADED_PLIST}" != "X" ] ; then
1145 launchctl unload /Library/LaunchDaemons/${APP_PLIST}
1147 rm -f /Library/LaunchDaemons/${APP_PLIST}
1148 else
1149 echo " The $APP_LONG_NAME daemon is not currently installed."
1150 exit 1
1152 elif [ "$DIST_OS" = "zos" ] ; then
1153 echo "Detected z/OS:"
1154 if [ -f /etc/rc.bak ] ; then
1155 echo " Removing $APP_LONG_NAME daemon..."
1156 cp /etc/rc /etc/rc.bak
1157 sed "s/_BPX_JOBNAME=\'APP_NAME\'.*//g" /etc/rc.bak > /etc/rc
1158 rm /etc/rc.bak
1159 else
1160 echo " The $APP_LONG_NAME daemon is not currently installed."
1161 exit 1
1163 else
1164 echo "Remove not currently supported for $DIST_OS"
1165 exit 1
1170 dump() {
1171 echo "Dumping $APP_LONG_NAME..."
1172 getpid
1173 if [ "X$pid" = "X" ]
1174 then
1175 echo "$APP_LONG_NAME was not running."
1176 else
1177 kill -3 $pid
1179 if [ $? -ne 0 ]
1180 then
1181 echo "Failed to dump $APP_LONG_NAME."
1182 exit 1
1183 else
1184 echo "Dumped $APP_LONG_NAME."
1189 # Used by HP-UX init scripts.
1190 startmsg() {
1191 getpid
1192 if [ "X$pid" = "X" ]
1193 then
1194 echo "Starting $APP_LONG_NAME... (Wrapper:Stopped)"
1195 else
1196 if [ "X$DETAIL_STATUS" = "X" ]
1197 then
1198 echo "Starting $APP_LONG_NAME... (Wrapper:Running)"
1199 else
1200 getstatus
1201 echo "Starting $APP_LONG_NAME... (Wrapper:$STATUS, Java:$JAVASTATUS)"
1206 # Used by HP-UX init scripts.
1207 stopmsg() {
1208 getpid
1209 if [ "X$pid" = "X" ]
1210 then
1211 echo "Stopping $APP_LONG_NAME... (Wrapper:Stopped)"
1212 else
1213 if [ "X$DETAIL_STATUS" = "X" ]
1214 then
1215 echo "Stopping $APP_LONG_NAME... (Wrapper:Running)"
1216 else
1217 getstatus
1218 echo "Stopping $APP_LONG_NAME... (Wrapper:$STATUS, Java:$JAVASTATUS)"
1223 case "$1" in
1225 'console')
1226 checkUser touchlock $1
1227 console
1230 'start')
1231 if [ "$DIST_OS" = "macosx" -a -f "/Library/LaunchDaemons/${APP_PLIST}" ] ; then
1232 macosxstart
1233 else
1234 checkUser touchlock $1
1235 start
1239 'stop')
1240 checkUser "" $1
1241 stopit "0"
1244 'restart')
1245 checkUser touchlock $1
1246 stopit "0"
1247 start
1250 'condrestart')
1251 checkUser touchlock $1
1252 stopit "1"
1253 start
1256 'status')
1257 checkUser "" $1
1258 status
1261 'install')
1262 installdaemon
1265 'remove')
1266 removedaemon
1269 'dump')
1270 checkUser "" $1
1271 dump
1274 'start_msg')
1275 # Internal command called by launchd on HP-UX.
1276 checkUser "" $1
1277 startmsg
1280 'stop_msg')
1281 # Internal command called by launchd on HP-UX.
1282 checkUser "" $1
1283 stopmsg
1286 'launchdinternal')
1287 # Internal command called by launchd on Max OSX.
1288 # We do not want to call checkUser here as it is handled in the launchd plist file. Doing it here would confuse launchd.
1289 launchdinternal
1293 echo "Usage: $0 { console | start | stop | restart | condrestart | status | install | remove | dump }"
1294 exit 1
1296 esac
1298 exit 0