-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommon_util.py
63 lines (50 loc) · 2.11 KB
/
common_util.py
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
import json
import os.path
import os
import sys
def check_services_running():
with open(processid_file_path, "r") as f:
data = json.load(f)
if(data["docservice"] > 0 and check_pid(data["docservice"])):
sys.exit("Error : docservice running with pid (" + str(data["docservice"]) + ") ")
if(data["spellchecker"] > 0 and check_pid(data["spellchecker"])):
sys.exit("Error : spellchecker running with pid (" + str(data["spellchecker"]) + ") ")
if(data["converter"] > 0 and check_pid(data["converter"])):
sys.exit("Error : converter running with pid (" + str(data["converter"]) + ") ")
def check_docservice_running():
with open(processid_file_path, "r") as f:
data = json.load(f)
if(data["docservice"] > 0 and check_pid(data["docservice"])):
sys.exit("Error : docservice running with pid (" + str(data["docservice"]) + ") ")
def check_spellchecker_running():
with open(processid_file_path, "r") as f:
data = json.load(f)
if(data["spellchecker"] > 0 and check_pid(data["spellchecker"])):
sys.exit("Error : spellchecker running with pid (" + str(data["spellchecker"]) + ") ")
def check_converter_running():
with open(processid_file_path, "r") as f:
data = json.load(f)
if(data["converter"] > 0 and check_pid(data["converter"])):
sys.exit("Error : converter running with pid (" + str(data["converter"]) + ") ")
def check_pid(pid):
try:
os.kill(pid, 0)
except OSError:
return False
else:
return True
def update_processid(docservice_process_id, spellchecker_process_id, converter_process_id):
with open(processid_file_path, "r") as f:
data = json.load(f)
if(docservice_process_id > 0):
data["docservice"] = docservice_process_id
if(spellchecker_process_id > 0):
data["spellchecker"] = spellchecker_process_id
if(converter_process_id > 0):
data["converter"] = converter_process_id
with open(processid_file_path, "w") as jsonFile:
json.dump(data, jsonFile, indent=4)
with open(processid_file_path, "r") as f:
dataupdated = json.load(f)
print("Process IDS docservice, spellchecker, converter :: "+ str(dataupdated))
processid_file_path = "process_id.json"