This repository has been archived by the owner on Sep 25, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
update.sh
executable file
·141 lines (129 loc) · 4.39 KB
/
update.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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
#!/bin/bash
# update.sh is run manually
# * It synchronises the local copy of LNXDIAGD with the current github BRANCH
# * It checks the state of and (re-)starts daemons if they are not (yet) running.
HOSTNAME=$(hostname)
BRANCH=$(cat "$HOME/.lnxdiagd.branch")
# Wait for the daemons to finish their job. Prevents stale locks when restarting.
#echo "Waiting 30s..."
#sleep 30
# make sure working tree exists
if [ ! -d /tmp/lnxdiagd/site/img ]; then
mkdir -p /tmp/lnxdiagd/site/img
chmod -R 755 /tmp/lnxdiagd
fi
# make sure working tree exists
if [ ! -d /tmp/lnxdiagd/mysql4gnuplot ]; then
mkdir -p /tmp/lnxdiagd/mysql4gnuplot
chmod -R 755 /tmp/lnxdiagd
fi
pushd "$HOME/lnxdiagd"
# shellcheck disable=SC1091
source ./includes
git fetch origin
# Check which files have changed
DIFFLIST=$(git --no-pager diff --name-only "$BRANCH..origin/$BRANCH")
git pull
git fetch origin
git checkout "$BRANCH"
git reset --hard "origin/$BRANCH" && git clean -f -d
# Set permissions
# chmod -R 744 ./*
for fname in $DIFFLIST; do
echo "> $fname was updated from GIT"
f7l4="${fname:0:15}${fname:${#fname}-4}"
f6l4="${fname:0:14}${fname:${#fname}-4}"
f5l3="${fname:0:14}${fname:${#fname}-4}"
# Detect DIAG changes
if [[ "$f7l4" == "daemons/lnxdiagd.py" ]]; then
echo " ! Diagnostic daemon changed"
eval "./$fname stop"
fi
# Detect SVC changes
if [[ "$f6l4" == "daemons/lnxsvcd.py" ]]; then
echo " ! Service daemon changed"
eval "./$fname stop"
fi
#CONFIG.INI changed
if [[ "$fname" == "config.ini" ]]; then
echo " ! Configuration file changed"
echo " o Restarting all daemons"
for daemon in $diaglist; do
echo " +- Restart DIAG ${daemon}"
eval "./daemons/lnxdiag${daemon}d.py restart"
done
echo " o Restarting all service daemons"
for daemon in $srvclist; do
echo " +- Restart SVC ${daemon}"
eval "./daemons/lnxsvc${daemon}d.py restart"
done
fi
done
# Check if DIAG daemons are running
for daemon in $diaglist; do
if [ -e "/tmp/lnxdiagd/${daemon}.pid" ]; then
if ! kill -0 $(cat "/tmp/lnxdiagd/${daemon}.pid") > /dev/null 2>&1; then
logger -p user.err -t lnxdiagd " * Stale daemon ${daemon} pid-file found."
rm "/tmp/lnxdiagd/${daemon}.pid"
echo " * Start DIAG ${daemon}"
eval "./daemons/lnxdiag${daemon}d.py start"
fi
else
logger -p user.notice -t lnxdiagd "Found daemon ${daemon} not running."
echo " * Start DIAG ${daemon}"
eval "./daemons/lnxdiag${daemon}d.py start"
fi
done
# Check if SVC daemons are running
for daemon in $srvclist; do
if [ -e "/tmp/lnxdiagd/${daemon}.pid" ]; then
if ! kill -0 $(cat "/tmp/lnxdiagd/${daemon}.pid") > /dev/null 2>&1; then
logger -p user.err -t lnxdiagd "* Stale daemon ${daemon} pid-file found."
rm "/tmp/lnxdiagd/${daemon}.pid"
echo " * Start SVC ${daemon}"
eval "./daemons/lnxsvc${daemon}d.py start"
fi
else
logger -p user.notice -t lnxdiagd "Found daemon ${daemon} not running."
echo " * Start SVC ${daemon}"
eval "./daemons/lnxsvc${daemon}d.py start"
fi
done
# Do some host specific stuff
case "$HOSTNAME" in
rbagain ) echo "Weather Monitor"
;;
bbone ) echo "BeagleBone Black"
;;
rbups ) echo "UPS monitor"
;;
rbux ) echo "Testbench"
;;
rbux3 ) echo "Testbench RPi3"
;;
rbelec ) echo "Electricity monitor"
;;
rbian ) echo "Raspberry testbench"
;;
osmc ) echo "OSMC Media Center"
;;
boson ) echo "BOSON"
if [ -e /tmp/lnxdiagd/19.pid ]; then
if ! kill -0 $(cat /tmp/lnxdiagd/19.pid) > /dev/null 2>&1; then
logger -p user.err -t lnxdiagd "* Stale daemon 19 pid-file found."
rm /tmp/lnxdiagd/19.pid
echo " * Start DIAG 19"
eval ./daemons/lnxdiag19d.py restart
fi
else
logger -p user.notice -t lnxdiagd "Found daemon 19 not running."
echo " * Start DIAG 19"
eval ./daemons/lnxdiag19d.py start
fi
;;
neutron ) echo "NEUTRON"
;;
* ) echo "!! undefined client !!"
;;
esac
popd