summaryrefslogtreecommitdiff
path: root/unittest/pre/beluga/system/tools/agent_config.sh
blob: c44994145712387bed5d9884d452999382436586 (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
#! /bin/sh
#set -e

WORK_DIR=/etc/dockzen/sc
AGENT_JSON=$WORK_DIR/dockzen_agent.json
INIT_JSON=$WORK_DIR/factory_init.json

stop() {
	echo "Stop docker service of dockzen-agent"
	if [ ! -z "$(docker service ls -q)" ]; then
		docker service rm $(docker service ls -q)
	fi
	docker system prune -f
	echo "Stop dockzen-launcher.service"
	systemctl status dockzen-launcher.service | grep Active
	systemctl stop dockzen-launcher.service
	systemctl status dockzen-launcher.service | grep Active
	echo "Change symbolic link of dockzen_agent.json"
	rm $AGENT_JSON
	echo "Clear init flag"
	rm $INIT_JSON
	echo "Start dockzen-launcher.service"
	systemctl start dockzen-launcher.service
	echo "Done"
}

restart() {
	echo "Start dockzen-launcher.service"
	systemctl start dockzen-launcher.service
}

if [ "$1" == "noop" ]; then
	echo "---------------------------------------------------"
	echo "  clear agent as no-operation"
	echo "---------------------------------------------------"
	stop
	restart
	echo "Cleared !!!"
elif [ "$1" == "show" ]; then
	echo "---------------------------------------------------"
	echo "  show current agent"
	echo "---------------------------------------------------"
	if [ -f "$AGENT_JSON" ]; then
		readlink $AGENT_JSON
	else
		echo "empty file ($AGENT_JSON)"
	fi
	echo "Completed !!!"
elif [ -f "$1" ]; then
	echo "---------------------------------------------------"
	echo "  change agent target"
	echo "---------------------------------------------------"
	stop
	echo "Change symbolic link of dockzen_agent.json(-->$1)"
	ln -s $1 $AGENT_JSON
	restart
	echo "Done !!! linked to \"$(readlink $AGENT_JSON)\""
else
	echo "check input parameter"
	echo "Usage 1 : ./agent_set noop (disable agent)"
	echo "Usage 2 : ./agent_set show (display current agent config file)"
	echo "Usage 3 : ./agent_set [json file] (set agent config file)"
fi