File: mkring.sh

package info (click to toggle)
php-redis 5.3.7%2B4.3.0-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 3,012 kB
  • sloc: ansic: 34,345; php: 12,275; xml: 1,910; sh: 297; makefile: 2
file content (55 lines) | stat: -rwxr-xr-x 731 bytes parent folder | download | duplicates (7)
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
#!/bin/bash

PORTS="6379 6380 6381 6382"
REDIS=redis-server

function start_node() {
	P=$1
	echo "starting node on port $P";
	CONFIG_FILE=`tempfile`
	cat > $CONFIG_FILE << CONFIG
port $P
CONFIG
	$REDIS $CONFIG_FILE > /dev/null 2>/dev/null &
	sleep 1
	rm -f $CONFIG_FILE
}

function stop_node() {

	P=$1
	PID=$2
	redis-cli -h localhost -p $P shutdown
	kill -9 $PID 2>/dev/null
}

function stop() {
	for P in $PORTS; do
		PID=`lsof -i :$P | tail -1 | cut -f 2 -d " "`
		if [ "$PID" != "" ]; then
			stop_node $P $PID
		fi
	done
}

function start() {
	for P in $PORTS; do
		start_node $P
	done
}

case "$1" in
	start)
		start
		;;
	stop)
		stop
		;;
	restart)
		stop
		start
		;;
	*)
		echo "Usage: $0 [start|stop|restart]"
		;;
esac