Per new behaviour for rhq-agent, config for running agent as a service includes symlinking to the actual location of the rhq-agent-wrapper.sh script. Agent fails to launch, however, after doing this. Steps to repro. 1. `ln -s /root/rhq-agent/bin/rhq-agent-wrapper.sh /etc/init.d/rhq-agent-wrapper.sh` 2. `service rhq-agent-wrapper.sh` 3. optional: enable debug (add export RHQ_AGENT_DEBUG=true to top of rhq-agent-wrapper.sh) 4. View results Current result. [root@rlx-0-12 ]# service rhq-agent-wrapper.sh start Starting RHQ Agent... ERROR! Cannot find the RHQ Agent start script Not found: /etc/bin/rhq-agent.sh If debug enabled: [root@rlx-0-12 ]# service rhq-agent-wrapper.sh start rhq-agent-wrapper.sh: RHQ_AGENT_WRAPPER_BIN_DIR_PATH=/etc/init.d rhq-agent-wrapper.sh: pidfile will be located at /etc/bin/rhq-agent.pid ERROR! Cannot find the RHQ Agent start script Not found: /etc/bin/rhq-agent.sh Expected result: Agent launches.
the problem is this line in rhq-agent-wrapper.sh: RHQ_AGENT_WRAPPER_BIN_DIR_PATH=`dirname "$0"` $0 is the value of the sym link, not the real script itself. Will need to use "readlink" here - need to example $0 and if its a symlink, use "readlink" to get the "real" file that the link points to.
Now using the following to follow symlinks - if the script isn't a symlink, it still works: _DOLLARZERO=`readlink "$0" || echo "$0"` So, we can now use "$_DOLLARZERO" for the "real" script path, e.g.: RHQ_AGENT_WRAPPER_BIN_DIR_PATH=`dirname "$_DOLLARZERO"`
How many flavors of *nix has this been tested on ?
This will work on all UNIX's that have "readlink" available and in the path, which from what it looks like is all the ones we care about (I see this working on solaris, rhel and fedora - unsure if readlink is available on aix, hpux, macos - but workaround is simple - provide readlink access to the user running the agent :)
QA Verified.
This bug was previously known as http://jira.rhq-project.org/browse/RHQ-1391 This bug relates to RHQ-1752