-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathexplorer.py
More file actions
88 lines (67 loc) · 2.52 KB
/
explorer.py
File metadata and controls
88 lines (67 loc) · 2.52 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# -*- coding: utf-8 -*-
# MultiChain Explorer 2 (c) Coin Sciences Ltd
# All rights reserved under BSD 3-clause license
import os
import sys
import signal
import cfg
import readconf
import utils
import server
explorer_app = "MultiChain Explorer"
def main(argv):
if len(argv) == 0:
print ("""\nUsage: python3 explorer.py config-file.ini ( daemon | stop | status )
""" + explorer_app +""", version """ + explorer_app +"""
config-file Configuration file, see example.ini for examples.
action Optional, one of the following:
daemon Start explorer as daemon
stop Stop running explorer
status Get explorer status
""")
return 0
print (explorer_app + """, version """ + cfg.version + "\n")
print ("")
args=readconf.parse_argv(argv)
if cfg.action is not None:
if cfg.action == 'daemon':
utils.become_daemon();
if not readconf.read_conf(args):
return 1;
current_pid=utils.file_read(cfg.pid_file)
if current_pid is not None:
try:
os.kill(int(current_pid), 0)
except OSError:
utils.remove_file(cfg.pid_file)
current_pid=None
if cfg.action is not None:
if (cfg.action == 'stop') or (cfg.action == 'status'):
if current_pid is None:
print("Explorer is not running\n")
return 0
process_id=int(current_pid)
print("Explorer found, PID " + str(process_id))
if cfg.action == 'stop':
utils.log_write("Stopping Explorer, PID: " + str(current_pid))
print("Sending stop signal")
try:
os.kill(int(current_pid),signal.SIGTERM)
utils.remove_file(cfg.pid_file)
except OSError:
utils.log_write("Explorer already stopped")
utils.remove_file(cfg.pid_file)
return 0
if current_pid is not None:
utils.print_error("Explorer for this configuration file is already running")
return 1
utils.file_write(cfg.pid_file,utils.get_pid())
current_pid=utils.file_read(cfg.pid_file)
utils.log_write("Explorer started, PID: " + str(current_pid))
if not server.start():
utils.remove_file(cfg.pid_file)
return 1
utils.remove_file(cfg.pid_file)
utils.log_write("Explorer stopped")
if __name__ == '__main__':
sys.exit(main(sys.argv[1:]))