-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplsDontBeDed.py
More file actions
executable file
·50 lines (38 loc) · 1.29 KB
/
plsDontBeDed.py
File metadata and controls
executable file
·50 lines (38 loc) · 1.29 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
#!/usr/bin/env python3
from subprocess import run
from datetime import datetime
import time
LAUNCHCS_CMD = "/home/cs-servers/launchcs/launchcs.py"
CS2_SERVER_CMD = "/home/cs-servers/.local/bin/cs2-server"
def getDedServer():
dedLine = []
process = run(f"{LAUNCHCS_CMD} list", shell=True, capture_output=True)
stdout_str = process.stdout.decode("utf-8")
stderr_str = process.stderr.decode("utf-8")
if stderr_str:
print(f"ERROR launchcs.py : {stderr_str}")
for line in stdout_str.split("\n"):
if "stopped" in line:
dedLine.append(line)
ded = []
for dedServer in dedLine:
try:
serverString = dedServer.split()[1]
ded.append(serverString)
except IndexError:
pass
return ded
def rebootDed():
servers = getDedServer()
for server in servers:
print(f"{CS2_SERVER_CMD} @{server} start")
process = run(f"{CS2_SERVER_CMD} @{server} start", shell=True, capture_output=True)
stdout_str = process.stdout.decode("utf-8")
stderr_str = process.stderr.decode("utf-8")
if stderr_str:
print(f"ERROR launchcs.py : {stderr_str}")
print(stdout_str)
print(f"[{datetime.now()}] - Revived {server}")
while 1:
rebootDed()
time.sleep(10)