-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall-on-device.sh
executable file
·109 lines (90 loc) · 3.33 KB
/
install-on-device.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
#!/bin/bash
set -e
PROJECT_DIR=$(dirname "$0")
LATENCY_SERVER_HOME_DIR=/opt/latency_server
LATENCY_SERVER_LOG_DIR=$LATENCY_SERVER_HOME_DIR/log
LATENCY_SERVER_WORKING_DIR=$LATENCY_SERVER_HOME_DIR/working_dir
uninstall_service() {
local service_name=$1
local service_unit=$service_name.service
# uninstall service
if systemctl list-units --full -all | grep -Fq "$service_unit"; then
echo "removing $service_name from systemd"
systemctl stop "$service_unit"
systemctl disable "$service_unit"
rm -f /etc/systemd/system/"$service_unit"
systemctl daemon-reload
systemctl reset-failed
echo "$service_name is removed from systemd"
fi
}
uninstall() {
# uninstall supervisor service
uninstall_service "supervisor"
# remove supervisor configs
if [ -d /etc/supervisor ]; then
rm -rf /etc/supervisor
echo "supervisor configuration files is removed"
fi
# remove latency server home dir
if [ -d $LATENCY_SERVER_HOME_DIR ]; then
rm -rf $LATENCY_SERVER_HOME_DIR
echo "log/configuration/tmp latency server files is removed"
fi
# uninstall latency server python package
python3 -m pip uninstall -y texas-instruments-latency-server
echo "latency server python package is removed"
}
install() {
# prepare dirs
mkdir -p $LATENCY_SERVER_HOME_DIR
mkdir -p $LATENCY_SERVER_LOG_DIR
mkdir -p $LATENCY_SERVER_WORKING_DIR
echo "latency server directories is created"
# copy tidl tools
tar -xvf "$PROJECT_DIR"/3rd_party/tidl_tools.tar.gz -C $LATENCY_SERVER_HOME_DIR
echo "tidl runtime is copied"
# update pip
python3 -m pip install pip -U
# install latency server package
python3 -m pip install "$PROJECT_DIR"'[device_server]'
echo "latency server python package is installed"
# install supervisor package
python3 -m pip install pip supervisor
echo "supervisor python package is installed"
# install supervisor configs
mkdir -p /etc/supervisor/
SUPERVISOR_DIR="$PROJECT_DIR"/3rd_party/supervisor/device-server
cp "$SUPERVISOR_DIR"/etc/supervisor/supervisord.conf /etc/supervisor/supervisord.conf
cp "$SUPERVISOR_DIR"/etc/systemd/system/supervisor.service /etc/systemd/system/supervisor.service
echo "supervisor configs is copied"
# install supervisor service
systemctl enable supervisor.service
systemctl start supervisor.service
echo "supervisor service is installed"
}
check_installation(){
echo ""
echo "===================================="
echo "checking latency server installation"
echo "===================================="
echo ""
python_package_status=$(python3 -c "import texas_instruments_latency_server" &> /dev/null && echo -n "OK" || echo -n "ERROR")
echo -e "latency server python package\t\t$python_package_status"
home_dir_status=$([ -d $LATENCY_SERVER_HOME_DIR ] && echo -n "OK" || echo -n "ERROR")
echo -e "latency server home directory\t\t$home_dir_status"
service_installed_status=$(systemctl list-units --full --all | grep -Fq supervisor.service && echo -n "OK" || echo -n "ERROR")
echo -e "supervisord service is installed\t$service_installed_status"
service_is_active_status=$(systemctl is-active --quiet supervisor.service && echo -n "OK" || echo -n "ERROR")
echo -e "supervisord service is active\t\t$service_is_active_status"
}
safe_install(){
uninstall
install
sleep 3
check_installation
}
update(){
safe_install
}
safe_install