Bug 831808 - Agent update fails when installed as non-root user; attempts to download into agent home's parent directory
Summary: Agent update fails when installed as non-root user; attempts to download into...
Keywords:
Status: CLOSED NOTABUG
Alias: None
Product: RHQ Project
Classification: Other
Component: Agent
Version: 4.1
Hardware: Unspecified
OS: Unspecified
high
high
Target Milestone: ---
: RHQ 4.5.0
Assignee: RHQ Project Maintainer
QA Contact: Mike Foley
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2012-06-13 19:32 UTC by Elias Ross
Modified: 2012-06-20 18:37 UTC (History)
2 users (show)

Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Clone Of:
Environment:
Last Closed: 2012-06-20 18:37:19 UTC
Embargoed:


Attachments (Terms of Use)

Description Elias Ross 2012-06-13 19:32:33 UTC
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 14:52:55 UTC
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 18:37:19 UTC
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.