4 # Copyright (c) 1999, 2010 Tanuki Software, Ltd.
5 # http://www.tanukisoftware.com
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.
25 APP_LONG_NAME
="Hudson Continuous build server"
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.
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
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
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.
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
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.
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.
82 # Provides: @app.name@
83 # Required-Start: $local_fs $network $syslog
86 # Default-Start: 2 3 4 5
88 # Short-Description: @app.long.name@
89 # Description: @app.description@
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
100 # Get the fully qualified path to the script
111 # Resolve the true real path without any sym links.
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'`
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
133 REALPATH
="`dirname "$REALPATH"`""/$LINK"
138 if [ "$REALPATH" = "$SCRIPT" ]
146 # Change the current directory to the location of the script
147 cd "`dirname "$REALPATH"`"
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" != "/" ]
155 PIDDIR
=$REALDIR/$PIDDIR
157 # Same test for WRAPPER_CMD
158 FIRST_CHAR
=`echo $WRAPPER_CMD | cut -c1,1`
159 if [ "$FIRST_CHAR" != "/" ]
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" != "/" ]
167 WRAPPER_CONF
=$REALDIR/$WRAPPER_CONF
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"
179 # Resolve the location of the 'ps' command
189 echo "Unable to locate 'ps'."
190 echo "Please report this message along with the location of the command on your system."
197 DIST_OS
=`uname -s | tr [A-Z] [a-z] | tr -d ' '`
203 # HP-UX needs the XPG4 version of ps (for -o args)
219 # Resolve the architecture
220 if [ "$DIST_OS" = "macosx" ]
222 DIST_ARCH
="universal"
223 APP_PLIST_BASE
=${PLIST_DOMAIN}.
${APP_NAME}
224 APP_PLIST
=${APP_PLIST_BASE}.plist
227 DIST_ARCH
=`uname -p 2>/dev/null | tr [A-Z] [a-z] | tr -d ' '`
228 if [ "X$DIST_ARCH" = "X" ]
232 if [ "$DIST_ARCH" = "unknown" ]
234 DIST_ARCH
=`uname -m 2>/dev/null | tr [A-Z] [a-z] | tr -d ' '`
237 'athlon' |
'i386' |
'i486' |
'i586' |
'i686')
239 if [ "${DIST_OS}" = "solaris" ] ; then
240 DIST_BITS
=`isainfo -b`
253 'ia64' |
'ia64n' |
'ia64w')
261 'power' |
'powerpc' |
'power_pc' |
'ppc64')
262 if [ "${DIST_ARCH}" = "ppc64" ] ; then
268 if [ "${DIST_OS}" = "aix" ] ; then
269 if [ `getconf KERNEL_BITMODE` -eq 64 ]; then
276 'pa_risc' |
'pa-risc')
278 if [ `getconf KERNEL_BITS` -eq 64 ]; then
284 'sun4u' |
'sparcv9' |
'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
/sparcv
9/libm.so
.2 -a "${DIST_BITS}" = "64" ]; then
290 ln -s /usr
/lib
/sparcv
9/libm.so
.1 /usr
/lib
/sparcv
9/libm.so
.2
293 '9000/800' |
'9000/785')
295 if [ `getconf KERNEL_BITS` -eq 64 ]; then
308 # OSX always places Java in the same location so we can reliably set JAVA_HOME
309 if [ "$DIST_OS" = "macosx" ]
311 if [ -z "$JAVA_HOME" ]; then
312 JAVA_HOME
="/Library/Java/Home"; export JAVA_HOME
317 ECHOTEST
=`echo -n "x"`
318 if [ "$ECHOTEST" = "x" ]
328 echo " $1 (Found but not executable.)";
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" ]
342 WRAPPER_CMD
="$WRAPPER_TEST_CMD"
344 WRAPPER_TEST_CMD
="$WRAPPER_CMD-$DIST_OS-$DIST_ARCH-32"
345 if [ -x "$WRAPPER_TEST_CMD" ]
347 WRAPPER_CMD
="$WRAPPER_TEST_CMD"
349 if [ ! -x "$WRAPPER_CMD" ]
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" ]
355 outputFile
"$WRAPPER_CMD-$DIST_OS-$DIST_ARCH-32"
357 outputFile
"$WRAPPER_CMD"
363 # Build the nice clause
364 if [ "X$PRIORITY" = "X" ]
368 CMDNICE
="nice -$PRIORITY"
371 # Build the anchor file clause.
372 if [ "X$IGNORE_SIGNALS" = "X" ]
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" ]
386 STATUSPROP
="wrapper.statusfile=\"$STATUSFILE\" wrapper.java.statusfile=\"$JAVASTATUSFILE\""
389 if [ ! -n "$WAIT_FOR_STARTED_STATUS" ]
391 WAIT_FOR_STARTED_STATUS
=true
394 if [ $WAIT_FOR_STARTED_STATUS = true
] ; then
399 # Build the lock file clause. Only create a lock file if the lock directory exists on this platform.
405 LOCKPROP
=wrapper.lockfile
=\"$LOCKFILE\"
413 # Check the configured user. If necessary rerun this script as the desired user.
414 if [ "X$RUN_AS_USER" != "X" ]
416 # Resolve the location of the 'id' command
417 IDEXE
="/usr/xpg4/bin/id"
423 echo "Unable to locate 'id'."
424 echo "Please report this message along with the location of the command on your system."
429 if [ "`$IDEXE -u -n`" = "$RUN_AS_USER" ]
431 # Already running as the configured user. Avoid password prompts by not calling su.
435 if [ "X$RUN_AS_USER" != "X" ]
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" ]
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" ]
449 RUN_AS_GROUP
=$RUN_AS_USER
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"
463 /sbin
/runuser
- $RUN_AS_USER -c "\"$REALPATH\" $2"
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" ]
474 # Wrapper is not running so make sure the lock file is deleted.
475 if [ -f "$LOCKFILE" ]
493 if [ "X$pid" != "X" ]
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.
502 pidtest
=`$PSEXE -p $pid -o args | tail -1`
503 if [ "X$pidtest" = "XCOMMAND" ]
509 pidtest
=`$PSEXE -ww -p $pid -o command | grep "$WRAPPER_CMD" | tail -1`
512 if [ -f "/usr/bin/pargs" ]
514 pidtest
=`pargs $pid | grep "$WRAPPER_CMD" | tail -1`
518 pidtest
=`$PSEXE -auxww $pid | grep "$WRAPPER_CMD" | tail -1`
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`
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"
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`
551 if [ "X$pidtest" = "X" ]
553 # This is a stale pid file.
555 echo "Removed stale pid file: $PIDFILE"
560 echo "Cannot read $PIDFILE."
568 if [ -f "$STATUSFILE" ]
570 if [ -r "$STATUSFILE" ]
572 STATUS
=`cat "$STATUSFILE"`
575 if [ "X$STATUS" = "X" ]
581 if [ -f "$JAVASTATUSFILE" ]
583 if [ -r "$JAVASTATUSFILE" ]
585 JAVASTATUS
=`cat "$JAVASTATUSFILE"`
588 if [ "X$JAVASTATUS" = "X" ]
599 pid
=`$PSEXE $pid | grep $pid | grep -v grep | awk '{print $1}' | tail -1`
602 pid
=`$PSEXE -p $pid | grep $pid | grep -v grep | awk '{print $1}' | tail -1`
605 pid
=`$PSEXE -p $pid | grep $pid | grep -v grep | awk '{print $1}' | tail -1`
608 echo "Unsupported ps command $PSEXE"
614 pid
=`$PSEXE -p $pid | grep $pid | grep -v grep | awk '{print $1}' | tail -1` 2>/dev
/null
619 # Process is gone so remove the pid file.
630 waitforwrapperstop
() {
632 while [ "X$pid" != "X" ] ; do
640 trap launchdtrap TERM
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"
647 echo "$APP_LONG_NAME is already running."
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
]
658 echo "Running $APP_LONG_NAME..."
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"
667 echo "$APP_LONG_NAME is already running."
672 waitforjavastartup
() {
674 echo $ECHOOPT"Waiting for $APP_LONG_NAME..."
676 # Wait until the timeout or we have something besides Unknown.
678 while [ "$JAVASTATUS" = "Unknown" -a $counter -gt 0 -a -n "$JAVASTATUS" ] ; do
682 counter
=`expr $counter - 1`
685 if [ -n "$WAIT_FOR_STARTED_TIMEOUT" ] ; then
686 counter
=$WAIT_FOR_STARTED_TIMEOUT
690 while [ "$JAVASTATUS" != "STARTED" -a "$JAVASTATUS" != "Unknown" -a $counter -gt 0 -a -n "$JAVASTATUS" ] ; do
694 counter
=`expr $counter - 1`
696 if [ "X$ECHOOPT" != "X" ] ; then
699 echo "$APP_LONG_NAME started."
703 if [ $WAIT_FOR_STARTED_STATUS = true
]
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 ]
717 if [ $WAIT_AFTER_STARTUP -gt 0 ]
722 echo " WARNING: $APP_LONG_NAME may have failed to start."
725 echo " running ($pid)."
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."
741 if [ "X$pid" != "X" ] ; then
742 echo "$APP_LONG_NAME is already running."
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
753 if [ "X$pid" == "X" ] ; then
754 launchctl start
${APP_PLIST_BASE}
761 echo $ECHOOPT"Starting $APP_LONG_NAME..."
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"
769 echo "$APP_LONG_NAME is already running."
777 # $1 exit if down flag
779 echo "Stopping $APP_LONG_NAME..."
783 echo "$APP_LONG_NAME was not running."
789 if [ "X$IGNORE_SIGNALS" = "X" ]
791 # Running so try to stop it.
795 # An explanation for the failure should have been given
796 echo "Unable to stop $APP_LONG_NAME."
801 if [ -f "$ANCHORFILE" ]
803 # An explanation for the failure should have been given
804 echo "Unable to stop $APP_LONG_NAME."
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.
815 while [ "X$pid" != "X" ]
817 # Show a waiting message every 5 seconds.
818 if [ "$CNT" -lt "5" ]
822 echo "Waiting for $APP_LONG_NAME to exit..."
825 TOTCNT
=`expr $TOTCNT + 1`
834 if [ "X$pid" != "X" ]
836 echo "Failed to stop $APP_LONG_NAME."
839 echo "Stopped $APP_LONG_NAME."
848 echo "$APP_LONG_NAME is not running."
851 if [ "X$DETAIL_STATUS" = "X" ]
853 echo "$APP_LONG_NAME is running (PID:$pid)."
856 echo "$APP_LONG_NAME is running (PID:$pid, Wrapper:$STATUS, Java:$JAVASTATUS)"
863 if [ `id | sed 's/^uid=//;s/(.*$//'` != "0" ] ; then
864 echo "Must be root to perform this action."
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."
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."
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."
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."
906 echo " Installing the $APP_LONG_NAME daemon.."
907 ln -s $REALPATH /etc
/init.d
/$APP_NAME
908 update-rc.d
$APP_NAME defaults
911 echo "Detected Linux:"
912 if [ -f /etc
/init.d
/$APP_NAME ] ; then
913 echo " The $APP_LONG_NAME daemon is already installed."
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."
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
937 if [ -f /etc
/rc.d
/init.d
/$APP_NAME ] ; then
938 echo " The $APP_LONG_NAME daemon is already installed."
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."
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
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."
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}
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.
"
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
1032 echo "Install not currently supported for $DIST_OS"
1039 if [ `id | sed 's
/^uid
=//;s
/(.
*$
//'` != "0" ] ; then
1040 echo "Must be root to perform this action."
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
1053 echo " The $APP_LONG_NAME daemon is not currently installed."
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
1065 echo " The $APP_LONG_NAME daemon is not currently installed."
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
1075 echo " The $APP_LONG_NAME daemon is not currently installed."
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
1085 echo " The $APP_LONG_NAME daemon is not currently installed."
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
1097 echo " The $APP_LONG_NAME daemon is not currently installed."
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
1110 echo " The $APP_LONG_NAME daemon is not currently installed."
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
1122 echo " The $APP_LONG_NAME daemon is not currently installed."
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
1133 sed -i .bak "/${APP_NAME}_enable=\"YES\"/d" /etc/rc.conf
1135 echo " The $APP_LONG_NAME daemon is not currently installed."
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}
1149 echo " The $APP_LONG_NAME daemon is not currently installed."
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
1160 echo " The $APP_LONG_NAME daemon is not currently installed."
1164 echo "Remove not currently supported for $DIST_OS"
1171 echo "Dumping $APP_LONG_NAME..."
1173 if [ "X$pid" = "X" ]
1175 echo "$APP_LONG_NAME was not running."
1181 echo "Failed to dump $APP_LONG_NAME."
1184 echo "Dumped $APP_LONG_NAME."
1189 # Used by HP-UX init scripts.
1192 if [ "X$pid" = "X" ]
1194 echo "Starting $APP_LONG_NAME... (Wrapper:Stopped)"
1196 if [ "X$DETAIL_STATUS" = "X" ]
1198 echo "Starting $APP_LONG_NAME... (Wrapper:Running)"
1201 echo "Starting $APP_LONG_NAME... (Wrapper:$STATUS, Java:$JAVASTATUS)"
1206 # Used by HP-UX init scripts.
1209 if [ "X$pid" = "X" ]
1211 echo "Stopping $APP_LONG_NAME... (Wrapper:Stopped)"
1213 if [ "X$DETAIL_STATUS" = "X" ]
1215 echo "Stopping $APP_LONG_NAME... (Wrapper:Running)"
1218 echo "Stopping $APP_LONG_NAME... (Wrapper:$STATUS, Java:$JAVASTATUS)"
1226 checkUser touchlock $1
1231 if [ "$DIST_OS" = "macosx" -a -f "/Library/LaunchDaemons/${APP_PLIST}" ] ; then
1234 checkUser touchlock $1
1245 checkUser touchlock $1
1251 checkUser touchlock $1
1275 # Internal command called by launchd on HP-UX.
1281 # Internal command called by launchd on HP-UX.
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.
1293 echo "Usage: $0 { console | start | stop | restart | condrestart | status | install | remove | dump }"