Making Froxlor NFS mount safe

0 Comments

As you all know I love Froxlor. Unfortunately I have problems dealing with developers at times. The Froxlor developers would seem to be no exception. Therefore, I am constantly generating patches for Froxlor but rarely submit a request.

This is another such situation. As many of you may remember, I run Froxlor in a 6 layer HA cluster stack with the HA cluster containing Froxlor in the 2nd layer in from the edge. All content and configs for Froxlor are stored on a GlusterFS HA cluster mounted using NFS.

Works great but when the Froxlor cronjob runs you get the following.

root@nvwh2a:/var/www/froxlor/lib/functions/filedir# /usr/bin/php5 -q /var/www/froxlor/scripts/froxlor_master_cronjob.php --force
chattr: Inappropriate ioctl for device while reading flags on /var/www/php-fcgi-scripts/bdmadmin/lesershop.kn-online.de.mol-servers.de/php-fcgi-starter
chattr: Inappropriate ioctl for device while reading flags on /var/www/php-fcgi-scripts/bdmadmin/ln-online.de/php-fcgi-starter
chattr: Inappropriate ioctl for device while reading flags on /var/www/php-fcgi-scripts/bdmadmin/dnn-online.de/php-fcgi-starter
chattr: Inappropriate ioctl for device while reading flags on /var/www/php-fcgi-scripts/bdmadmin/owastats.bluedotmedia.de/php-fcgi-starter
chattr: Inappropriate ioctl for device while reading flags on /var/www/php-fcgi-scripts/bdmadmin/maz-online.de/php-fcgi-starter
chattr: Inappropriate ioctl for device while reading flags on /var/www/php-fcgi-scripts/bdmadmin/partnershop.niedersachsen.com/php-fcgi-starter
chattr: Inappropriate ioctl for device while reading flags on /var/www/php-fcgi-scripts/bdmadmin/mol-servers.de/php-fcgi-starter
chattr: Inappropriate ioctl for device while reading flags on /var/www/php-fcgi-scripts/bdmadmin/mmashops.bluedotmedia.de/php-fcgi-starter
chattr: Inappropriate ioctl for device while reading flags on /var/www/php-fcgi-scripts/bdmadmin/maghost1.mol-servers.de/php-fcgi-starter
chattr: Inappropriate ioctl for device while reading flags on /var/www/php-fcgi-scripts/bdmadmin/shop.philapress.de/php-fcgi-starter
chattr: Inappropriate ioctl for device while reading flags on /var/www/php-fcgi-scripts/bdmadmin/goettinger-tageblatt.de/php-fcgi-starter
chattr: Inappropriate ioctl for device while reading flags on /var/www/php-fcgi-scripts/bdmadmin/paz-online.de/php-fcgi-starter
chattr: Inappropriate ioctl for device while reading flags on /var/www/php-fcgi-scripts/bdmadmin/haz.de/php-fcgi-starter
chattr: Inappropriate ioctl for device while reading flags on /var/www/php-fcgi-scripts/bdmadmin/bluedotmedia.de/php-fcgi-starter
chattr: Inappropriate ioctl for device while reading flags on /var/www/php-fcgi-scripts/bdmadmin/wlz-fz.de/php-fcgi-starter

This is due to the fact that chattr will not work on an NFS mount and Froxlor does not check what type of mount it is working on. Now make no mistake, this is by no means an error on the part of the Froxlor team. Most are not experienced in such setups and therefore cannot be expected to take such issues into account.

The source of the problem is found in /var/www/froxlor/lib/functions/filedir/function.fileImmutable.php which contains the following

< ?php /** * This file is part of the Froxlor project. * Copyright (c) 2010 the Froxlor Team (see authors). * * For the full copyright and license information, please view the COPYING * file that was distributed with this source code. You can also view the * COPYING file online at http://files.froxlor.org/misc/COPYING.txt * * @copyright (c) the authors * @author Froxlor team (2010-)
* @license GPLv2 http://files.froxlor.org/misc/COPYING.txt
* @package Functions
*
*/

/**
* set the immutable flag for a file
*
* @param string $filename the file to set the flag for
*
* @return boolean
*/

function setImmutable($filename = null) {
safe_exec(_getImmutableFunction(false).escapeshellarg($filename));
}

/**
* removes the immutable flag for a file
*
* @param string $filename the file to set the flag for
*
* @return boolean
*/
function removeImmutable($filename = null) {
safe_exec(_getImmutableFunction(true).escapeshellarg($filename));
}

/**
* internal function to check whether
* to use chattr (Linux) or chflags (FreeBSD)
*
* @param boolean $remove whether to use +i|schg (false) or -i|noschg (true)
*
* @return string functionname + parameter (not the file)
*/
function _getImmutableFunction($remove = false) {

if (isFreeBSD()) {
// FreeBSD style
return 'chflags '.(($remove === true) ? 'noschg ' : 'schg ');
} else {
// Linux style
return 'chattr '.(($remove === true) ? '-i ' : '+i ');
}
}

Adding a call to “stat” and checking the mount type will enable us to forgo the chattr call on NFS mounted files. I did a quick change to this particular install of Froxlor to add this ability.

< ?php /** * This file is part of the Froxlor project. * Copyright (c) 2010 the Froxlor Team (see authors). * * For the full copyright and license information, please view the COPYING * file that was distributed with this source code. You can also view the * COPYING file online at http://files.froxlor.org/misc/COPYING.txt * * @copyright (c) the authors * @author Froxlor team (2010-)
* @license GPLv2 http://files.froxlor.org/misc/COPYING.txt
* @package Functions
*
*/

/**
* set the immutable flag for a file
*
* @param string $filename the file to set the flag for
*
* @return boolean
*/

function setImmutable($filename = null) {
$fstype = safe_exec('/usr/bin/stat --file-system --format=%T '.$filename);
if($fstype[0] !== "nfs")

safe_exec(_getImmutableFunction(false).escapeshellarg($filename));
}

/**
* removes the immutable flag for a file
*
* @param string $filename the file to set the flag for
*
* @return boolean
*/
function removeImmutable($filename = null) {
$fstype = safe_exec('/usr/bin/stat --file-system --format=%T '.$filename);
if($fstype[0] !== "nfs")

safe_exec(_getImmutableFunction(true).escapeshellarg($filename));
}

/**
* internal function to check whether
* to use chattr (Linux) or chflags (FreeBSD)
*
* @param boolean $remove whether to use +i|schg (false) or -i|noschg (true)
*
* @return string functionname + parameter (not the file)
*/
function _getImmutableFunction($remove = false) {

if (isFreeBSD()) {
// FreeBSD style
return 'chflags '.(($remove === true) ? 'noschg ' : 'schg ');
} else {
// Linux style
return 'chattr '.(($remove === true) ? '-i ' : '+i ');
}
}

Enjoy

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.