-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun_redis.sh
executable file
·72 lines (66 loc) · 1.74 KB
/
run_redis.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#!/bin/bash
if [ "$1" = "-h" ]; then
echo "./run_redis.sh run"
echo "./run_redis.sh clean"
exit 0
fi
redis_run() {
port=$1
aof=$2
conf_file=redis_$port.conf
if [ ! -f "redis_$port.conf" ]; then
cp redis.conf redis_$port.conf
mkdir $port
sed -i "s/^daemonize.*/daemonize yes/g" $conf_file
sed -i "s/^protected-mode.*/protected-mode no/g" $conf_file
sed -i "s/6379/$port/g" $conf_file
sed -i "s/^bind.*/#&/g" $conf_file
sed -i "s/^dir.*/&$port\//g" $conf_file
sed -i "/nvm/d;/pointer/d" $conf_file
if [ "$aof" = "noaof" ]
then
sed -i "s/^appendonly.*/appendonly no/g" $conf_file
else
sed -i "s/^appendonly.*/appendonly yes/g" $conf_file
sed -i "s/^appendfsync.*/appendfsync always/g" $conf_file
fi
if [ -d "/mnt/pmem0" ]
then
sed -i '$a\nvm-maxcapacity 1' $conf_file
sed -i '$a\nvm-dir \/mnt\/pmem0' $conf_file
sed -i '$a\nvm-threshold 64' $conf_file
sed -i '$a\pointer-based-aof yes' $conf_file
touch /mnt/pmem0/redis-port-$port-1GB-AEP
dd if=/dev/zero of=/mnt/pmem0/redis-port-$port-1GB-AEP bs=1024k count=1024 >/dev/null 2>&1
fi
fi
cpu=`echo "$port - 6379" | bc`
taskset -c $cpu redis-server $conf_file >/dev/null 2>&1
cpuset0=`echo "$port - 6379" | bc`
cpuset1=`echo "$cpuset0 + 12" | bc`
taskset -c $cpuset0,$cpuset1 redis-server $conf_file >/dev/null 2>&1
}
redis_clean() {
port=$1
aof=$2
conf_file=redis_$port.conf
redis-cli -p $port shutdown
rm -rf $port $conf_file
if [ -d "/mnt/pmem0" ]; then
rm -rf /mnt/pmem0/redis*
fi
}
Operation=$1 #clean or run
######################
# Run or Clean Redis #
######################
for port in $PORT_LIST
do
# echo $port
if [ "$Operation" = "run" ]; then
redis_run $port $AOF
fi
if [ "$Operation" = "clean" ]; then
redis_clean $port
fi
done