serverwatcher 5.8.dev11__tar.gz → 5.8.dev13__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.8.dev11/src/serverwatcher.egg-info → serverwatcher-5.8.dev13}/PKG-INFO +1 -1
- {serverwatcher-5.8.dev11 → serverwatcher-5.8.dev13}/pyproject.toml +1 -1
- {serverwatcher-5.8.dev11 → serverwatcher-5.8.dev13}/src/serverwatcher/configclasses/config.py +4 -4
- serverwatcher-5.8.dev13/src/serverwatcher/configclasses/messages.py +61 -0
- {serverwatcher-5.8.dev11 → serverwatcher-5.8.dev13}/src/serverwatcher/configclasses/watcher.py +4 -2
- {serverwatcher-5.8.dev11 → serverwatcher-5.8.dev13}/src/serverwatcher/defaultconfigs/config.yaml +0 -1
- {serverwatcher-5.8.dev11 → serverwatcher-5.8.dev13}/src/serverwatcher/defaultconfigs/messages.yaml +2 -20
- {serverwatcher-5.8.dev11 → serverwatcher-5.8.dev13}/src/serverwatcher/defaultconfigs/watcher.yaml +2 -0
- {serverwatcher-5.8.dev11 → serverwatcher-5.8.dev13}/src/serverwatcher/validator.py +2 -2
- {serverwatcher-5.8.dev11 → serverwatcher-5.8.dev13}/src/serverwatcher/watcher.py +29 -76
- {serverwatcher-5.8.dev11 → serverwatcher-5.8.dev13/src/serverwatcher.egg-info}/PKG-INFO +1 -1
- serverwatcher-5.8.dev11/src/serverwatcher/configclasses/messages.py +0 -65
- {serverwatcher-5.8.dev11 → serverwatcher-5.8.dev13}/LICENSE +0 -0
- {serverwatcher-5.8.dev11 → serverwatcher-5.8.dev13}/README.md +0 -0
- {serverwatcher-5.8.dev11 → serverwatcher-5.8.dev13}/setup.cfg +0 -0
- {serverwatcher-5.8.dev11 → serverwatcher-5.8.dev13}/src/serverwatcher/__init__.py +0 -0
- {serverwatcher-5.8.dev11 → serverwatcher-5.8.dev13}/src/serverwatcher/configclasses/__init__.py +0 -0
- {serverwatcher-5.8.dev11 → serverwatcher-5.8.dev13}/src/serverwatcher.egg-info/SOURCES.txt +0 -0
- {serverwatcher-5.8.dev11 → serverwatcher-5.8.dev13}/src/serverwatcher.egg-info/dependency_links.txt +0 -0
- {serverwatcher-5.8.dev11 → serverwatcher-5.8.dev13}/src/serverwatcher.egg-info/requires.txt +0 -0
- {serverwatcher-5.8.dev11 → serverwatcher-5.8.dev13}/src/serverwatcher.egg-info/top_level.txt +0 -0
{serverwatcher-5.8.dev11 → serverwatcher-5.8.dev13}/src/serverwatcher/configclasses/config.py
RENAMED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
from dataclasses import
|
|
1
|
+
from dataclasses import field
|
|
2
|
+
from hungerlib.datamap import datamap, Syntax
|
|
2
3
|
|
|
3
4
|
def yaml_key(path: str, default=None):
|
|
4
5
|
return field(default=default, metadata={"yaml_key": path})
|
|
5
6
|
|
|
6
|
-
@
|
|
7
|
+
@datamap(syntax=Syntax.braces)
|
|
7
8
|
class GlobalConfig:
|
|
8
|
-
watch_interval: int = yaml_key("watch_interval")
|
|
9
9
|
timezone: str = yaml_key("timezone")
|
|
10
10
|
|
|
11
11
|
panel_name: str = yaml_key("panel.name")
|
|
@@ -28,4 +28,4 @@ class GlobalConfig:
|
|
|
28
28
|
log_path: str = yaml_key("logger.log_path")
|
|
29
29
|
|
|
30
30
|
console_backspaces: int = yaml_key("terminal.backspaces")
|
|
31
|
-
clear_terminal: bool = yaml_key("terminal.enable_clearing")
|
|
31
|
+
clear_terminal: bool = yaml_key("terminal.enable_clearing")
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
from dataclasses import field
|
|
2
|
+
from hungerlib.datamap import datamap, Syntax
|
|
3
|
+
|
|
4
|
+
def yaml_key(path: str, default=None):
|
|
5
|
+
return field(default=default, metadata={"yaml_key": path})
|
|
6
|
+
|
|
7
|
+
@datamap(syntax=Syntax.braces)
|
|
8
|
+
class MessagesConfig:
|
|
9
|
+
prefix: str = yaml_key("prefix", "<aqua>[Server Watcher]")
|
|
10
|
+
bullet: str = yaml_key("bullet")
|
|
11
|
+
|
|
12
|
+
broadcast_restart_at: str = yaml_key("broadcast_restart_at")
|
|
13
|
+
|
|
14
|
+
minute_120: str = yaml_key("broadcast_minutes.120", "{prefix} Restart in 2 hours!")
|
|
15
|
+
minute_60: str = yaml_key("broadcast_minutes.60", "{prefix} Restart in 1 hour!")
|
|
16
|
+
minute_45: str = yaml_key("broadcast_minutes.45", "{prefix} Restart in 45 minutes!")
|
|
17
|
+
minute_30: str = yaml_key("broadcast_minutes.30", "{prefix} Restart in 30 minutes!")
|
|
18
|
+
minute_15: str = yaml_key("broadcast_minutes.15", "{prefix} Restart in 15 minutes!")
|
|
19
|
+
minute_5: str = yaml_key("broadcast_minutes.5", "{prefix} Restart in 5 minutes!")
|
|
20
|
+
minute_1: str = yaml_key("broadcast_minutes.1", "{prefix} Restart in 1 minute!")
|
|
21
|
+
|
|
22
|
+
second_10: str = yaml_key("broadcast_seconds.10", "{prefix} Restart in 10 seconds!")
|
|
23
|
+
second_9: str = yaml_key("broadcast_seconds.9", "{prefix} Restart in 9 seconds!")
|
|
24
|
+
second_8: str = yaml_key("broadcast_seconds.8", "{prefix} Restart in 8 seconds!")
|
|
25
|
+
second_7: str = yaml_key("broadcast_seconds.7", "{prefix} Restart in 7 seconds!")
|
|
26
|
+
second_6: str = yaml_key("broadcast_seconds.6", "{prefix} Restart in 6 seconds!")
|
|
27
|
+
second_5: str = yaml_key("broadcast_seconds.5", "{prefix} Restart in 5 seconds!")
|
|
28
|
+
second_4: str = yaml_key("broadcast_seconds.4", "{prefix} Restart in 4 seconds!")
|
|
29
|
+
second_3: str = yaml_key("broadcast_seconds.3", "{prefix} Restart in 3 seconds!")
|
|
30
|
+
second_2: str = yaml_key("broadcast_seconds.2", "{prefix} Restart in 2 seconds!")
|
|
31
|
+
second_1: str = yaml_key("broadcast_seconds.1", "{prefix} Restart in 1 second!")
|
|
32
|
+
|
|
33
|
+
startup: str = yaml_key("logging.startup")
|
|
34
|
+
status_check: str = yaml_key("logging.status_check")
|
|
35
|
+
validation_fail: str = yaml_key("logging.validation_fail")
|
|
36
|
+
validation_ok: str = yaml_key("logging.validation_ok")
|
|
37
|
+
shutdown: str = yaml_key("logging.shutdown")
|
|
38
|
+
immediate_restart: str = yaml_key("logging.immediate_restart")
|
|
39
|
+
no_restart: str = yaml_key("logging.no_restart")
|
|
40
|
+
scheduled: str = yaml_key("logging.scheduled")
|
|
41
|
+
gap_low: str = yaml_key("logging.gap_low")
|
|
42
|
+
gap_high: str = yaml_key("logging.gap_high")
|
|
43
|
+
|
|
44
|
+
pro_restart_splash: str = yaml_key("reasons.pro_splash")
|
|
45
|
+
anti_restart_splash: str = yaml_key("reasons.anti_splash")
|
|
46
|
+
|
|
47
|
+
reason_restart_soon: str = yaml_key("reasons.restart_soon")
|
|
48
|
+
reason_ram: str = yaml_key("reasons.ram")
|
|
49
|
+
reason_cpu: str = yaml_key("reasons.cpu")
|
|
50
|
+
reason_uptime: str = yaml_key("reasons.uptime")
|
|
51
|
+
reason_tps: str = yaml_key("reasons.tps")
|
|
52
|
+
reason_low_uptime: str = yaml_key("reasons.low_uptime")
|
|
53
|
+
reason_players: str = yaml_key("reasons.players")
|
|
54
|
+
|
|
55
|
+
pro_restart_number: str = yaml_key("reasons.pro_restart_number")
|
|
56
|
+
anti_restart_number: str = yaml_key("reasons.anti_restart_number")
|
|
57
|
+
|
|
58
|
+
restart_action_sent: str = yaml_key("restarts.restart_action_sent")
|
|
59
|
+
server_back_online: str = yaml_key("restarts.back_online")
|
|
60
|
+
server_back_online_broadcast: str = yaml_key("restarts.back_online_broadcast")
|
|
61
|
+
server_failed_restart: str = yaml_key("restarts.failed_restart")
|
{serverwatcher-5.8.dev11 → serverwatcher-5.8.dev13}/src/serverwatcher/configclasses/watcher.py
RENAMED
|
@@ -1,10 +1,12 @@
|
|
|
1
|
-
from dataclasses import
|
|
1
|
+
from dataclasses import field
|
|
2
|
+
from hungerlib.datamap import datamap, Syntax
|
|
2
3
|
|
|
3
4
|
def yaml_key(path: str, default=None):
|
|
4
5
|
return field(default=default, metadata={"yaml_key": path})
|
|
5
6
|
|
|
6
|
-
@
|
|
7
|
+
@datamap(syntax=Syntax.braces)
|
|
7
8
|
class WatcherConfig:
|
|
9
|
+
watch_interval: int = yaml_key("watch_interval")
|
|
8
10
|
schedule_control: bool = yaml_key("schedule_control.enabled")
|
|
9
11
|
restart_soon_id: int = yaml_key("schedule_control.restart_soon_id")
|
|
10
12
|
|
{serverwatcher-5.8.dev11 → serverwatcher-5.8.dev13}/src/serverwatcher/defaultconfigs/messages.yaml
RENAMED
|
@@ -3,26 +3,8 @@ bullet: '-'
|
|
|
3
3
|
|
|
4
4
|
broadcast_restart_at: '{prefix} The server will restart at {time} CDT.'
|
|
5
5
|
|
|
6
|
-
broadcast_minutes:
|
|
7
|
-
|
|
8
|
-
'60': '{prefix} Restart in 1 hour!'
|
|
9
|
-
'45': '{prefix} Restart in 45 minutes!'
|
|
10
|
-
'30': '{prefix} Restart in 30 minutes!'
|
|
11
|
-
'15': '{prefix} Restart in 15 minutes!'
|
|
12
|
-
'5': '{prefix} Restart in 5 minutes!'
|
|
13
|
-
'1': '{prefix} Restart in 1 minute!'
|
|
14
|
-
|
|
15
|
-
broadcast_seconds:
|
|
16
|
-
'10': '{prefix} Restart in 10 seconds!'
|
|
17
|
-
'9': '{prefix} Restart in 9 seconds!'
|
|
18
|
-
'8': '{prefix} Restart in 8 seconds!'
|
|
19
|
-
'7': '{prefix} Restart in 7 seconds!'
|
|
20
|
-
'6': '{prefix} Restart in 6 seconds!'
|
|
21
|
-
'5': '{prefix} Restart in 5 seconds!'
|
|
22
|
-
'4': '{prefix} Restart in 4 seconds!'
|
|
23
|
-
'3': '{prefix} Restart in 3 seconds!'
|
|
24
|
-
'2': '{prefix} Restart in 2 seconds!'
|
|
25
|
-
'1': '{prefix} Restart in 1 second!'
|
|
6
|
+
broadcast_minutes: {}
|
|
7
|
+
broadcast_seconds: {}
|
|
26
8
|
|
|
27
9
|
logging:
|
|
28
10
|
startup: 'ServerWatcher is running!'
|
|
@@ -50,8 +50,8 @@ def validate_dataclass(config_obj, schema, errors):
|
|
|
50
50
|
|
|
51
51
|
|
|
52
52
|
def validate_global_config(config, errors):
|
|
53
|
-
if
|
|
54
|
-
errors.append(f"watch_interval: must be >= 1 (got {
|
|
53
|
+
if watcher.watch_interval < 1:
|
|
54
|
+
errors.append(f"watch_interval: must be >= 1 (got {watcher.watch_interval})")
|
|
55
55
|
|
|
56
56
|
if config.server_port <= 0 or config.server_port > 65535:
|
|
57
57
|
errors.append(f"server_port: must be 1–65535 (got {config.server_port})")
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import os
|
|
2
2
|
import time
|
|
3
|
-
import re
|
|
4
3
|
from zoneinfo import ZoneInfo
|
|
5
4
|
|
|
6
|
-
from hungerlib import Panel, MessageRouter
|
|
5
|
+
from hungerlib import Panel, MessageRouter, mapit, set_default_maps
|
|
6
|
+
from hungerlib.datamaps import ASCII_COLOR_MAP, MC_COLOR_MAP
|
|
7
7
|
from hungerlib.servers import MinecraftServer, GenericServer
|
|
8
8
|
from hungerlib.addons import (
|
|
9
9
|
clearTerminal,
|
|
@@ -18,22 +18,10 @@ from hungerlib.addons import (
|
|
|
18
18
|
from serverwatcher.configclasses.config import GlobalConfig
|
|
19
19
|
from serverwatcher.configclasses.messages import MessagesConfig
|
|
20
20
|
from serverwatcher.configclasses.watcher import WatcherConfig
|
|
21
|
-
|
|
22
21
|
from serverwatcher.validator import validate_all
|
|
23
22
|
|
|
24
23
|
validate_all()
|
|
25
24
|
|
|
26
|
-
_T_EXPR = re.compile(r"{([^{}]+)}")
|
|
27
|
-
|
|
28
|
-
def t_eval(template: str, /, **ctx):
|
|
29
|
-
# evaluate inline expressions inside message templates
|
|
30
|
-
def repl(match):
|
|
31
|
-
expr = match.group(1).strip()
|
|
32
|
-
try:
|
|
33
|
-
return str(eval(expr, {}, ctx))
|
|
34
|
-
except Exception as e:
|
|
35
|
-
return f"<err:{e}>"
|
|
36
|
-
return _T_EXPR.sub(repl, template)
|
|
37
25
|
|
|
38
26
|
class ServerWatcher:
|
|
39
27
|
def __init__(self):
|
|
@@ -55,6 +43,13 @@ class ServerWatcher:
|
|
|
55
43
|
WatcherConfig
|
|
56
44
|
)
|
|
57
45
|
|
|
46
|
+
set_default_maps(
|
|
47
|
+
ASCII_COLOR_MAP,
|
|
48
|
+
self.config,
|
|
49
|
+
self.messages,
|
|
50
|
+
self.watcherconfig
|
|
51
|
+
)
|
|
52
|
+
|
|
58
53
|
self.panel = Panel(
|
|
59
54
|
name=self.config.panel_name,
|
|
60
55
|
url=self.config.panel_url,
|
|
@@ -78,40 +73,30 @@ class ServerWatcher:
|
|
|
78
73
|
tpsCommand=self.config.tps_command,
|
|
79
74
|
)
|
|
80
75
|
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
server_name=self.config.server_name
|
|
84
|
-
)
|
|
85
|
-
|
|
86
|
-
# initialize message router
|
|
76
|
+
logger_name = mapit(self.config.logger_name, server_name=self.config.server_name)
|
|
77
|
+
|
|
87
78
|
self.router = MessageRouter(
|
|
88
79
|
name=logger_name,
|
|
89
80
|
server=self.server,
|
|
90
81
|
log_path=self.config.log_path,
|
|
91
|
-
formatter=self.
|
|
82
|
+
formatter=self._fmt,
|
|
92
83
|
console_backspaces=self.config.console_backspaces,
|
|
93
84
|
)
|
|
94
85
|
|
|
95
|
-
# timezone for scheduling
|
|
96
86
|
self.tz = ZoneInfo(self.config.timezone)
|
|
97
87
|
|
|
98
|
-
def
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
}
|
|
103
|
-
for key, value in simple.items():
|
|
104
|
-
template = template.replace(f"{{{key}}}", value)
|
|
105
|
-
return t_eval(template, self=self, **fmt)
|
|
106
|
-
|
|
107
|
-
def say(self, template, level="info", **fmt):
|
|
88
|
+
def _fmt(self, template: str, **ctx):
|
|
89
|
+
return mapit(template, **ctx)
|
|
90
|
+
|
|
91
|
+
def say(self, template, level="info", **ctx):
|
|
108
92
|
if not template:
|
|
109
93
|
return
|
|
94
|
+
msg = mapit(template, **ctx)
|
|
110
95
|
self.router.say(
|
|
111
|
-
|
|
96
|
+
msg,
|
|
112
97
|
level=level,
|
|
113
98
|
log=self.config.enable_logging,
|
|
114
|
-
**
|
|
99
|
+
**ctx
|
|
115
100
|
)
|
|
116
101
|
|
|
117
102
|
def shutdown(self):
|
|
@@ -119,16 +104,13 @@ class ServerWatcher:
|
|
|
119
104
|
raise SystemExit
|
|
120
105
|
|
|
121
106
|
def restart_and_wait(self):
|
|
122
|
-
# disable schedule if configured
|
|
123
107
|
if self.watcherconfig.schedule_control:
|
|
124
108
|
self.origin.disableSchedule(self.watcherconfig.restart_soon_id)
|
|
125
109
|
|
|
126
|
-
# send restart command
|
|
127
110
|
self.server.restart()
|
|
128
111
|
self.say(self.messages.restart_action_sent)
|
|
129
112
|
time.sleep(self.watcherconfig.restart_wait_seconds)
|
|
130
113
|
|
|
131
|
-
# check server status
|
|
132
114
|
self.say(self.messages.status_check, level="warn")
|
|
133
115
|
alive = waitForOnline(
|
|
134
116
|
self.server,
|
|
@@ -136,7 +118,6 @@ class ServerWatcher:
|
|
|
136
118
|
interval=self.watcherconfig.restart_online_interval,
|
|
137
119
|
)
|
|
138
120
|
|
|
139
|
-
# handle restart result
|
|
140
121
|
if alive:
|
|
141
122
|
self.say(self.messages.server_back_online)
|
|
142
123
|
self.say(self.messages.server_back_online_broadcast, broadcast=True)
|
|
@@ -144,38 +125,32 @@ class ServerWatcher:
|
|
|
144
125
|
self.say(self.messages.server_failed_restart, level="error")
|
|
145
126
|
|
|
146
127
|
def schedule_restart(self, minutes):
|
|
147
|
-
# compute scheduled restart time
|
|
148
128
|
info = snapSchedule(minimumMinutes=minutes)
|
|
149
129
|
scheduled = info["scheduled"]
|
|
150
130
|
|
|
151
|
-
# format local time
|
|
152
131
|
local_time = scheduled.astimezone(self.tz)
|
|
153
132
|
time_str = local_time.strftime("%I:%M %p")
|
|
154
133
|
|
|
155
|
-
|
|
156
|
-
self.router.broadcast(self.fmt(self.messages.broadcast_restart_at, time=time_str))
|
|
134
|
+
self.router.broadcast(mapit(self.messages.broadcast_restart_at, time=time_str))
|
|
157
135
|
|
|
158
|
-
# build minute callbacks
|
|
159
136
|
minute_callbacks = {
|
|
160
137
|
int(k.split("_")[1]): (
|
|
161
|
-
lambda msg=
|
|
138
|
+
lambda msg=mapit(getattr(self.messages, k)):
|
|
162
139
|
self.router.broadcast(msg)
|
|
163
140
|
)
|
|
164
141
|
for k in vars(self.messages)
|
|
165
142
|
if k.startswith("minute_")
|
|
166
143
|
}
|
|
167
144
|
|
|
168
|
-
# build second callbacks
|
|
169
145
|
second_callbacks = {
|
|
170
146
|
int(k.split("_")[1]): (
|
|
171
|
-
lambda msg=
|
|
147
|
+
lambda msg=mapit(getattr(self.messages, k)):
|
|
172
148
|
self.router.broadcast(msg)
|
|
173
149
|
)
|
|
174
150
|
for k in vars(self.messages)
|
|
175
151
|
if k.startswith("second_")
|
|
176
152
|
}
|
|
177
153
|
|
|
178
|
-
# run countdown events
|
|
179
154
|
runCountdownEvents(
|
|
180
155
|
target_time=scheduled,
|
|
181
156
|
minute_callbacks=minute_callbacks,
|
|
@@ -183,98 +158,78 @@ class ServerWatcher:
|
|
|
183
158
|
)
|
|
184
159
|
|
|
185
160
|
def evaluate(self):
|
|
186
|
-
# announce evaluation start
|
|
187
161
|
self.say(self.messages.startup)
|
|
188
162
|
|
|
189
|
-
# validate panel and server
|
|
190
163
|
if not validateAll(self.panel, self.server):
|
|
191
164
|
self.say(self.messages.validation_fail, level="error")
|
|
192
165
|
self.shutdown()
|
|
193
166
|
|
|
194
|
-
# refresh server state
|
|
195
167
|
self.server.refresh()
|
|
196
168
|
snap = Snapshot(self.server, 2, True)
|
|
197
169
|
|
|
198
|
-
# scoring variables
|
|
199
170
|
pro = 0
|
|
200
171
|
anti = 0
|
|
201
172
|
restart_reasons = []
|
|
202
173
|
no_restart_reasons = []
|
|
203
174
|
|
|
204
|
-
# check schedule flag
|
|
205
175
|
if self.watcherconfig.schedule_control and self.server.getSchedule(self.watcherconfig.restart_soon_id)["is_active"]:
|
|
206
176
|
restart_reasons.append(self.messages.reason_restart_soon)
|
|
207
177
|
pro += self.watcherconfig.weight_restart_soon
|
|
208
178
|
|
|
209
|
-
# check RAM threshold
|
|
210
179
|
if snap.ram >= self.watcherconfig.threshold_ram:
|
|
211
|
-
restart_reasons.append(
|
|
180
|
+
restart_reasons.append(mapit(self.messages.reason_ram, ram=snap.ram, threshold=self.watcherconfig.threshold_ram))
|
|
212
181
|
pro += int(round(snap.ram, 0) - (self.watcherconfig.threshold_ram - 1))
|
|
213
182
|
|
|
214
|
-
# check CPU threshold
|
|
215
183
|
if snap.cpu >= self.watcherconfig.threshold_cpu:
|
|
216
|
-
restart_reasons.append(
|
|
184
|
+
restart_reasons.append(mapit(self.messages.reason_cpu, cpu=snap.cpu, threshold=self.watcherconfig.threshold_cpu))
|
|
217
185
|
pro += self.watcherconfig.weight_cpu
|
|
218
186
|
|
|
219
|
-
# check uptime threshold
|
|
220
187
|
if snap.uptime // 3600 >= self.watcherconfig.threshold_uptime:
|
|
221
188
|
restart_reasons.append(
|
|
222
|
-
|
|
223
|
-
threshold=self.watcherconfig.threshold_uptime)
|
|
189
|
+
mapit(self.messages.reason_uptime, uptime=snap.uptime_formatted, threshold=self.watcherconfig.threshold_uptime)
|
|
224
190
|
)
|
|
225
191
|
pro += self.watcherconfig.weight_uptime
|
|
226
192
|
|
|
227
|
-
# check TPS threshold
|
|
228
193
|
if (snap.tps if snap.tps is not None else 20) <= self.watcherconfig.threshold_tps:
|
|
229
|
-
restart_reasons.append(
|
|
194
|
+
restart_reasons.append(mapit(self.messages.reason_tps, tps=snap.tps, threshold=self.watcherconfig.threshold_tps))
|
|
230
195
|
pro += self.watcherconfig.weight_tps
|
|
231
196
|
|
|
232
|
-
# check low uptime penalty
|
|
233
197
|
if snap.uptime // 60 < 30:
|
|
234
|
-
no_restart_reasons.append(
|
|
198
|
+
no_restart_reasons.append(mapit(self.messages.reason_low_uptime, uptime=snap.uptime_formatted))
|
|
235
199
|
anti += self.watcherconfig.weight_low_uptime
|
|
236
200
|
|
|
237
|
-
# check player count penalty
|
|
238
201
|
if snap.players > 0:
|
|
239
202
|
verb = "are" if snap.players != 1 else "is"
|
|
240
203
|
plural = "players" if snap.players != 1 else "player"
|
|
241
|
-
no_restart_reasons.append(
|
|
204
|
+
no_restart_reasons.append(mapit(self.messages.reason_players, verb=verb, count=snap.players, plural=plural))
|
|
242
205
|
anti += snap.players * self.watcherconfig.weight_per_player
|
|
243
206
|
|
|
244
|
-
# output pro-restart reasons
|
|
245
207
|
if restart_reasons:
|
|
246
208
|
self.say(self.messages.pro_restart_splash, level="warn")
|
|
247
209
|
for r in restart_reasons:
|
|
248
210
|
self.say(f"{self.messages.bullet} {r}", level="warn")
|
|
249
211
|
|
|
250
|
-
# output anti-restart reasons
|
|
251
212
|
if no_restart_reasons:
|
|
252
213
|
self.say(self.messages.anti_restart_splash, level="warn")
|
|
253
214
|
for r in no_restart_reasons:
|
|
254
215
|
self.say(f"{self.messages.bullet} {r}", level="warn")
|
|
255
216
|
|
|
256
|
-
# output scores
|
|
257
217
|
self.say(f"{self.messages.pro_restart_number} {pro}", level="warn")
|
|
258
218
|
self.say(f"{self.messages.anti_restart_number} {anti}", level="warn")
|
|
259
219
|
|
|
260
|
-
# compute gap
|
|
261
220
|
gap = abs(pro - anti)
|
|
262
221
|
|
|
263
|
-
# no restart case
|
|
264
222
|
if pro == 0:
|
|
265
223
|
self.say(self.messages.no_restart)
|
|
266
224
|
return
|
|
267
225
|
|
|
268
|
-
# immediate restart case
|
|
269
226
|
if pro > anti and snap.players == 0:
|
|
270
227
|
self.say(self.messages.immediate_restart)
|
|
271
228
|
self.restart_and_wait()
|
|
272
229
|
return
|
|
273
230
|
|
|
274
|
-
# scheduled restart case
|
|
275
231
|
self.say(self.messages.scheduled)
|
|
276
232
|
|
|
277
|
-
# choose schedule window
|
|
278
233
|
if gap <= 2:
|
|
279
234
|
self.say(self.messages.gap_low, level="warn", gap=gap)
|
|
280
235
|
self.schedule_restart(self.watcherconfig.low_gap_minutes)
|
|
@@ -282,10 +237,8 @@ class ServerWatcher:
|
|
|
282
237
|
self.say(self.messages.gap_high, level="warn", gap=gap)
|
|
283
238
|
self.schedule_restart(self.watcherconfig.high_gap_minutes)
|
|
284
239
|
|
|
285
|
-
# perform restart
|
|
286
240
|
self.restart_and_wait()
|
|
287
241
|
|
|
288
|
-
# main loop
|
|
289
242
|
def run(self):
|
|
290
243
|
if self.config.clear_terminal:
|
|
291
244
|
clearTerminal()
|
|
@@ -293,4 +246,4 @@ class ServerWatcher:
|
|
|
293
246
|
if self.config.clear_terminal:
|
|
294
247
|
clearTerminal()
|
|
295
248
|
self.evaluate()
|
|
296
|
-
time.sleep(self.
|
|
249
|
+
time.sleep(self.watcher.watch_interval)
|
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
from dataclasses import dataclass, field
|
|
2
|
-
|
|
3
|
-
def yaml_key(path: str, default=None):
|
|
4
|
-
return field(default=default, metadata={"yaml_key": path})
|
|
5
|
-
|
|
6
|
-
@dataclass
|
|
7
|
-
class MessagesConfig:
|
|
8
|
-
prefix: str = yaml_key("prefix", default="<aqua>[Server Watcher]")
|
|
9
|
-
bullet: str = yaml_key("bullet")
|
|
10
|
-
|
|
11
|
-
broadcast_restart_at: str = yaml_key("broadcast_restart_at")
|
|
12
|
-
|
|
13
|
-
# minute messages
|
|
14
|
-
minute_120: str = yaml_key("broadcast_minutes.120", default="{prefix} Restart in 2 hours!")
|
|
15
|
-
minute_60: str = yaml_key("broadcast_minutes.60", default="{prefix} Restart in 1 hour!")
|
|
16
|
-
minute_45: str = yaml_key("broadcast_minutes.45", default="{prefix} Restart in 45 minutes!")
|
|
17
|
-
minute_30: str = yaml_key("broadcast_minutes.30", default="{prefix} Restart in 30 minutes!")
|
|
18
|
-
minute_15: str = yaml_key("broadcast_minutes.15", default="{prefix} Restart in 15 minutes!")
|
|
19
|
-
minute_5: str = yaml_key("broadcast_minutes.5", default="{prefix} Restart in 5 minutes!")
|
|
20
|
-
minute_1: str = yaml_key("broadcast_minutes.1", default="{prefix} Restart in 1 minute!")
|
|
21
|
-
|
|
22
|
-
# second messages
|
|
23
|
-
second_10: str = yaml_key("broadcast_seconds.10", default="{prefix} Restart in 10 seconds!")
|
|
24
|
-
second_9: str = yaml_key("broadcast_seconds.9", default="{prefix} Restart in 9 seconds!")
|
|
25
|
-
second_8: str = yaml_key("broadcast_seconds.8", default="{prefix} Restart in 8 seconds!")
|
|
26
|
-
second_7: str = yaml_key("broadcast_seconds.7", default="{prefix} Restart in 7 seconds!")
|
|
27
|
-
second_6: str = yaml_key("broadcast_seconds.6", default="{prefix} Restart in 6 seconds!")
|
|
28
|
-
second_5: str = yaml_key("broadcast_seconds.5", default="{prefix} Restart in 5 seconds!")
|
|
29
|
-
second_4: str = yaml_key("broadcast_seconds.4", default="{prefix} Restart in 4 seconds!")
|
|
30
|
-
second_3: str = yaml_key("broadcast_seconds.3", default="{prefix} Restart in 3 seconds!")
|
|
31
|
-
second_2: str = yaml_key("broadcast_seconds.2", default="{prefix} Restart in 2 seconds!")
|
|
32
|
-
second_1: str = yaml_key("broadcast_seconds.1", default="{prefix} Restart in 1 second!")
|
|
33
|
-
|
|
34
|
-
# logging
|
|
35
|
-
startup: str = yaml_key("logging.startup")
|
|
36
|
-
status_check: str = yaml_key("logging.status_check")
|
|
37
|
-
validation_fail: str = yaml_key("logging.validation_fail")
|
|
38
|
-
validation_ok: str = yaml_key("logging.validation_ok")
|
|
39
|
-
shutdown: str = yaml_key("logging.shutdown")
|
|
40
|
-
immediate_restart: str = yaml_key("logging.immediate_restart")
|
|
41
|
-
no_restart: str = yaml_key("logging.no_restart")
|
|
42
|
-
scheduled: str = yaml_key("logging.scheduled")
|
|
43
|
-
gap_low: str = yaml_key("logging.gap_low")
|
|
44
|
-
gap_high: str = yaml_key("logging.gap_high")
|
|
45
|
-
|
|
46
|
-
# reasons
|
|
47
|
-
pro_restart_splash: str = yaml_key("reasons.pro_splash")
|
|
48
|
-
anti_restart_splash: str = yaml_key("reasons.anti_splash")
|
|
49
|
-
|
|
50
|
-
reason_restart_soon: str = yaml_key("reasons.restart_soon")
|
|
51
|
-
reason_ram: str = yaml_key("reasons.ram")
|
|
52
|
-
reason_cpu: str = yaml_key("reasons.cpu")
|
|
53
|
-
reason_uptime: str = yaml_key("reasons.uptime")
|
|
54
|
-
reason_tps: str = yaml_key("reasons.tps")
|
|
55
|
-
reason_low_uptime: str = yaml_key("reasons.low_uptime")
|
|
56
|
-
reason_players: str = yaml_key("reasons.players")
|
|
57
|
-
|
|
58
|
-
pro_restart_number: str = yaml_key("reasons.pro_restart_number")
|
|
59
|
-
anti_restart_number: str = yaml_key("reasons.anti_restart_number")
|
|
60
|
-
|
|
61
|
-
# restarts
|
|
62
|
-
restart_action_sent: str = yaml_key("restarts.restart_action_sent")
|
|
63
|
-
server_back_online: str = yaml_key("restarts.back_online")
|
|
64
|
-
server_back_online_broadcast: str = yaml_key("restarts.back_online_broadcast")
|
|
65
|
-
server_failed_restart: str = yaml_key("restarts.failed_restart")
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{serverwatcher-5.8.dev11 → serverwatcher-5.8.dev13}/src/serverwatcher/configclasses/__init__.py
RENAMED
|
File without changes
|
|
File without changes
|
{serverwatcher-5.8.dev11 → serverwatcher-5.8.dev13}/src/serverwatcher.egg-info/dependency_links.txt
RENAMED
|
File without changes
|
|
File without changes
|
{serverwatcher-5.8.dev11 → serverwatcher-5.8.dev13}/src/serverwatcher.egg-info/top_level.txt
RENAMED
|
File without changes
|