new quota functions accept login not uid
[cloudstore.git] / gearman / narada_s1_quota
1 #!/bin/sh -e
2
3 # sudo /mnt/narada/rootfs/srv/cloudstore/gearman/narada_s1_quota start get
4 # sudo /mnt/narada/rootfs/srv/cloudstore/gearman/narada_s1_quota start set
5
6 name=`basename $0`
7 op=$2
8 test -z "$op" && op="get"
9 tmp_file="/mnt/narada/rootfs/tmp/${name}_${op}"
10 pid_file="${tmp_file}.pid"
11 log_file="${tmp_file}.log"
12 echo "# $name $op" >> $log_file
13
14 if [ "$1" = "get" ] ; then
15         while read login ; do
16                 uid=`echo $login | sed 's/^u//'`
17                 echo -n "get $uid = " >> $log_file
18                 quota --raw-grace --no-wrap -u $uid | tail -1 \
19                         | awk '{ print $2 " " $3 }' | sed -e 's/*//' | tee -a $log_file
20         done
21 elif [ "$1" = "set" ] ; then
22         while read login quota ; do
23                 uid=`echo $login | sed 's/^u//'`
24                 echo "set $uid $quota" >> $log_file
25                 setquota -u $uid $quota 0 0 0 /mnt/narada/
26                 #quota --raw-grace --no-wrap -u $uid | tail -1
27         done
28 elif [ "$1" = "start" ] ; then
29         test -e $pid_file && kill `cat $pid_file` || true;
30         LD_PRELOAD=/mnt/narada/rootfs/usr/lib/libgearman.so.4 /mnt/narada/rootfs/usr/bin/gearman \
31         -h 10.60.0.244 -p 4730 -i $pid_file \
32         -n -f ${name}_${op} -w $0 $op &
33 elif [ "$1" = "stop" ] ; then
34         kill `cat $pid_file` && rm $pid_file
35 elif [ "$1" = "status" ] ; then
36         kill -s 0 `cat $pid_file` && echo "$name $op OK";
37 fi
38