forked from zunxbt/pop-mining
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhemifee.sh
More file actions
65 lines (52 loc) · 1.93 KB
/
hemifee.sh
File metadata and controls
65 lines (52 loc) · 1.93 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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#!/bin/bash
show() {
echo -e "\033[1;35m$1\033[0m"
}
restart_service() {
local service_name="hemi.service"
local attempts=0
local max_attempts=10
while (( attempts < max_attempts )); do
sudo systemctl restart "$service_name"
if systemctl is-active --quiet "$service_name"; then
show "$service_name restarted successfully."
return 0
else
attempts=$((attempts + 1))
show "Failed to restart $service_name (Attempt $attempts/$max_attempts). Retrying in 5 seconds..."
sleep 15
fi
done
show "Failed to restart $service_name after $max_attempts attempts."
return 1
}
fetch_and_update_fee() {
local service_name="hemi.service"
local service_file="/etc/systemd/system/$service_name"
while true; do
raw_fee=$(curl -sSL "https://mempool.space/testnet/api/v1/fees/mempool-blocks" | jq '.[0].medianFee')
if [[ ! -z "$raw_fee" ]]; then
static_fee=$(printf "%.0f" "$raw_fee")
show "Static fee fetched: $static_fee"
if [[ -f "$service_file" ]]; then
if systemctl is-active --quiet "$service_name"; then
show "Stopping $service_name..."
sudo systemctl stop "$service_name"
fi
show "Updating static fee in $service_file"
sudo sed -i '/POPM_STATIC_FEE/d' "$service_file"
sudo sed -i "/\[Service\]/a Environment=\"POPM_STATIC_FEE=$static_fee\"" "$service_file"
sudo systemctl daemon-reload
show "Waiting 15 seconds before restarting the service..."
sleep 15
restart_service "$service_name"
fi
sleep 600
else
show "Failed to fetch static fee. Retrying in 15 seconds."
sleep 15
continue
fi
done
}
fetch_and_update_fee &