aboutsummaryrefslogtreecommitdiffstats
path: root/lava-slave/scripts/retire.sh
blob: def6c8e71bb91be46ecb402d4282821fbeec9014 (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
#!/bin/bash

LAVA_MASTER_URI=$1

if [ -z "$LAVA_MASTER_URI" ];then
	echo "retire.sh: remove an offline worker"
	echo "Usage: $0 LAVA_MASTER_URI"
	echo "ERROR: Missing LAVA_MASTER_URI"
	exit 11
fi

LAVACLIOPTS="--uri $LAVA_MASTER_URI"

retire_worker() {
	worker=$1
	lavacli $LAVACLIOPTS workers list |grep -q $worker
	if [ $? -eq 0 ];then
		echo "Removing $worker"
		lavacli $LAVACLIOPTS workers update $worker || exit $?
	else
		echo "SKIP: worker $worker does not exists"
		return 0
	fi
	lavacli $LAVACLIOPTS devices list -a | grep '^\*' | cut -d' ' -f2 |
	while read devicename
	do
		lavacli $LAVACLIOPTS devices show $devicename |grep -q "^worker.*$worker$"
		if [ $? -eq 0 ];then
			echo "Retire $devicename"
			lavacli $LAVACLIOPTS devices update --health RETIRED --worker $worker $devicename || exit $?
		fi
	done
	return 0
}

if [ -z "$2" ];then
	for ww in $(ls devices/)
	do
		retire_worker $ww
	done
else
	retire_worker $2
fi