-
Notifications
You must be signed in to change notification settings - Fork 23
/
check-system
executable file
·68 lines (53 loc) · 2.13 KB
/
check-system
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
66
67
68
#!/usr/bin/python
import psutil
import sys
ONE_MB = 1024 ** 2
def check_bound_port(port):
with open("/proc/net/tcp") as tcp:
contents = tcp.read()
# parse the contents of /proc/net/tcp looking for a bound port
lines = contents.split('\n')
# skip the header line
for line in lines[1:]:
# format is sl, local_address, rem_address, st (state), ...
# we look for a local address whose port (in hex) matches our target
# port and is also in the listening state (0A)
fields = line.split()
# ignore malformed lines
if len(fields) < 4:
continue
local_address = fields[1].split(":")
state = fields[3]
if len(local_address) != 2:
continue
try:
local_port = int(local_address[1], 16)
if local_port == port and state == "0A":
return True
except ValueError:
continue
return False
if __name__ == "__main__":
virtual_memory = psutil.virtual_memory()
cpu_count = psutil.cpu_count()
if cpu_count < 4:
sys.stderr.write("Error: MemSQL requires at least 4 CPU cores available.\n")
sys.stderr.write("See our documentation for help.\n")
sys.stderr.write("http://docs.memsql.com/latest/setup/docker/\n\n")
sys.exit(1)
if virtual_memory.total < ONE_MB * 3700:
sys.stderr.write("Error: MemSQL requires at least 4 GB of memory to run.\n")
sys.stderr.write("See our documentation for help.\n")
sys.stderr.write("http://docs.memsql.com/latest/setup/docker/\n\n")
sys.exit(1)
if check_bound_port(3306):
sys.stderr.write("Error: Port 3306 is already taken.\n")
sys.stderr.write("See our documentation for help.\n")
sys.stderr.write("http://docs.memsql.com/latest/setup/docker/\n\n")
sys.exit(1)
if check_bound_port(9000):
sys.stderr.write("Error: Port 9000 is already taken.\n")
sys.stderr.write("See our documentation for help.\n")
sys.stderr.write("http://docs.memsql.com/latest/setup/docker/\n\n")
sys.exit(1)
print("System check successful.")