-
Notifications
You must be signed in to change notification settings - Fork 0
/
merlin.py
153 lines (126 loc) · 4.61 KB
/
merlin.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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
# -*- coding: utf-8 -*-
"""Scalix Installer.
Usage:
merlin.py [--cli] [--pkgdir=<pkgdir>] [--logdir=<logdir>] \
[--instance=<instance_name>] [--hostname=<hostname>] [--no-root]
merlin.py (-h | --help)
merlin.py --version
Options:
-h --help Show this screen.
--version Show version.
--cli Console only application
--pkgdir=<pkgdir> Directory with packages to install or upgrade \
[default: ../products/]
--logdir=<logdir> Directory for log file [default: ../logs/]
--instance=<instance_name> Scalix Instance name
--hostname=<hostname> Set hostname
--no-root No root
"""
from __future__ import print_function, unicode_literals, with_statement, \
absolute_import
__author__ = 'pussbb'
import os
import sys
import signal
def sigint_handler(signum, frame):
pass
signal.signal(signal.SIGINT, sigint_handler )
_dir = os.path.abspath(os.path.dirname(__file__))
sys.path.append(os.path.join(_dir, '3rdparty'))
from sx.exceptions import ScalixException, ScalixPackageException, \
ScalixUnresolvedDependencies, ScalixPackageProblems
import sx.version as version
import sx.logger as logger
from sx.system import System
from sx.package.manager import PackageManager
from sx import utils
def service_test(system):
print(system.service_manager.available())
apache_service = system.service_manager.apache
print(apache_service.exists)
print(apache_service.commands)
print(apache_service('restart'))
print(apache_service.is_running())
print(apache_service.run_levels())
print(system.service_manager.enable(apache_service))
print(apache_service.run_levels())
print(system.service_manager.disable(apache_service))
print(apache_service.run_levels())
def package_manager_test(system):
pm = PackageManager(system)
pm.scan_folder('../products/')
print(repr(pm))
try:
for package in pm.packages:
if not package.installed:
package.install = True
else:
package.uninstall = True
pm.proccess()
except ScalixPackageException as exception:
if isinstance(exception, ScalixUnresolvedDependencies):
print(pm.format_dependencies(exception.dependecies))
elif isinstance(exception, ScalixPackageProblems):
print(pm.format_problems(exception.problems))
else:
# some unexpected exception
raise
#print(repr(pm))
def system_tests(system):
#print(System.command_exists('wipe'))
print(system.determine_interface(System.determine_ip()))
print(system.determine_ip())
print(System.get_java_version())
print(System.is_ibm_j2sdk())
print(system.get_mx_records('allwebsuite.com'))
print(system.get_ips())
print(System.get_fqdn())
print(System.is_fqdn())
print(*system.listening_port(80))
print("supported", system.is_supported())
print("run level", system.run_level())
mem = system.memory()
print("Memory (total, free)", [utils.size2human(i) for i in mem])
print([utils.size2human(i) for i in system.disk_space('/', '/opt')])
#print(System.open_url('http://python.org/'))
def init_logger(args):
logger.init_logger('Merlin', directory=args['--logdir'])
logger.info("Initializing Installer version", version.get_version(),
output=True)
logger.info("Using log file", logger.logger_filename(), output=True)
def main(args, system):
if not args['--no-root'] and os.geteuid() != 0:
raise ScalixException('Error: You need to be root or superuser '
'to run this application')
if 'DISPLAY' not in os.environ:
args["--cli"] = True
# Process Instance
if args["--instance"]:
os.environ["OMCURRENT"] = args["--instance"]
# Process Hostname
if args["--hostname"]:
os.environ["OMHOSTNAME"] = args["--hostname"]
app = None
if args["--cli"] or not app:
import sx.cli.app
app = sx.cli.app.CliApplication
try:
app(system, args).run()
except (EOFError, KeyboardInterrupt, SystemExit) as _:
pass
if __name__ == '__main__':
from docopt import docopt
ARGS = docopt(__doc__, version=version.get_version())
init_logger(ARGS)
system = System()
logger.info('Running on:\n', system, output=True)
try:
main(ARGS, system)
#system_tests(system)
#package_manager_test(system)
#service_test(system)
except:
raise
finally:
if __debug__:
os.remove(logger.logger_filename(base_name=False))