serverwatcher 5.21__tar.gz → 5.23__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-5.21/src/serverwatcher.egg-info → serverwatcher-5.23}/PKG-INFO +1 -1
- {serverwatcher-5.21 → serverwatcher-5.23}/pyproject.toml +1 -1
- {serverwatcher-5.21 → serverwatcher-5.23}/src/serverwatcher/configclasses/config.py +2 -2
- {serverwatcher-5.21 → serverwatcher-5.23}/src/serverwatcher/configclasses/messages.py +2 -2
- {serverwatcher-5.21 → serverwatcher-5.23}/src/serverwatcher/configclasses/watcher.py +1 -1
- {serverwatcher-5.21 → serverwatcher-5.23}/src/serverwatcher/watcher.py +74 -30
- {serverwatcher-5.21 → serverwatcher-5.23/src/serverwatcher.egg-info}/PKG-INFO +1 -1
- {serverwatcher-5.21 → serverwatcher-5.23}/LICENSE +0 -0
- {serverwatcher-5.21 → serverwatcher-5.23}/README.md +0 -0
- {serverwatcher-5.21 → serverwatcher-5.23}/setup.cfg +0 -0
- {serverwatcher-5.21 → serverwatcher-5.23}/src/serverwatcher/__init__.py +0 -0
- {serverwatcher-5.21 → serverwatcher-5.23}/src/serverwatcher/__main__.py +0 -0
- {serverwatcher-5.21 → serverwatcher-5.23}/src/serverwatcher/configclasses/__init__.py +0 -0
- {serverwatcher-5.21 → serverwatcher-5.23}/src/serverwatcher/defaultconfigs/config.yaml +0 -0
- {serverwatcher-5.21 → serverwatcher-5.23}/src/serverwatcher/defaultconfigs/messages.yaml +0 -0
- {serverwatcher-5.21 → serverwatcher-5.23}/src/serverwatcher/defaultconfigs/watcher.yaml +0 -0
- {serverwatcher-5.21 → serverwatcher-5.23}/src/serverwatcher/validator.py +0 -0
- {serverwatcher-5.21 → serverwatcher-5.23}/src/serverwatcher.egg-info/SOURCES.txt +0 -0
- {serverwatcher-5.21 → serverwatcher-5.23}/src/serverwatcher.egg-info/dependency_links.txt +0 -0
- {serverwatcher-5.21 → serverwatcher-5.23}/src/serverwatcher.egg-info/requires.txt +0 -0
- {serverwatcher-5.21 → serverwatcher-5.23}/src/serverwatcher.egg-info/top_level.txt +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
from
|
|
1
|
+
from mapres import datamap, syntax
|
|
2
2
|
|
|
3
|
-
@datamap(syntax=
|
|
3
|
+
@datamap(syntax=syntax.braces, mode='config')
|
|
4
4
|
class GlobalConfig:
|
|
5
5
|
__user_config_path__ = 'config/config.yaml'
|
|
6
6
|
__default_config_path__ = 'defaultconfigs/config.yaml'
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
from hungerlib import datamap,
|
|
1
|
+
from hungerlib import datamap, syntax
|
|
2
2
|
|
|
3
|
-
@datamap(syntax=
|
|
3
|
+
@datamap(syntax=syntax.braces, mode='config')
|
|
4
4
|
class MessagesConfig:
|
|
5
5
|
__user_config_path__ = 'config/messages.yaml'
|
|
6
6
|
__default_config_path__ = 'defaultconfigs/messages.yaml'
|
|
@@ -2,28 +2,25 @@ import os
|
|
|
2
2
|
import time
|
|
3
3
|
from zoneinfo import ZoneInfo
|
|
4
4
|
|
|
5
|
-
from hungerlib import servers, MessageRouter, loadConfig, utils
|
|
5
|
+
from hungerlib import servers, MessageRouter, loadConfig, utils
|
|
6
|
+
from mapres import MapResolver, maps
|
|
6
7
|
|
|
7
8
|
from serverwatcher.configclasses.config import GlobalConfig
|
|
8
9
|
from serverwatcher.configclasses.messages import MessagesConfig
|
|
9
10
|
from serverwatcher.configclasses.watcher import WatcherConfig
|
|
10
11
|
|
|
11
12
|
|
|
12
|
-
|
|
13
13
|
class ServerWatcher:
|
|
14
14
|
def __init__(self):
|
|
15
15
|
self.config = loadConfig(GlobalConfig)
|
|
16
16
|
self.messages = loadConfig(MessagesConfig)
|
|
17
17
|
self.watcherconfig = loadConfig(WatcherConfig)
|
|
18
18
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
self.config,
|
|
23
|
-
self.messages,
|
|
24
|
-
self.watcherconfig,
|
|
25
|
-
)
|
|
19
|
+
# resolver for internal mapping
|
|
20
|
+
self.resolver = MapResolver()
|
|
21
|
+
self.res = self.resolver.res
|
|
26
22
|
|
|
23
|
+
# panel + server
|
|
27
24
|
self.panel = servers.Panel(
|
|
28
25
|
name=self.config.panel_name,
|
|
29
26
|
url=self.config.panel_url,
|
|
@@ -41,18 +38,54 @@ class ServerWatcher:
|
|
|
41
38
|
tpsCommand=self.config.tps_command,
|
|
42
39
|
)
|
|
43
40
|
|
|
44
|
-
|
|
45
|
-
|
|
41
|
+
# logger name
|
|
42
|
+
logger_name = self.res(
|
|
43
|
+
self.config.logger_name,
|
|
44
|
+
server_name=self.config.server_name
|
|
45
|
+
)
|
|
46
|
+
|
|
47
|
+
# router using mapres
|
|
46
48
|
self.router = MessageRouter(
|
|
47
49
|
name=logger_name,
|
|
48
50
|
Servers=[self.server],
|
|
49
51
|
log_path=self.config.log_path,
|
|
50
52
|
|
|
51
|
-
origin_maps
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
53
|
+
origin_maps=[
|
|
54
|
+
maps.ascii_colors,
|
|
55
|
+
maps.time_tk(self.config.timezone),
|
|
56
|
+
self.config,
|
|
57
|
+
self.messages,
|
|
58
|
+
self.watcherconfig
|
|
59
|
+
],
|
|
60
|
+
|
|
61
|
+
destination_maps=[
|
|
62
|
+
maps.ascii_colors,
|
|
63
|
+
maps.time_tk(self.config.timezone),
|
|
64
|
+
self.config,
|
|
65
|
+
self.messages,
|
|
66
|
+
self.watcherconfig
|
|
67
|
+
],
|
|
68
|
+
|
|
69
|
+
broadcast_maps=[
|
|
70
|
+
maps.mc_colors,
|
|
71
|
+
maps.time_tk(self.config.timezone),
|
|
72
|
+
self.config,
|
|
73
|
+
self.messages,
|
|
74
|
+
self.watcherconfig
|
|
75
|
+
],
|
|
76
|
+
|
|
77
|
+
file_maps=[
|
|
78
|
+
maps.strip_colors,
|
|
79
|
+
maps.time_tk(self.config.timezone),
|
|
80
|
+
self.config,
|
|
81
|
+
self.messages,
|
|
82
|
+
self.watcherconfig
|
|
83
|
+
],
|
|
84
|
+
|
|
85
|
+
prefix_maps=[
|
|
86
|
+
maps.ascii_colors,
|
|
87
|
+
maps.time_tk(self.config.timezone)
|
|
88
|
+
],
|
|
56
89
|
|
|
57
90
|
info_prefix=self.config.info_prefix,
|
|
58
91
|
warn_prefix=self.config.warn_prefix,
|
|
@@ -84,7 +117,10 @@ class ServerWatcher:
|
|
|
84
117
|
self.router.error(self.messages.server_failed_restart)
|
|
85
118
|
|
|
86
119
|
def schedule_restart(self, minutes):
|
|
87
|
-
info = utils.snapSchedule(
|
|
120
|
+
info = utils.snapSchedule(
|
|
121
|
+
minimumMinutes=minutes,
|
|
122
|
+
snapMinutes=tuple(sorted(self.watcherconfig.snap_minutes))
|
|
123
|
+
)
|
|
88
124
|
scheduled = info["scheduled"]
|
|
89
125
|
|
|
90
126
|
local_time = scheduled.astimezone(self.tz)
|
|
@@ -92,34 +128,38 @@ class ServerWatcher:
|
|
|
92
128
|
|
|
93
129
|
self.router.broadcast(self.messages.broadcast_restart_at, time=time_str)
|
|
94
130
|
|
|
131
|
+
# minute callbacks
|
|
95
132
|
minute_callbacks = {
|
|
96
133
|
int(k.split("_")[1]): (
|
|
97
134
|
lambda raw=self.messages.as_map()[k]:
|
|
98
|
-
self.router.broadcast(
|
|
99
|
-
|
|
135
|
+
(self.router.broadcast(self.res(raw)),
|
|
136
|
+
self.router.origin(raw))
|
|
100
137
|
)
|
|
101
138
|
for k in self.messages.as_map()
|
|
102
139
|
if k.startswith("minute_")
|
|
103
140
|
}
|
|
104
141
|
|
|
142
|
+
# second callbacks
|
|
105
143
|
second_callbacks = {
|
|
106
144
|
int(k.split("_")[1]): (
|
|
107
145
|
lambda raw=self.messages.as_map()[k]:
|
|
108
|
-
self.router.broadcast(
|
|
109
|
-
|
|
146
|
+
(self.router.broadcast(self.res(raw)),
|
|
147
|
+
self.router.origin(raw))
|
|
110
148
|
)
|
|
111
149
|
for k in self.messages.as_map()
|
|
112
150
|
if k.startswith("second_")
|
|
113
151
|
}
|
|
114
152
|
|
|
115
|
-
utils.runCountdownEvents(
|
|
153
|
+
utils.runCountdownEvents(
|
|
154
|
+
target_time=scheduled,
|
|
155
|
+
minute_callbacks=minute_callbacks,
|
|
156
|
+
second_callbacks=second_callbacks
|
|
157
|
+
)
|
|
116
158
|
|
|
117
159
|
def evaluate(self):
|
|
118
|
-
# Lets Pterodactyl know the server is online, then clears terminal and uses user-defined startup key
|
|
119
160
|
self.router.info("ServerWatcher is running!")
|
|
120
161
|
utils.clearTerminal()
|
|
121
162
|
|
|
122
|
-
# Configurable start message
|
|
123
163
|
self.router.info(self.messages.startup)
|
|
124
164
|
|
|
125
165
|
if not utils.validateAll(self.panel, self.server):
|
|
@@ -135,31 +175,35 @@ class ServerWatcher:
|
|
|
135
175
|
no_restart_reasons = []
|
|
136
176
|
|
|
137
177
|
if snap.ram >= self.watcherconfig.threshold_ram:
|
|
138
|
-
restart_reasons.append(
|
|
178
|
+
restart_reasons.append(
|
|
179
|
+
self.res(self.messages.reason_ram, ram=snap.ram, threshold=self.watcherconfig.threshold_ram)
|
|
180
|
+
)
|
|
139
181
|
pro += int(round(snap.ram, 0) - (self.watcherconfig.threshold_ram - 1))
|
|
140
182
|
|
|
141
183
|
if snap.cpu >= self.watcherconfig.threshold_cpu:
|
|
142
|
-
restart_reasons.append(
|
|
184
|
+
restart_reasons.append(
|
|
185
|
+
self.res(self.messages.reason_cpu, cpu=snap.cpu, threshold=self.watcherconfig.threshold_cpu)
|
|
186
|
+
)
|
|
143
187
|
pro += self.watcherconfig.weight_cpu
|
|
144
188
|
|
|
145
189
|
if snap.uptime // 3600 >= self.watcherconfig.threshold_uptime:
|
|
146
190
|
restart_reasons.append(
|
|
147
|
-
|
|
191
|
+
self.res(self.messages.reason_uptime, uptime=snap.uptime_formatted, threshold=self.watcherconfig.threshold_uptime)
|
|
148
192
|
)
|
|
149
193
|
pro += self.watcherconfig.weight_uptime
|
|
150
194
|
|
|
151
195
|
if (snap.tps if snap.tps is not None else 20) <= self.watcherconfig.threshold_tps:
|
|
152
|
-
restart_reasons.append(
|
|
196
|
+
restart_reasons.append(self.res(self.messages.reason_tps, tps=snap.tps, threshold=self.watcherconfig.threshold_tps))
|
|
153
197
|
pro += self.watcherconfig.weight_tps
|
|
154
198
|
|
|
155
199
|
if snap.uptime // 60 < self.watcherconfig.threshold_min_uptime:
|
|
156
|
-
no_restart_reasons.append(
|
|
200
|
+
no_restart_reasons.append(self.res(self.messages.reason_low_uptime, uptime=snap.uptime_formatted))
|
|
157
201
|
anti += self.watcherconfig.weight_low_uptime
|
|
158
202
|
|
|
159
203
|
if snap.players > 0:
|
|
160
204
|
verb = "are" if snap.players != 1 else "is"
|
|
161
205
|
plural = "players" if snap.players != 1 else "player"
|
|
162
|
-
no_restart_reasons.append(
|
|
206
|
+
no_restart_reasons.append(self.res(self.messages.reason_players, verb=verb, count=snap.players, plural=plural))
|
|
163
207
|
anti += snap.players * self.watcherconfig.weight_per_player
|
|
164
208
|
|
|
165
209
|
if restart_reasons:
|
|
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
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|