-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathosiris.sh
More file actions
44 lines (39 loc) · 1.03 KB
/
osiris.sh
File metadata and controls
44 lines (39 loc) · 1.03 KB
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
#!/bin/sh
workingDir=/home/bot/maverage
scriptName=maverage.py
# -ac for holdntrade
params=
# only for maverage
exclude=mamaster
minFree=40960
resurrect() {
instance=$1
echo "resurrecting ${instance}"
if ! tmux has-session -t "${instance}" 2>/dev/null; then
tmux new -d -s "${instance}"
sleep 1
fi
tmux send-keys -t "${instance}" C-z "${workingDir}/${scriptName} ${instance} ${params}" C-m
}
if [ ${minFree} -gt 0 ]; then
available=$(free | awk 'NR == 2{print $7}')
if [ "${available}" -lt ${minFree} ]; then
echo "terminating all ${scriptName} instances"
killall ${scriptName} 2>/dev/null
fi
fi
cd "${workingDir}" || exit 1
find . -name "*.pid" -type f 2>/dev/null | while read -r file;
do
read -r pid instance < "${file}"
if [ "${instance}" != ${exclude} ]; then
if kill -0 "${pid}" 2>/dev/null; then
processName=$(ps --pid "${pid}" -o comm h)
if [ "${scriptName}" = "${processName}" ]; then
echo "${instance} is alive"
continue
fi
fi
resurrect "${instance}"
fi
done