1
|
1 |
|
import os |
2
|
1 |
|
import sys |
3
|
|
|
|
4
|
|
|
|
5
|
|
|
# ---------------------------------------------------------------------------------------------------------------------- |
6
|
1 |
|
HOME = os.path.realpath(os.path.dirname(os.path.realpath(__file__)) + '/../..') |
7
|
|
|
|
8
|
1 |
|
CONTROLLER_PULL_END_POINT = 'tcp://127.0.0.1:7771' |
9
|
1 |
|
CONTROLLER_LOCKSTEP_END_POINT = 'tcp://127.0.0.1:7772' |
10
|
1 |
|
LOGGER_PULL_END_POINT = 'tcp://127.0.0.1:7773' |
11
|
1 |
|
SPAWNER_PULL_END_POINT = 'tcp://127.0.0.1:7774' |
12
|
|
|
|
13
|
1 |
|
MYSQL_HOSTNAME = '127.0.0.1' |
14
|
1 |
|
MYSQL_USERNAME = 'enarksh_owner' |
15
|
1 |
|
MYSQL_PASSWORD = 'cH5thast2stebeT3' |
16
|
1 |
|
MYSQL_SCHEMA = 'enarksh' |
17
|
1 |
|
MYSQL_PORT = 3306 |
18
|
|
|
|
19
|
1 |
|
CHUNK_SIZE = 1024 * 1024 |
20
|
|
|
|
21
|
1 |
|
ENK_RST_ID_COMPLETED = 3 |
22
|
1 |
|
ENK_RST_ID_ERROR = 4 |
23
|
1 |
|
ENK_RST_ID_QUEUED = 5 |
24
|
1 |
|
ENK_RST_ID_RUNNING = 2 |
25
|
1 |
|
ENK_RST_ID_WAITING = 1 |
26
|
|
|
|
27
|
1 |
|
ENK_ACT_ID_TRIGGER = 1 |
28
|
1 |
|
ENK_ACT_ID_RESTART = 2 |
29
|
1 |
|
ENK_ACT_ID_RESTART_FAILED = 3 |
30
|
|
|
|
31
|
1 |
|
ENK_PTT_ID_INPUT = 1 |
32
|
1 |
|
ENK_PTT_ID_OUTPUT = 2 |
33
|
|
|
|
34
|
1 |
|
ENK_RWS_ID_NONE = 1 |
35
|
1 |
|
ENK_RWS_ID_READ = 2 |
36
|
1 |
|
ENK_RWS_ID_WRITE = 3 |
37
|
|
|
|
38
|
1 |
|
ENK_RTP_ID_COUNTING = 1 |
39
|
1 |
|
ENK_RTP_ID_READ_WRITE = 2 |
40
|
|
|
|
41
|
1 |
|
ENK_CTP_ID_COUNTING = 1 |
42
|
1 |
|
ENK_CTP_ID_READ_WRITE = 2 |
43
|
|
|
|
44
|
1 |
|
ENK_NTP_SCHEDULE = 1 |
45
|
1 |
|
ENK_NTP_COMMAND_JOB = 2 |
46
|
1 |
|
ENK_NTP_COMPOUND_JOB = 3 |
47
|
1 |
|
ENK_NTP_MANUAL_TRIGGER = 4 |
48
|
1 |
|
ENK_NTP_TERMINATOR = 5 |
49
|
1 |
|
ENK_NTP_DYNAMIC_JOB = 6 |
50
|
1 |
|
ENK_NTP_DYNAMIC_OUTER_WORKER = 7 |
51
|
1 |
|
ENK_NTP_DYNAMIC_INNER_WORKER = 8 |
52
|
|
|
|
53
|
1 |
|
ENK_MESSAGE_ADMIN_DIR = HOME + '/var/lib/message/admin' |
54
|
1 |
|
ENK_MESSAGE_CONTROLLER_DIR = HOME + '/var/lib/message/controller' |
55
|
1 |
|
ENK_MESSAGE_LOGGER_DIR = HOME + '/var/lib/message/logger' |
56
|
1 |
|
ENK_MESSAGE_SPAWNER_DIR = HOME + '/var/lib/message/spawner' |
57
|
1 |
|
ENK_LOCK_DIR = HOME + '/var/lock' |
58
|
|
|
|
59
|
|
|
|
60
|
|
|
# ---------------------------------------------------------------------------------------------------------------------- |
61
|
1 |
|
def daemonize(pid_filename, stdin, stdout, stderr): |
62
|
|
|
""" |
63
|
|
|
Turns the current process into a daemon process. |
64
|
|
|
|
65
|
|
|
Note: Call this function before opening files or create (database) connections. |
66
|
|
|
|
67
|
|
|
:param str pid_filename: The filename where the PID of the daemon process must be stored. |
68
|
|
|
:param str stdin: |
69
|
|
|
:param str stdout: |
70
|
|
|
:param str stderr: |
71
|
|
|
""" |
72
|
|
|
if os.path.exists(pid_filename): |
73
|
|
|
file = open(pid_filename, 'r') |
74
|
|
|
pid = file.read() |
75
|
|
|
try: |
76
|
|
|
os.kill(int(pid), 0) |
77
|
|
|
# No exception. This means a process with pid is already running. |
78
|
|
|
raise RuntimeError('Already running') |
79
|
|
|
except ProcessLookupError: |
80
|
|
|
# Ignore No such process error. This means process it not running. |
81
|
|
|
pass |
82
|
|
|
|
83
|
|
|
# Fork the current process (detaches from parent) |
84
|
|
|
if os.fork() > 0: |
85
|
|
|
# Exit the parent process. |
86
|
|
|
raise SystemExit(0) |
87
|
|
|
|
88
|
|
|
# Change the working directory. |
89
|
|
|
os.chdir(HOME) |
90
|
|
|
|
91
|
|
|
# Reset the file mode mask. |
92
|
|
|
os.umask(0) |
93
|
|
|
|
94
|
|
|
# Become the session leader. |
95
|
|
|
os.setsid() |
96
|
|
|
|
97
|
|
|
# Flush I/O buffers |
98
|
|
|
sys.stdout.flush() |
99
|
|
|
sys.stderr.flush() |
100
|
|
|
|
101
|
|
|
# Replace file descriptors for stdin, stdout, and stderr |
102
|
|
|
with open(stdin, 'rb', 0) as f: |
103
|
|
|
os.dup2(f.fileno(), sys.stdin.fileno()) |
104
|
|
|
with open(stdout, 'ab', 0) as f: |
105
|
|
|
os.dup2(f.fileno(), sys.stdout.fileno()) |
106
|
|
|
with open(stderr, 'ab', 0) as f: |
107
|
|
|
os.dup2(f.fileno(), sys.stderr.fileno()) |
108
|
|
|
|
109
|
|
|
# Write the PID file |
110
|
|
|
with open(pid_filename, 'w') as f: |
111
|
|
|
print(os.getpid(), file=f) |
112
|
|
|
|
113
|
|
|
# ---------------------------------------------------------------------------------------------------------------------- |
114
|
|
|
|