Bug 535784 - (RHQ-2444) rhq-agent-wrapper.sh needs to be modified to work with SYSV init systems and chkconfig
rhq-agent-wrapper.sh needs to be modified to work with SYSV init systems and ...
Product: RHQ Project
Classification: Other
Component: Launch Scripts (Show other bugs)
All Linux
medium Severity medium (vote)
: ---
: ---
Assigned To: John Mazzitelli
: SubBug
: 615322 (view as bug list)
Depends On:
Blocks: rhq_triage
  Show dependency treegraph
Reported: 2009-09-30 15:06 EDT by Mark Burchard
Modified: 2014-04-15 17:18 EDT (History)
4 users (show)

See Also:
Fixed In Version: 2.4
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Reproduced on RHEL 5.3 and 5.4
Last Closed: 2010-08-12 12:50:49 EDT
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---

Attachments (Terms of Use)

  None (edit)
Description Mark Burchard 2009-09-30 15:06:00 EDT
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 16:46:35 EDT
Correction: line 104
Comment 2 John Mazzitelli 2009-10-12 08:34:10 EDT
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 13:39:08 EDT
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 16:04:34 EST
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 11:51:32 EST
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 11:57:50 EST
making sure we're not missing any bugs in rhq_triage
Comment 8 John Mazzitelli 2010-07-15 15:34:05 EDT
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 16:05:55 EDT
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 16:07:22 EDT
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 18:49:23 EDT
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 19:10:10 EDT
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 10:07:11 EDT
*** Bug 615322 has been marked as a duplicate of this bug. ***
Comment 14 John Mazzitelli 2010-07-16 12:23:42 EDT
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 12:50:49 EDT
Mass-closure of verified bugs against JON.

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