Bug 831808 - Agent update fails when installed as non-root user; attempts to download into agent home's parent directory
Agent update fails when installed as non-root user; attempts to download into...
Status: CLOSED NOTABUG
Product: RHQ Project
Classification: Other
Component: Agent (Show other bugs)
4.1
Unspecified Unspecified
high Severity high (vote)
: ---
: RHQ 4.5.0
Assigned To: RHQ Project Maintainer
Mike Foley
:
Depends On:
Blocks:
  Show dependency treegraph
 
Reported: 2012-06-13 15:32 EDT by Elias Ross
Modified: 2012-06-20 14:37 EDT (History)
2 users (show)

See Also:
Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Environment:
Last Closed: 2012-06-20 14:37:19 EDT
Type: Bug
Regression: ---
Mount Type: ---
Documentation: ---
CRM:
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---


Attachments (Terms of Use)

  None (edit)
Description Elias Ross 2012-06-13 15:32:33 EDT
Description of problem:

When Agent is being upgraded automatically, the installer attempts to install the agent to the parent of the agent home directory. If the Agent is run as a non-root user, this fails.

If for example, RHQ_AGENT_HOME is /usr/local/rhq-agent, then it will attempt to download to /usr/local. This directory is typically owned by root and it will fail.


Version-Release number of selected component (if applicable):

4.1 update to 4.4


How reproducible:

Always

Steps to Reproduce:
1. Install 4.1 agent and server, running as 'rhq' user.
2. Update server to 4.4, attempt to update agent.
  

Additional info:

Agent should download to java.io.tmpdir instead, since this is always available to any user. I don't see any potential downside to this.


Suggested fix:

diff --git a/modules/enterprise/agent/src/main/java/org/rhq/enterprise/agent/AgentUpdateDownload.java b/modules/enterprise/agent/src/main/java/org/rhq/enterprise/agent/AgentUpdateDownload.java
index 9edad7f..709875e 100644
--- a/modules/enterprise/agent/src/main/java/org/rhq/enterprise/agent/AgentUpdateDownload.java
+++ b/modules/enterprise/agent/src/main/java/org/rhq/enterprise/agent/AgentUpdateDownload.java
@@ -83,18 +83,7 @@ public class AgentUpdateDownload {
      * @return local file system location where the downloaded files are stored
      */
     public File getLocalDownloadDirectory() {
-        String agentHome = this.agent.getAgentHomeDirectory();
-        File dir = null;
-
-        if (agentHome != null && agentHome.length() > 0) {
-            dir = (new File(agentHome)).getParentFile();
-        }
-
-        if (dir == null) {
-            dir = new File(System.getProperty("java.io.tmpdir"));
-        }
-
-        return dir;
+        return new File(System.getProperty("java.io.tmpdir"));
     }
 
     /**
Comment 1 John Mazzitelli 2012-06-20 10:52:55 EDT
Note that this has been a requirement that is already documented in the Installation documentation:

https://docs.jboss.org/author/display/RHQ/RHQ+Agent+Installation#RHQAgentInstallation-InstallTheAgentInAWritableDirectory

"Install The Agent In A Writable Directory

During the update process, files will need to be written in the directory where the agent is currently installed. This means that the parent directory of the agent's install directory must be writable by the user that is running the agent. As an example, if the agent's $RHQ_AGENT_HOME (i.e. where the agent is installed) is the directory called "/opt/rhq-agent-parent/rhq-agent", the agent will need to write files to the "/opt/rhq-agent-parent" directory and therefore must have write permissions there."

I haven't looked at the side effects of the proposed patch, but the issue that requires this writable parent dir (IIRC) was that the ant script that runs the agent update expects the binary jar to be in the parent location of the agent installation home directory.
Comment 2 Elias Ross 2012-06-20 14:37:19 EDT
Sorry I didn't carefully read the documentation. I migrated several instances from running the agent as root to rhq and failed to consider this. The patch is also incomplete as you note as the ant script will fail to run.

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