#!/usr/bin/perl # Script to sync context disk limit quotas. # Written by Matt Ayres and released to the public domain. $prefix = '/root/cq-tools-0.06'; @devices = qw(hda7 hdc2); $runpath = '/var/run/vservers'; $dbpath = '/var/db/vservers'; $sync_interval = 60; while (1) { while ($file = <$runpath/*.ctx>) { ($inodes_used,$inodes_total,$blocks_used,$blocks_total,$reserved) = 0; open (CTXINFO, $file) || die "Could not open $file: $!"; @ctxinfo = ; close (CTXINFO); $name = $file; $name =~ s#$runpath/(\w+).ctx#$1#g; $ctxinfo[0] =~ /S_CONTEXT=(\d+)/; $ctx = $1; foreach $device (@devices) { open (CQDLIM, "$prefix/cqdlim -x $ctx /dev/$device |") || die "Could not open cqdlim: $!"; while ($line = ) { chomp $line; if ($line =~ /inodes:/) { $line =~ m#^inodes:\s(\d+)/(\d+)$#; $inodes_used = $1; $inodes_total = $2; } elsif ($line =~ /blocks:/) { $line =~ m#^blocks:\s(\d+)/(\d+)\s\((\d+)%\)$#; $blocks_used = $1; $blocks_total = $2; $reserved = $3; } } if ($blocks_used > 1) { # print "Found blocks used for $ctx on /dev/$device\n"; open (DLIM, ">$dbpath/$ctx.dlim") || die "Could not open $dbpath/$ctx.dlim: $!"; print DLIM "$inodes_used $inodes_total $blocks_used $blocks_total $reserved\n"; close (DLIM); } } } sleep $sync_interval; }