serverwatcher 2.1__tar.gz → 2.1.2__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {serverwatcher-2.1/src/serverwatcher.egg-info → serverwatcher-2.1.2}/PKG-INFO +1 -1
- {serverwatcher-2.1 → serverwatcher-2.1.2}/pyproject.toml +1 -1
- {serverwatcher-2.1 → serverwatcher-2.1.2}/src/serverwatcher/watcher.py +7 -178
- {serverwatcher-2.1 → serverwatcher-2.1.2/src/serverwatcher.egg-info}/PKG-INFO +1 -1
- {serverwatcher-2.1 → serverwatcher-2.1.2}/LICENSE +0 -0
- {serverwatcher-2.1 → serverwatcher-2.1.2}/README.md +0 -0
- {serverwatcher-2.1 → serverwatcher-2.1.2}/setup.cfg +0 -0
- {serverwatcher-2.1 → serverwatcher-2.1.2}/src/serverwatcher/__init__.py +0 -0
- {serverwatcher-2.1 → serverwatcher-2.1.2}/src/serverwatcher/config.py +0 -0
- {serverwatcher-2.1 → serverwatcher-2.1.2}/src/serverwatcher/messages.py +0 -0
- {serverwatcher-2.1 → serverwatcher-2.1.2}/src/serverwatcher.egg-info/SOURCES.txt +0 -0
- {serverwatcher-2.1 → serverwatcher-2.1.2}/src/serverwatcher.egg-info/dependency_links.txt +0 -0
- {serverwatcher-2.1 → serverwatcher-2.1.2}/src/serverwatcher.egg-info/requires.txt +0 -0
- {serverwatcher-2.1 → serverwatcher-2.1.2}/src/serverwatcher.egg-info/top_level.txt +0 -0
|
@@ -1,113 +1,13 @@
|
|
|
1
|
-
import os
|
|
2
1
|
import time
|
|
3
|
-
import yaml
|
|
4
2
|
from zoneinfo import ZoneInfo
|
|
5
3
|
|
|
6
|
-
from hungerlib import
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
DEFAULT_CONFIG = {
|
|
14
|
-
"panel": {
|
|
15
|
-
"name": "My Panel",
|
|
16
|
-
"url": "https://example.com",
|
|
17
|
-
"api_key": "CHANGE_ME"
|
|
18
|
-
},
|
|
19
|
-
|
|
20
|
-
"origin": {
|
|
21
|
-
"server_id": "CHANGE_ME"
|
|
22
|
-
},
|
|
23
|
-
|
|
24
|
-
"server": {
|
|
25
|
-
"name": "My SMP",
|
|
26
|
-
"server_id": "CHANGE_ME",
|
|
27
|
-
"domain": "example.com",
|
|
28
|
-
"port": 25565,
|
|
29
|
-
"rcon_port": 25575,
|
|
30
|
-
"rcon_password": "password",
|
|
31
|
-
"tps_command": "ticks"
|
|
32
|
-
},
|
|
33
|
-
|
|
34
|
-
"watcher": {
|
|
35
|
-
"restart_soon_schedule_id": 0,
|
|
36
|
-
"origin_disable_schedule_id": 0,
|
|
37
|
-
|
|
38
|
-
"thresholds": {
|
|
39
|
-
"ram": 6,
|
|
40
|
-
"cpu": 150,
|
|
41
|
-
"uptime_hours": 12,
|
|
42
|
-
"tps": 19.5
|
|
43
|
-
},
|
|
44
|
-
|
|
45
|
-
"weights": {
|
|
46
|
-
"restart_soon": 3,
|
|
47
|
-
"ram": 1,
|
|
48
|
-
"cpu": 1,
|
|
49
|
-
"uptime": 1,
|
|
50
|
-
"tps": 1,
|
|
51
|
-
"low_uptime": 5,
|
|
52
|
-
"per_player": 1
|
|
53
|
-
},
|
|
54
|
-
|
|
55
|
-
"gaps": {
|
|
56
|
-
"low": 120,
|
|
57
|
-
"high": 60
|
|
58
|
-
},
|
|
59
|
-
|
|
60
|
-
"restart": {
|
|
61
|
-
"wait_seconds": 45,
|
|
62
|
-
"online_timeout": 120,
|
|
63
|
-
"online_interval": 2
|
|
64
|
-
}
|
|
65
|
-
},
|
|
66
|
-
|
|
67
|
-
"messages": {
|
|
68
|
-
"prefix": "<gray>[Watcher]</gray>",
|
|
69
|
-
|
|
70
|
-
"log_start": "Evaluating server health...",
|
|
71
|
-
"log_validation_fail": "Validation failed!",
|
|
72
|
-
"log_no_restart": "No restart needed.",
|
|
73
|
-
"log_immediate_restart": "Restarting immediately...",
|
|
74
|
-
"log_scheduled": "Scheduling restart...",
|
|
75
|
-
"log_gap_low": "Gap is low ({gap}), using low-gap schedule.",
|
|
76
|
-
"log_gap_high": "Gap is high ({gap}), using high-gap schedule.",
|
|
77
|
-
|
|
78
|
-
"reason_restart_soon": "Restart soon schedule is active.",
|
|
79
|
-
"reason_ram": "RAM {ram}GB >= threshold {threshold}GB",
|
|
80
|
-
"reason_cpu": "CPU {cpu}% >= threshold {threshold}%",
|
|
81
|
-
"reason_uptime": "Uptime {uptime} >= {threshold} hours",
|
|
82
|
-
"reason_tps": "TPS {tps} <= threshold {threshold}",
|
|
83
|
-
"reason_low_uptime": "Uptime too low ({uptime})",
|
|
84
|
-
"reason_players": "There {verb} {count} {plural} online.",
|
|
85
|
-
|
|
86
|
-
"broadcast_restart_at": "<yellow>Server restart scheduled at {time}",
|
|
87
|
-
|
|
88
|
-
"broadcast_minute": {
|
|
89
|
-
10: "<red>Restart in 10 minutes!",
|
|
90
|
-
5: "<red>Restart in 5 minutes!",
|
|
91
|
-
1: "<red>Restart in 1 minute!"
|
|
92
|
-
},
|
|
93
|
-
|
|
94
|
-
"broadcast_second": {
|
|
95
|
-
10: "<red>Restart in 10 seconds!",
|
|
96
|
-
5: "<red>Restart in 5 seconds!",
|
|
97
|
-
1: "<red>Restarting now!"
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
def load_or_create_config(path="config.yaml"):
|
|
104
|
-
if not os.path.exists(path):
|
|
105
|
-
with open(path, "w") as f:
|
|
106
|
-
yaml.dump(DEFAULT_CONFIG, f, sort_keys=False)
|
|
107
|
-
print("Generated default config.yaml — please edit it.")
|
|
108
|
-
time.sleep(2)
|
|
109
|
-
with open(path, "r") as f:
|
|
110
|
-
return yaml.safe_load(f)
|
|
4
|
+
from hungerlib.addons import (
|
|
5
|
+
Snapshot,
|
|
6
|
+
snapSchedule,
|
|
7
|
+
waitForOnline,
|
|
8
|
+
validateAll,
|
|
9
|
+
runCountdownEvents
|
|
10
|
+
)
|
|
111
11
|
|
|
112
12
|
|
|
113
13
|
class ServerWatcher:
|
|
@@ -264,74 +164,3 @@ class ServerWatcher:
|
|
|
264
164
|
self.schedule_restart(self.cfg.high_gap_minutes)
|
|
265
165
|
|
|
266
166
|
self.restart_and_wait()
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
# -------------------------
|
|
271
|
-
# MAIN
|
|
272
|
-
# -------------------------
|
|
273
|
-
|
|
274
|
-
cfg = load_or_create_config()
|
|
275
|
-
|
|
276
|
-
panel = Panel(**cfg["panel"])
|
|
277
|
-
|
|
278
|
-
origin = GenericServer(
|
|
279
|
-
name="Origin",
|
|
280
|
-
panel=panel,
|
|
281
|
-
server_id=cfg["origin"]["server_id"]
|
|
282
|
-
)
|
|
283
|
-
|
|
284
|
-
srv = cfg["server"]
|
|
285
|
-
server = MinecraftServer(
|
|
286
|
-
name=srv["name"],
|
|
287
|
-
panel=panel,
|
|
288
|
-
server_id=srv["server_id"],
|
|
289
|
-
server_domain=srv["domain"],
|
|
290
|
-
server_port=srv["port"],
|
|
291
|
-
rcon_port=srv["rcon_port"],
|
|
292
|
-
rcon_password=srv["rcon_password"],
|
|
293
|
-
tpsCommand=srv["tps_command"]
|
|
294
|
-
)
|
|
295
|
-
|
|
296
|
-
log = HungerLogger(
|
|
297
|
-
name=f"ServerWatcher-{srv['name']}",
|
|
298
|
-
server=server,
|
|
299
|
-
log_path="/home/container/logs/",
|
|
300
|
-
console_backspaces=8
|
|
301
|
-
)
|
|
302
|
-
|
|
303
|
-
w = cfg["watcher"]
|
|
304
|
-
config = WatcherConfig(
|
|
305
|
-
restart_soon_schedule_id=w["restart_soon_schedule_id"],
|
|
306
|
-
origin_disable_schedule_id=w["origin_disable_schedule_id"],
|
|
307
|
-
|
|
308
|
-
ram_threshold=w["thresholds"]["ram"],
|
|
309
|
-
cpu_threshold=w["thresholds"]["cpu"],
|
|
310
|
-
uptime_hours_threshold=w["thresholds"]["uptime_hours"],
|
|
311
|
-
tps_threshold=w["thresholds"]["tps"],
|
|
312
|
-
|
|
313
|
-
weight_restart_soon=w["weights"]["restart_soon"],
|
|
314
|
-
weight_ram=w["weights"]["ram"],
|
|
315
|
-
weight_cpu=w["weights"]["cpu"],
|
|
316
|
-
weight_uptime=w["weights"]["uptime"],
|
|
317
|
-
weight_tps=w["weights"]["tps"],
|
|
318
|
-
weight_low_uptime=w["weights"]["low_uptime"],
|
|
319
|
-
weight_per_player=w["weights"]["per_player"],
|
|
320
|
-
|
|
321
|
-
low_gap_minutes=w["gaps"]["low"],
|
|
322
|
-
high_gap_minutes=w["gaps"]["high"],
|
|
323
|
-
|
|
324
|
-
restart_wait_seconds=w["restart"]["wait_seconds"],
|
|
325
|
-
restart_online_timeout=w["restart"]["online_timeout"],
|
|
326
|
-
restart_online_interval=w["restart"]["online_interval"],
|
|
327
|
-
)
|
|
328
|
-
|
|
329
|
-
messages = WatcherMessages(**cfg["messages"])
|
|
330
|
-
|
|
331
|
-
clearTerminal()
|
|
332
|
-
|
|
333
|
-
Watcher = ServerWatcher(server, origin, panel, log, config, messages)
|
|
334
|
-
|
|
335
|
-
while True:
|
|
336
|
-
Watcher.evaluate()
|
|
337
|
-
time.sleep(60)
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|