MRatWork Forum by Mustafa Ramadhan

Sawo Project - Kloxo-MR Discussions => Kloxo-MR Technical Helps => Topic started by: Spacedust on 2013-04-22, 17:32:49

Title: Bug in linuxfslib.php causing disk usage not to be counted
Post by: Spacedust on 2013-04-22, 17:32:49
Mustafa you made a huge mistake in this file. Leaving disk usage count to work only on linux installations using english language only.
Title: Re: Bug in linuxfslib.php causing disk usage not to be count
Post by: Spacedust on 2013-04-22, 17:34:39
You disabled this:

Code: [Select]
$rt = lxshell_output("du", "-sc", $path);
$os  = preg_replace("/s+/", ":", $rt);
$ret = explode(":", $os);
$t = $ret[2];

and replaced this with non-working code if Linux installation is installed in different language than English !

Code: [Select]
exec("du -sc {$path} | grep -i 'total'", $out);
$os  = preg_replace("/s+/", ":", $out[0]);
$t = str_replace(":total", "", $os);

Take a look:

Code: [Select]
[root@nowosci /]# du -sc /home/admin
100544  /home/admin
100544  razem

So there is no word total !

Code: [Select]
[root@nowosci /]# du -sc /home/admin | grep total
[root@nowosci /]#

That's why Kloxo isn't counting quota properly on so many systems, because we use polish on all of them !
Title: Re: Bug in linuxfslib.php causing disk usage not to be count
Post by: Spacedust on 2013-04-22, 17:40:40
It will be very easy to switch to quotas now - see example:

Quote
quota -u monia_mal
Disk quotas for user monia_mal (uid 2117):
 System plików   bloki mi?kki  twardy  pob?.   pliki mi?kki  twardy  pob?.
      /dev/root      28  52428800 52428800              79       0       0
       /dev/md2 33699544  52428800 52428800          312604       0       0

We should just use du -sc for mail and databases and use quota for /home.

This will give us realtime disk usage at least for /home.
Title: Re: Bug in linuxfslib.php causing disk usage not to be count
Post by: MRatWork on 2013-04-22, 19:12:57
Look like need modified as:
Code: [Select]
  exec("du -sc {$path} | grep -i '{$path}'", $out);
   $os  = preg_replace("/s+/", ":", $out[0]);
   $t = str_replace(":total", "", $os);
Title: Re: Bug in linuxfslib.php causing disk usage not to be count
Post by: Spacedust on 2013-04-22, 19:23:37
Quote from: "MRatWork"
Look like need modified as:
Code: [Select]
  exec("du -sc {$path} | grep -i '{$path}'", $out);
   $os  = preg_replace("/s+/", ":", $out[0]);
   $t = str_replace(":total", "", $os);

Yes it works ok on polish linux. But this is only a temporary solution which takes almost 4 hours to count on our filesystem and causing very high I/O load. We must use quota -u as soon as possible.
Title: Re: Bug in linuxfslib.php causing disk usage not to be count
Post by: MRatWork on 2013-04-22, 19:36:19
Using 'quota -u' not work in my servers
Title: Re: Bug in linuxfslib.php causing disk usage not to be count
Post by: Spacedust on 2013-04-22, 19:42:40
Quote from: "MRatWork"
Using 'quota -u' not work in my servers

Make sure you use add "usrjquota=aquota.user,grpjquota=aquota.group,usrquota,grpquota" to each entry you want quotas in /etc/fstab:

Code: [Select]
proc /proc proc defaults 0 0
none /dev/pts devpts gid=5,mode=620 0 0
tmpfs /dev/shm        tmpfs   defaults        0       0
/dev/md0 /boot ext3           defaults  1 1
/dev/md1        /       ext4    rw,discard,noatime,nodiratime,usrjquota=aquota.user,grpjquota=aquota.group,usrquota,grpquota,jqfmt=vfsv0        1       1
/dev/md2        /home   ext4    rw,noatime,nodiratime,usrjquota=aquota.user,grpjquota=aquota.group,usrquota,grpquota,jqfmt=vfsv0        0       0
/dev/md3 /var/lib/mysql ext4    rw,discard,noatime,nodiratime,usrjquota=aquota.user,grpjquota=aquota.group,usrquota,grpquota,jqfmt=vfsv0  1      1
/root/swapfile1 swap swap defaults 0 0

Then reboot to remount all partition.

Then run /script/fixquota and all will work ok.
Title: Re: Bug in linuxfslib.php causing disk usage not to be count
Post by: MRatWork on 2013-04-22, 19:48:38
@Spacedust,

A problems is most servers (especially vps) not using quota for partitions. Using 'quota -u' need modified partition config and it's make more difficult rather then using 'du -sc'.
Title: Re: Bug in linuxfslib.php causing disk usage not to be count
Post by: Spacedust on 2013-04-22, 19:53:07
Quote from: "MRatWork"
@Spacedust,

A problems is most servers (especially vps) not using quota for partitions. Using 'quota -u' need modified partition config and it's make more difficult rather then using 'du -sc'.

All servers should use quotas. What's the problem to add these entries during Kloxo install ?

You can then remount partitions with:

Code: [Select]
remount -o /dev/<partitionname>
No need to reboot. cPanel and DirectAdmin are using quotas so I don't know what's the problem.

If you dislike quotas then please make a second version with du -sc and use it by default. We won't use du -sc because it's overloading our servers.

Imagine what would happens if you run it on a 16 TB array. It would take ages to complete.

If you won't use quotas then your users are able to use more disk space than they're allowed so this is a big security problem.
Title: Re: Bug in linuxfslib.php causing disk usage not to be count
Post by: Spacedust on 2013-04-22, 20:01:10
Sorry, a typo:

Code: [Select]
mount -o remount /dev/<partitionname>
Then you should see something like this inside dmesg:

Code: [Select]
EXT4-fs (md1): re-mounted. Opts: discard,usrjquota=aquota.user,grpjquota=aquota.group,usrquota,grpquota,jqfmt=vfsv0
Title: Re: Bug in linuxfslib.php causing disk usage not to be count
Post by: MRatWork on 2013-04-22, 20:14:32
Try with:
Code: [Select]
// exec("du -sc {$path} | grep -i '{$path}'", $out);
exec("du -s {$path}", $out);
$os  = preg_replace("/s+/", ":", $out[0]);
$t = str_replace(":{$path}", "", $os);
Title: Re: Bug in linuxfslib.php causing disk usage not to be count
Post by: Spacedust on 2013-04-22, 20:30:30
Quote from: "MRatWork"
Try with:
Code: [Select]
// exec("du -sc {$path} | grep -i '{$path}'", $out);
exec("du -s {$path}", $out);
$os  = preg_replace("/s+/", ":", $out[0]);
$t = str_replace(":{$path}", "", $os);

Work ok for me, but maybe we should use ionice -c2 before this command to reduce I/O load ?

How these lines should look if I want to use quota ?
Title: Re: Bug in linuxfslib.php causing disk usage not to be count
Post by: MRatWork on 2013-04-22, 20:48:15
Yes. this function 'lxfile_dirsize($path, $byteflag = false)' need 'path'.

If using 'quota -u', need new function like 'lxfile_quotasize($user, $byteflag = false)'.
Title: Re: Bug in linuxfslib.php causing disk usage not to be count
Post by: Spacedust on 2013-04-22, 22:54:42
Quote from: "MRatWork"
Yes. this function 'lxfile_dirsize($path, $byteflag = false)' need 'path'.

If using 'quota -u', need new function like 'lxfile_quotasize($user, $byteflag = false)'.

Can you write one for testing purposes ?
Title: Re: Bug in linuxfslib.php causing disk usage not to be count
Post by: Spacedust on 2013-04-23, 16:03:52
Mustafa do something about this. It's overloading our servers !!!

Here's load average from last night:

(http://imageshack.us/a/img197/2788/1load1.png)
Title: Re: Bug in linuxfslib.php causing disk usage not to be count
Post by: Spacedust on 2013-04-23, 16:17:12
To get quota running on particular customer you have to create client with Resource Package and limited disk space for example to 50 GB.
Title: Re: Bug in linuxfslib.php causing disk usage not to be count
Post by: Spacedust on 2013-04-23, 16:29:20
Here you've got tutorial how to enable quota: http://www.yolinux.com/TUTORIALS/LinuxT ... uotas.html (http://www.yolinux.com/TUTORIALS/LinuxTutorialQuotas.html)

It works fine on my VPS:

Code: [Select]
[root@nowosci /]# quota -u testclient                                                   Ograniczenia dyskowe user testclient (uid 7798):
 System plików   bloki mi?kki  twardy  pob?.   pliki mi?kki  twardy  pob?.
      /dev/root  100256  51200000 51200000              34       0       0
Title: Re: Bug in linuxfslib.php causing disk usage not to be count
Post by: Spacedust on 2013-04-23, 16:36:09
My temporary solution:

Code: [Select]
      exec("ionice -c2 -n7 du -s {$path}", $out);
       $os  = preg_replace("/s+/", ":", $out[0]);
       $t = str_replace(":{$path}", "", $os);
Title: Re: Bug in linuxfslib.php causing disk usage not to be count
Post by: Spacedust on 2013-04-23, 16:55:28
Look how this is made inside DirectAdmin:

http://forum.directadmin.com/showthread ... #post51071 (http://forum.directadmin.com/showthread.php?t=8818&p=51071#post51071)
Title: Re: Bug in linuxfslib.php causing disk usage not to be count
Post by: MRatWork on 2013-04-23, 17:22:52
I will use your 'ionice -c2 -n7' code.

For quota, it's not easy because need overhaul the code related to diskuse.
Title: Re: Bug in linuxfslib.php causing disk usage not to be count
Post by: Spacedust on 2013-04-23, 18:24:16
Quote from: "MRatWork"
I will use your 'ionice -c2 -n7' code.

For quota, it's not easy because need overhaul the code related to diskuse.

We will have to do this anyway in future. I will be testing the new command tonight.
Title: Re: Bug in linuxfslib.php causing disk usage not to be count
Post by: Spacedust on 2013-04-24, 00:08:50
I found another bug !

Go to admin home -> select domains -> choose domains -> TotDisk is always 0 !

(http://img836.imageshack.us/img836/6609/aaaabl.jpg)
Title: Re: Bug in linuxfslib.php causing disk usage not to be count
Post by: MRatWork on 2013-04-24, 01:31:37
Look like certain codes unfinished by Ligesh. So, need more time to investigate dirsize codes.
Title: Re: Bug in linuxfslib.php causing disk usage not to be count
Post by: Spacedust on 2013-04-24, 01:57:35
Quote from: "MRatWork"
Look like certain codes unfinished by Ligesh. So, need more time to investigate dirsize codes.

He propably wanted to add quota disk usage anyway. What would be the reason to integrate quotas directly inside Kloxo ? Try to do tail -f /usr/local/lxlabs/kloxo/shell_exec and then add customer with Resource Plan - you will see setquota command ;)
Title: Re: Bug in linuxfslib.php causing disk usage not to be count
Post by: Spacedust on 2013-04-25, 15:04:04
This is still causing our servers to overload. This can't stay that way !
Title: Re: Bug in linuxfslib.php causing disk usage not to be count
Post by: Spacedust on 2013-04-25, 17:25:00
Mustafa please write this function ASAP and I will donate this project !
Title: Re: Bug in linuxfslib.php causing disk usage not to be count
Post by: Spacedust on 2013-04-25, 18:22:29
I'm getting somewhere:

Code: [Select]
     exec("quota -u testclient | tail -1 | awk '{print $2}'", $out);
       $os  = preg_replace("/s+/", ":", $out[0]);
       $t = str_replace(":{$user}", "", $os);

This is reporting correctly, but all values for mail, mysql and web are the same.

First I need to replace testclient with $user then add additional function to use quota for web usage only.
Title: Re: Bug in linuxfslib.php causing disk usage not to be count
Post by: Spacedust on 2013-04-26, 00:26:00
Quote
I will use your 'ionice -c2 -n7' code.

Please use ionice -c3 -n7 at least ! This is the lowest priority.
Title: Re: Bug in linuxfslib.php causing disk usage not to be count
Post by: Spacedust on 2013-05-03, 00:05:06
Our developer will create quota for Kloxo-MR.