Skip to content

Commit cedcf1a

Browse files
authored
Sonm standby (#16)
* Add switcher to internal mining for Hive OS
1 parent fd28845 commit cedcf1a

File tree

3 files changed

+83
-0
lines changed

3 files changed

+83
-0
lines changed

hive/sonm-standby

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
#!/usr/bin/env bash
2+
3+
log() {
4+
echo $(date --rfc-3339=seconds) - $1
5+
}
6+
7+
check_deal() {
8+
echo $(sonmcli worker ask-plan list | grep deal)
9+
}
10+
11+
check_miner() {
12+
echo $(ps ax | grep miner | grep SCREEN)
13+
}
14+
15+
wait_deal() {
16+
while true; do
17+
SONM_DEAL=$(check_deal)
18+
if [ -z "$SONM_DEAL" ]; then
19+
log "No deal in SONM, waiting"
20+
sleep 10
21+
else
22+
log "Deal opened: ${SONM_DEAL}, stopping miner"
23+
miner stop
24+
watch_deal
25+
fi
26+
done
27+
}
28+
29+
watch_deal() {
30+
while true; do
31+
SONM_DEAL=$(check_deal)
32+
if ! [ -z "$SONM_DEAL" ]; then
33+
log "Deal is active ($SONM_DEAL), waiting"
34+
if ! [ -z "$(check_miner)" ]; then
35+
log "WARN - Miner is running for some reason, stopping miner"
36+
miner stop
37+
fi
38+
sleep 10
39+
else
40+
log "Deal has been closed: starting miner"
41+
miner start
42+
wait_deal
43+
fi
44+
done
45+
}
46+
47+
MINER_STATUS=$(check_miner)
48+
SONM_STATUS=$(check_deal)
49+
50+
if [ -z "$MINER_STATUS" ]; then
51+
log "Miner not running"
52+
if [ -z "$SONM_STATUS" ]; then
53+
log "There's no deal in SONM, starting miner"
54+
miner start
55+
wait_deal
56+
else
57+
log "There is the deal in SONM ($SONM_STATUS), waiting for deal finish"
58+
watch_deal
59+
fi
60+
else
61+
log "Miner is running"
62+
if [ -z "$SONM_STATUS" ]; then
63+
log "There's no deal in SONM, waiting for the deal"
64+
wait_deal
65+
else
66+
log "There is the deal in SONM ($SONM_STATUS), stopping miner"
67+
miner stop
68+
watch_deal
69+
fi
70+
fi

hive/sonm-standby.service

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
[Unit]
2+
Description=Switcher for Sonm/Hive internal mining
3+
After=sonm-worker.service
4+
5+
[Service]
6+
Type=oneshot
7+
ExecStart=/usr/bin/sonm-standby

sonm-auto-deploy-supplier.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,11 +208,17 @@ fix_hive() {
208208
wget -q ${github_url}/${branch}/hive/sonm-xorg-config -O /usr/bin/sonm-xorg-config
209209
chmod +x /usr/bin/sonm-xorg-config
210210

211+
wget -q ${github_url}/${branch}/hive/sonm-standby.service -O /etc/systemd/system/sonm-standby.service
212+
wget -q ${github_url}/${branch}/hive/sonm-standby -O /usr/bin/sonm-standby
213+
chmod +x /usr/bin/sonm-standby
214+
211215
echo "Enabling service"
212216
systemctl daemon-reload
213217
systemctl enable sonm-xorg-config.service
214218
systemctl restart sonm-xorg-config.service
215219
systemctl restart hivex.service
220+
systemctl enable sonm-standby.service
221+
systemctl restart sonm-standby.service
216222
fi
217223
}
218224

0 commit comments

Comments
 (0)