Bug 535784 (RHQ-2444) - rhq-agent-wrapper.sh needs to be modified to work with SYSV init systems and chkconfig
Summary: rhq-agent-wrapper.sh needs to be modified to work with SYSV init systems and ...
Alias: RHQ-2444
Product: RHQ Project
Classification: Other
Component: Launch Scripts
Version: 1.2
Hardware: All
OS: Linux
medium vote
Target Milestone: ---
: ---
Assignee: John Mazzitelli
QA Contact:
URL: http://jira.rhq-project.org/browse/RH...
: 615322 (view as bug list)
Depends On:
Blocks: rhq_triage
TreeView+ depends on / blocked
Reported: 2009-09-30 19:06 UTC by Mark Burchard
Modified: 2018-10-27 16:14 UTC (History)
4 users (show)

Fixed In Version: 2.4
Doc Type: Bug Fix
Doc Text:
Clone Of:
Reproduced on RHEL 5.3 and 5.4
Last Closed: 2010-08-12 16:50:49 UTC

Attachments (Terms of Use)

System ID Priority Status Summary Last Updated
Red Hat Bugzilla 535012 None None None Never
Red Hat Bugzilla 1088032 None None None Never

Internal Links: 535012 1088032

Description Mark Burchard 2009-09-30 19:06:00 UTC
Line 102 of rhq-agent-wrapper.sh needs to be modified with after -e (Canonical, exists) after the readlink command, eg.

# -------------------------------
# Get the location of this script.
# Make sure we take into account the possibility $0
# is a symlink to the real agent installation script.

_DOLLARZERO=`readlink -e "$0" || echo "$0"`

This is because, at least under RHEL using chkconfig, the script called by init is a symlink to another symlink, the /etc/init.d/rhq-agent-wrapper -> /path/to/real/wrapper/file.  This causes the following to happen:

# ../rc3.d/S93rhq-agent-wrapper.sh start
++ readlink ../rc3.d/S93rhq-agent-wrapper.sh
+ _DOLLARZERO=../init.d/rhq-agent-wrapper.sh
++ dirname ../init.d/rhq-agent-wrapper.sh

Adding the -e option corrects this..

We also need to add some platform-check logic before this, as at least Solaris readlink does not support the -e option.


Comment 1 Mark Burchard 2009-09-30 20:46:35 UTC
Correction: line 104

Comment 2 John Mazzitelli 2009-10-12 12:34:10 UTC
RHQ-2461 reported the same thing, but says you can use -f option to correct the problem.

Does Solaris support the -f option?

Comment 3 Mark Burchard 2009-10-12 17:39:08 UTC
No the Solaris version of readlink does not appear to support any options at all.

However, in the case of Solaris 10, we should be providing an SMF  init script[1], which obsoletes the need for readlink.


Comment 4 Red Hat Bugzilla 2009-11-10 21:04:34 UTC
This bug was previously known as http://jira.rhq-project.org/browse/RHQ-2444
This bug is duplicated by RHQ-2461

Comment 5 wes hayutin 2010-02-16 16:51:32 UTC
Temporarily adding the keyword "SubBug" so we can be sure we have accounted for all the bugs.

new = Tracking + FutureFeature + SubBug

Comment 6 wes hayutin 2010-02-16 16:57:50 UTC
making sure we're not missing any bugs in rhq_triage

Comment 8 John Mazzitelli 2010-07-15 19:34:05 UTC
we should test which works : -f or -e (or both?)

we'll need to write this in such a way that it won't fail on solaris, since apparently neither switch is valid on solaris

Comment 9 John Mazzitelli 2010-07-15 20:05:55 UTC
readlink -e works on solaris 9 at least:

# uname -sr
SunOS 5.9
# ls -l /bin
lrwxrwxrwx   1 root     root           9 Mar 24  2009 /bin -> ./usr/bin
# readlink -f /bin

I think this should be an easy fix, assuming readlink's -f option is cross-platform across all unix flavors

Comment 10 John Mazzitelli 2010-07-15 20:07:22 UTC
The -e option is also available on solaris, which is probably the one we'd want to use:

# uname -sr
SunOS 5.9
# ls -l /bin
lrwxrwxrwx   1 root     root           9 Mar 24  2009 /bin -> ./usr/bin
# readlink -e /bin

Comment 11 John Mazzitelli 2010-07-15 22:49:23 UTC
the basic change will be made to rhq-agent.sh, rhq-agent-wrapper.sh and rhq-server.sh... it goes something like this:

   if [ "x${_LINUX}${_SOLARIS}${_CYGWIN}" != "x" ]; then
      # only certain platforms support the -e argument for readlink

   _DOLLARZERO=`readlink $_READLINK_ARG "$0" 2>/dev/null || echo "$0"`

Note that we'll know what platform we are on via this switch:

case "`uname`" in
   CYGWIN*) _CYGWIN=true
   Linux*)  _LINUX=true
   Darwin*) _DARWIN=true
   SunOS*) _SOLARIS=true
   AIX*)   _AIX=true

MacOS doesn't support the -e flag. Unknown if AIX does, so I leave that alone for now. The main issue is on Fedora/RHEL anyway. We can add ${_AIX} to that if-stmt if we know AIX's version of readlink supports -e

Comment 12 John Mazzitelli 2010-07-15 23:10:10 UTC
release-3.0.0 branch commit: 58c0104617caf09db42c7802e55d6df3fb420f81

To test:

1a) install an agent (I'll assume it is at /tmp/rhq-agent)
1b) install a server (I'll assume it is at /tmp/rhq-server)
2) Create two test directories: /tmp/test and a /tmp/test/subdir
3) Create a symlink to the agent and server scripts:
   ln -s /tmp/rhq-agent/bin/rhq-agent.sh /tmp/test/link.sh
   ln -s /tmp/rhq-agent/bin/rhq-agent-wrapper.sh /tmp/test/link-wrapper.sh
   ln -s /tmp/rhq-server/bin/rhq-server.sh /tmp/test/server-link.sh
4) Now create links to the links in that test subdir:
   ln -s /tmp/test/link.sh /tmp/test/subdir/another-link.sh
   ln -s /tmp/test/link-wrapper.sh /tmp/test/subdir/another-link-wrapper.sh
   ln -s /tmp/test/server-link.sh /tmp/test/subdir/another-server-link.sh
5) Turn on agent and server debug env vars so you can see the scripts' log messages on console:
   export RHQ_AGENT_DEBUG=true
   export RHQ_SERVER_DEBUG=true
6) Now run the links to the links (you don't need to run both agent and server together, we are just confirming the scripts themselves work and can determine the home directories OK - if they start the server and the agent fine its good - look at the debug logs on the console to confirm that RHQ_AGENT_HOME and RHQ_SERVER_HOME is set properly):
   /tmp/test/subdir/another-link-wrapper.sh start

Comment 13 dsteigne 2010-07-16 14:07:11 UTC
*** Bug 615322 has been marked as a duplicate of this bug. ***

Comment 14 John Mazzitelli 2010-07-16 16:23:42 UTC
I tested this on Fedora11. I also confirmed this readlink argument fix works on Solaris 9.

This fix is also applicable on Windows/Cygwin, though I didn't test that.

This fix is not applicable on AIX or MacOS (AIX because I didnt know if readlink has -e on that platform, and MacOS because it doesn't look it -e is supported there). Therefore, this problem will probably still exist on AIX or MacOS - in those cases, just don't have symlink-to-symlink-to-script. This problem is showing up on RHEL/Fedora because of the way chkconfig creates symlink-to-symlink in rc3.d->init.d

Comment 15 Corey Welton 2010-08-12 16:50:49 UTC
Mass-closure of verified bugs against JON.

Note You need to log in before you can comment on or make changes to this bug.