CollaboraOnline / richdocumentscode

Built-in CODE Server app
https://apps.nextcloud.com/apps/richdocumentscode
Apache License 2.0
119 stars 29 forks source link

Feature request: Define unpacking location of AppImage by setting TMPDIR environment variable #205

Open EdRoxter opened 2 years ago

EdRoxter commented 2 years ago

This might be somewhat of an edge case, but it'd be great if it was possible to define the path in which the AppImage extracts itself in case FUSE is unavailable.

Scenario: I'm running Nextcloud on a shared hosting provider's server which uses cPanel as management platform. By default, the AppImage extracts its contents into /tmp, which is mounted with noexec - apparently that's quite the default setup with cPanel. Obviously, the AppImage gets extracted, but the binaries inside can't be run which results in permission errors and of course the whole app not working.

On the other hand, binaries residing inside the "jail" of my hosting account (e.g. /home/myaccount/mybinarycollection/) can be run without any issues.

It is possible to achieve that by setting the environment variable TMPDIR in the context where the AppImage is executed. Problem is: In such a more or less restrictive environment, setting environment variables for the PHP processes as well as the exec()'d AppImage command is virtually impossible. I can't set environment variables for PHP in cPanel; I can't directly edit the php.ini; bash -c is non-login non-interactive, thus ignores .bashrc and .profile; /etc/environment is obviously read-only for me; etc.

So, as far as I'm concerned, the only way to reliably get this done is to set TMPDIR within proxy.php, either by putenv('TMPDIR=/home/myaccount/mybinarycollection')or by weaving it into $launchCmd. I successfully tried the putenv() method, but of course it breaks Nextcloud's code integrity check and will be overwritten with every update. Incorporating it into $launchCmd might be a safer call though, since putenv() might be disabled by hosting providers.

So my request would be to make the desired extraction path configurable in the app's admin backend and, if configured, have proxy.php set it as content of TMPDIR; of course given that you, dear developers, consider this an issue worth addressing.

ernolf commented 1 year ago

My /tmp directory is mounted with tmpfs, what makes it fast but limited in space. Because it is filled up from time to time by various scripts and tasks, which in extreme cases can make the server unresponsive, I created the following entries in php.ini for analysis purposes:

sys_temp_dir = "/tmp_php"
upload_tmp_dir = "/tmp_upload"
soap.wsdl_cache_dir="/tmp_wsdl"
opcache.lockfile_path="/tmp_opcache_lockfile"

and in /var/www/nextcloud/config/config.php:

'tempdirectory' => '/tmp_nc',

Of course all of these directories exist with 777 permissions.

I noticed the following: The app stores the coolwsd.pid in /tmp_upload, which is upload_tmp_dir as defined in php.ini which is incomprehensible to me. Look Here That would be better off in the (/var)/run directory, which is also mounted with tmpfs and is not persistent across reboots. Then all 'working' temp files are stored in /tmp. Neither the settings from php.ini nor from config/config.php are taken into account.

It would be great, when this app would at least take the 'tempdirectory' as defined in config/config.php and if possible move the pid file to (/var)/run

[Edit: added link to code]

EdRoxter commented 1 year ago

Thanks for your additions and conclusions!

Then all 'working' temp files are stored in /tmp. Neither the settings from php.ini nor from config/config.php are taken into account.

I guess that confirms that obviously only the setting of env variable TMPDIR is what influences the AppImage's behavior here.

It would be great, when this app would at least take the 'tempdirectory' as defined in config/config.php and if possible move the pid file to (/var)/run

That would be really neat indeed as it makes for consistent configuration of temp files' location overall.