11

My users are all on NFS home directories and with hundreds of users all using Firefox it generates a bit of traffic reading/writing to the disk cache. As a result, I'd like to move the default Firefox disk cache over to a local file system just to reduce extraneous NFS traffic and lighten the load on my NFS server too.

I know I can set system wide default preferences in a file called my_firefox_path/defaults/pref/all.js of the following form:

pref("browser.cache.disk.parent_directory", string)

For testing I had it set to the following:

pref("browser.cache.disk.parent_directory", "/tmp/firefox/");

Unfortunately that doesn't work well as there are multiple users on each system. Is there a way to include a user and a profile in that preference file so that I can tweak this system wide and it will apply to all my users? Something like:

pref("browser.cache.disk.parent_directory", "/tmp/firefox/$USER/$PROFILE");

Patrick Mevzek
  • 9,273
  • 7
  • 29
  • 42
Andrew Case
  • 3,409
  • 3
  • 21
  • 38
  • You may be able to use getenv() to retrieve environment variables. For instance: getenv("USER") for the username; not sure how you could get the profile path though. Extensions can easily retrieve the profile path, but I expect that making the extension API available outside of an extension would be a challenge. – cyberx86 Aug 17 '11 at 08:18
  • Not able to use getenv() or grab the profile path by running this in the .js file: Components.classes["@mozilla.org/file/directory_service;1"].getService( Components.interfaces.nsIProperties).get("ProfD", Components.interfaces.nsIFile).path – Andrew Case Aug 18 '11 at 03:01
  • Depending on the relation with your users, why not make the change (or ask them to make the change) once in their profile and be done with it? Since, even if you find a way to specify, they can override it. – Patrick Mevzek Nov 17 '17 at 23:17
  • 1
    It is unlikely that you can do that directly in that file, according to [this](https://developer.mozilla.org/en-US/docs/Archive/Add-ons/Default_Preferences). Have you tried making it a symlink? it=the nfs folder. – Florin Asăvoaie Jan 10 '18 at 00:28

2 Answers2

0

The only way I see doing this is to programmatically update the user.js preferences file on each user's login.

When a user logs in, a script runs that does the following:

  1. reads their ~/mozilla/firefox/profiles.ini.
  2. Parses out the directory for the profiles.
  3. Creates a temp directory and a variable for a directory path like /tmp/$(id -u)/firefox/${profile.dirname}/cache
  4. Creates/updates ~/mozilla/firefox/${profile.dirname}/user.js file with pref("browser.cache.disk.parent_directory", "${TEMP_DIRECTORY_PATH");
hydrian
  • 47
  • 5
-1

You can try to create a symlink for old cache folder to the new place. The command will be like:

ln -s /tmp/firefox /path_to_cache_folder_on_share
  • This doesn't solve the problem, since that would still be just one cache directory for all users. – Andrew Schulman Jan 31 '18 at 12:50
  • 1
    this solves half the problem though, @AndrewSchulman, if there was a login script to create `/tmp/$USER/firefox` for each user then make the link, then the shared profile could use the link path. e.g. `mkdir -p /tmp/$USER/firefox; ln -s /tmp/$USER/firefox /path_to_cache_folder_on_share` – mike Jul 22 '18 at 11:50