forked from arkOScloud/genesis
-
Notifications
You must be signed in to change notification settings - Fork 0
/
genesis-panel
executable file
·91 lines (75 loc) · 2.47 KB
/
genesis-panel
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
#!/usr/bin/env python
import sys
import getopt
import os
import logging
from genesis.daemon import Daemon
class GenesisDaemon(Daemon):
def run(self):
from genesis.standalone import run_server # fixes gevent kevent loop
run_server(self.log_level, self.config_file)
def usage():
print """
Usage: %s [options]
Options:
-c, --config <file> - Use given config file instead of default
-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__':
reload(sys)
sys.setdefaultencoding('utf-8')
sys.dont_write_bytecode = True
log_level = logging.INFO
config_file = ''
try:
opts, args = getopt.getopt(sys.argv[1:], 'hc:drsv', ['help', 'config=', 'start', 'stop', 'restart'])
except getopt.GetoptError, e:
print str(e)
usage()
sys.exit(2)
action = 'run'
os.environ['XTABLES_LIBDIR'] = '/usr/lib/iptables'
for o, a in opts:
if o in ('-h', '--help'):
usage()
sys.exit(0)
elif o in ('-v',):
log_level = logging.DEBUG
elif o in ('-c', '--config'):
if os.path.isfile(a):
config_file = 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 not config_file:
# Check for config file in /etc/genesis/genesis.conf
if os.path.isfile('/etc/genesis/genesis.conf'):
config_file = '/etc/genesis/genesis.conf'
elif os.path.isfile(os.path.join(sys.path[0], 'genesis.conf')):
# Try local config file
config_file = os.path.join(sys.path[0], 'genesis.conf')
if action == 'run':
from genesis.standalone import run_server
run_server(log_level, config_file)
else:
genesisd = GenesisDaemon('/var/run/genesis.pid',stdout='/var/log/genesis.log')
genesisd.log_level = log_level
genesisd.config_file = config_file
if 'start' == action:
genesisd.start()
elif 'stop' == action:
genesisd.stop()
elif 'restart' == action:
genesisd.restart()
else:
usage()
sys.exit(2)
sys.exit(0)