finish quota set/get worker and test it
authorroot <root@narada.(none)>
Sat, 10 Dec 2011 15:35:28 +0000 (16:35 +0100)
committerDobrica Pavlinusic <dpavlin@rot13.org>
Sat, 10 Dec 2011 16:31:41 +0000 (17:31 +0100)
gearman/narada_s1_get_quota.sh [deleted file]
gearman/narada_s1_quota [new file with mode: 0755]
test-quota.sh [new file with mode: 0755]

diff --git a/gearman/narada_s1_get_quota.sh b/gearman/narada_s1_get_quota.sh
deleted file mode 100755 (executable)
index 07a38f2..0000000
+++ /dev/null
@@ -1,14 +0,0 @@
-#!/bin/sh -xe
-
-if [ "$1" = "get_quota" ] ; then
-       while read uid ; do
-               quota --raw-grace --no-wrap -u $uid | tail -1 | awk '{ print $2 " " $3 }'
-       done
-elif [ "$1" = "start" ] ; then
-       LD_PRELOAD=/mnt/narada/rootfs/usr/lib/libgearman.so.4 /mnt/narada/rootfs/usr/bin/gearman \
-       -h 10.60.0.240 -p 4730 -i /mnt/narada/rootfs/tmp/narada_s1_get_quota.pid \
-       -n -f narada_s1_get_quota -w $0 get_quota &
-elif [ "$1" = "stop" ] ; then
-       kill `cat /mnt/narada/rootfs/tmp/narada_s1_get_quota.pid`
-fi
-
diff --git a/gearman/narada_s1_quota b/gearman/narada_s1_quota
new file mode 100755 (executable)
index 0000000..cd393b9
--- /dev/null
@@ -0,0 +1,34 @@
+#!/bin/sh -e
+
+name=`basename $0`
+op=$2
+test -z "$op" && op="get"
+tmp_file="/mnt/narada/rootfs/tmp/${name}_${op}"
+pid_file="${tmp_file}.pid"
+log_file="${tmp_file}.log"
+echo "# $name $op" >> $log_file
+
+if [ "$1" = "get" ] ; then
+       while read uid ; do
+               echo -n "get $uid = " >> $log_file
+               quota --raw-grace --no-wrap -u $uid | tail -1 \
+                       | awk '{ print $2 " " $3 }' | tee -a $log_file \
+                       | grep '^[0-9][0-9]*'
+       done
+elif [ "$1" = "set" ] ; then
+       while read uid quota ; do
+               echo "set $uid $quota" >> $log_file
+               setquota -u $uid $quota 0 0 0 /mnt/narada/
+               quota --raw-grace --no-wrap -u $uid | tail -1
+       done
+elif [ "$1" = "start" ] ; then
+       test -e $pid_file && kill `cat $pid_file`
+       LD_PRELOAD=/mnt/narada/rootfs/usr/lib/libgearman.so.4 /mnt/narada/rootfs/usr/bin/gearman \
+       -h 10.60.0.240 -p 4730 -i $pid_file \
+       -n -f ${name}_${op} -w `pwd`/$0 $op &
+elif [ "$1" = "stop" ] ; then
+       kill `cat $pid_file` && rm $pid_file
+elif [ "$1" = "status" ] ; then
+       kill -s 0 `cat $pid_file` && echo "$name $op OK";
+fi
+
diff --git a/test-quota.sh b/test-quota.sh
new file mode 100755 (executable)
index 0000000..6a5b9d4
--- /dev/null
@@ -0,0 +1,7 @@
+#!/bin/sh -xe
+
+echo 2001 | gearman -f narada_s1_quota_get -n
+echo "2001 20000" | gearman -f narada_s1_quota_set -n
+echo 2001 | gearman -f narada_s1_quota_get -n
+echo "2001 10000" | gearman -f narada_s1_quota_set -n
+echo 2001 | gearman -f narada_s1_quota_get -n