aboutsummaryrefslogtreecommitdiff
path: root/system/bees/rc.bees
blob: e28122e4964232b183d8483cd333f8bee5b2181d (plain)
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
#!/bin/bash

declare -a UUIDS
declare -a LOGFILES

. /etc/rc.d/rc.bees.conf

umount_uuid()
{
	UUID="$1"
	MNT="/run/bees/mnt/$UUID"
	# Try for up to 10 seconds and then bail out
	for _ in {1..10} ; do
		umount "$MNT" > /dev/null 2>&1
		if mountpoint -q "$MNT" ; then
			sleep 1
		else
			break
		fi
	done
}

bees_start()
{
	for i in "${!UUIDS[@]}" ; do
		UUID="${UUIDS[$i]}"
		LOGFILE="${LOGFILES[$i]}"
		umount_uuid "$UUID"
		nice -n 15 ionice -c 3 daemon --name="bees.$UUID" --output="$LOGFILE" -- beesd "$UUID"
	done
}

bees_stop()
{
	for UUID in "${UUIDS[@]}" ; do
		daemon --name="bees.$UUID" --stop
		umount_uuid "$UUID"
	done
}

bees_status()
{
	for UUID in "${UUIDS[@]}" ; do
		daemon --name="bees.$UUID" --running --verbose
	done
}

bees_forcestop()
{
	killall bees
}

case "$1" in
	'start')
		bees_start
		;;
	'stop')
		bees_stop
		;;
	'status')
		bees_status
		;;
	'forcestop')
		bees_forcestop
		;;
	*)
		echo "usage $0 start|stop|status|forcestop"
		;;
esac