-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathkrakend
More file actions
executable file
·112 lines (97 loc) · 3.12 KB
/
krakend
File metadata and controls
executable file
·112 lines (97 loc) · 3.12 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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
#!/usr/bin/env python
import imp
import sys
import getopt
import os
from arkos.daemon import Daemon
from kraken.application import run_daemon
class KrakenDaemon(Daemon):
def run(self):
run_daemon(
self.environment, self.config_file,
self.secrets_file, self.policy_file,
self.debug
)
def usage():
print("""
Usage: kraken [options]
Options:
-c, --config <file> - Use given config file instead of default
-e, --env <env> - Set run environment (dev, vagrant, etc)
-v - Debug/verbose logging
-d, --start - Run in background (daemon mode)
-r, --restart - Restart daemon
-s, --stop - Stop daemon
-h, --help - This help
""")
if __name__ == '__main__':
imp.reload(sys)
sys.dont_write_bytecode = True
try:
opts, args = getopt.getopt(
sys.argv[1:], 'hce:drsv',
['help', 'config=', 'env=', 'start', 'stop', 'restart']
)
except getopt.GetoptError as e:
print((str(e)))
usage()
sys.exit(2)
action = 'run'
environment = 'prod'
debug = False
config_file = secrets_file = policy_file = ''
for o, a in opts:
if o in ('-h', '--help'):
usage()
sys.exit(0)
elif o in ('-v',):
debug = True
elif o in ('-c', '--config'):
if os.path.isfile(a):
config_file = a
elif o in ('-e', '--env'):
environment = a
elif o in ('-d', '--start'):
action = 'start'
elif o in ('-r', '--restart'):
action = 'restart'
elif o in ('-s', '--stop'):
action = 'stop'
# Find default config file
if environment != "prod":
if not config_file or not os.path.exists(config_file):
config_file = os.path.join(
os.path.dirname(__file__), "settings.json")
if not os.path.exists(config_file):
config_file = ""
if not secrets_file or not os.path.exists(secrets_file):
secrets_file = os.path.join(
os.path.dirname(__file__), "secrets.json")
if not os.path.exists(secrets_file):
secrets_file = ""
if not policy_file or not os.path.exists(policy_file):
policy_file = os.path.join(
os.path.dirname(__file__), "policies.json")
if not os.path.exists(policy_file):
policy_file = ""
if action == 'run':
run_daemon(
environment, config_file, secrets_file, policy_file, debug
)
else:
krakend = KrakenDaemon('/var/run/kraken.pid')
krakend.environment = environment
krakend.config_file = config_file
krakend.secrets_file = secrets_file
krakend.policy_file = policy_file
krakend.debug = debug
if 'start' == action:
krakend.start()
elif 'stop' == action:
krakend.stop()
elif 'restart' == action:
krakend.restart()
else:
usage()
sys.exit(2)
sys.exit(0)