-
Notifications
You must be signed in to change notification settings - Fork 36
/
isi_data_insights_d.py
executable file
·78 lines (62 loc) · 2.34 KB
/
isi_data_insights_d.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#!/usr/bin/env python
# From __future_ imports have to be before everything.
from __future__ import print_function
from builtins import str
# Have to do this before importing the other libs
# The noqa comment prevents spurious E402 flake8 errors
# The documentation for monkey explicitly requires patching to be
# performed as early as possible BEFORE other imports but after the
# from __future__ imports.
from gevent import monkey
monkey.patch_all() # noqa
import sys
from isi_data_insights_config import (
parse_cli,
configure_args_via_file,
process_pid_file_arg,
configure_logging_via_cli,
configure_via_cli,
configure_via_file,
)
from isi_data_insights_daemon import IsiDataInsightsDaemon
def main():
args = parse_cli()
# load the config file if one is provided, then set the "required"
# parameters of the CLI args with config file parameters (if possible)
config_file = configure_args_via_file(args)
# validate the pid_file arg and get the full path to it.
pid_file_path = process_pid_file_arg(args.pid_file, args.action)
daemon = IsiDataInsightsDaemon(pidfile=pid_file_path)
# before we do the long process of configuring, lets make sure we have
# a valid pid to do a stop or restart with
if (args.action == "restart" or args.action == "stop") and daemon.pid is None:
print(
"Cannot " + args.action + " daemon, "
"invalid pid in file: " + str(pid_file_path),
file=sys.stderr,
)
sys.exit(1)
if args.action == "start" or args.action == "debug" or args.action == "restart":
configure_logging_via_cli(args)
if config_file is not None:
configure_via_file(daemon, args, config_file)
else:
configure_via_cli(daemon, args)
if args.action == "start":
daemon.start()
elif args.action == "restart":
print("Restarting daemon with pid " + str(daemon.pid))
daemon.restart()
else:
daemon.run(debug=True)
elif args.action == "stop":
print("Stopping daemon with pid " + str(daemon.pid))
daemon.stop()
else:
print(
"Invalid action arg: '%s', must be one of "
"'start', 'stop', or 'restart'." % args.action,
file=sys.stderr,
)
if __name__ == "__main__":
main()