-
Notifications
You must be signed in to change notification settings - Fork 56
/
Copy pathnginx-amplify-agent.py
executable file
·98 lines (84 loc) · 2.54 KB
/
nginx-amplify-agent.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#!/usr/bin/python
# -*- coding: utf-8 -*-
import sys
import amplify
amplify_path = '/'.join(amplify.__file__.split('/')[:-1])
sys.path.insert(0, amplify_path)
from gevent import monkey
monkey.patch_all(socket=False, ssl=False, select=False)
from optparse import OptionParser, Option
__author__ = "Mike Belov"
__copyright__ = "Copyright (C) 2015, Nginx Inc. All rights reserved."
__credits__ = ["Mike Belov", "Andrei Belov", "Ivan Poluyanov", "Oleg Mamontov", "Andrew Alexeev"]
__license__ = ""
__maintainer__ = "Mike Belov"
__email__ = "[email protected]"
usage = "usage: %prog [start|stop|configtest] [options]"
option_list = (
Option(
'--config',
action='store',
dest='config',
type='string',
help='path to config file',
default=None,
),
Option(
'--pid',
action='store',
dest='pid',
type='string',
help='path to pid file',
default=None,
),
Option(
'--foreground',
action='store_true',
dest='foreground',
help='do not daemonize, run in foreground',
default=False,
),
)
parser = OptionParser(usage, option_list=option_list)
(options, args) = parser.parse_args()
if __name__ == '__main__':
try:
from setproctitle import setproctitle
setproctitle('amplify-agent')
except ImportError:
pass
try:
action = sys.argv[1]
if action not in ('start', 'stop', 'configtest'):
raise IndexError
except IndexError:
print "Invalid action or no action supplied\n"
parser.print_help()
sys.exit(1)
if action == 'configtest':
from amplify.agent.util import configreader
rc = configreader.test(options.config, options.pid)
print ""
sys.exit(rc)
else:
try:
from amplify.agent.context import context
context.setup(
app='agent',
config_file=options.config,
pid_file=options.pid
)
except:
import traceback
print traceback.format_exc()
try:
from amplify.agent.supervisor import Supervisor
supervisor = Supervisor(foreground=options.foreground)
if not options.foreground:
from amplify.agent.runner import Runner
daemon_runner = Runner(supervisor)
daemon_runner.do_action()
else:
supervisor.run()
except:
context.default_log.error('failed to run', exc_info=True)