forked from czcorpus/kontext
-
Notifications
You must be signed in to change notification settings - Fork 0
/
install.py
127 lines (109 loc) · 5.15 KB
/
install.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
# Copyright (c) 2021 Charles University, Faculty of Arts,
# Institute of the Czech National Corpus
# Copyright (c) 2021 Martin Zimandl <[email protected]>
# Copyright (c) 2021 Tomas Machalek <[email protected]>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; version 2
# dated June, 1991.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
import argparse
import inspect
import os
import subprocess
KONTEXT_PATH = os.path.abspath(os.path.join(os.path.dirname(os.path.abspath(__file__)), '../..'))
KONTEXT_INSTALL_CONF = os.environ.get('KONTEXT_INSTALL_CONF', 'config.default.xml')
SCHEDULER_INSTALL_CONF = os.environ.get('SCHEDULER_INSTALL_CONF', 'rq-schedule-conf.sample.json')
MANATEE_VER = '2.223.6'
REQUIREMENTS = [
'python3-pip',
'wget',
'curl',
'openssh-server',
'net-tools',
'redis-server',
'build-essential',
'openssl',
'pkg-config',
'swig',
'nginx',
'libltdl7',
'libpcre3',
'libicu-dev',
'libpcre++-dev',
'libxml2-dev',
'libxslt1-dev',
'libltdl-dev',
# required by manatee packages
'm4',
'parallel',
'locales-all',
'sox'
]
if __name__ == "__main__":
argparser = argparse.ArgumentParser('Kontext instalation script')
argparser.add_argument('--ucnk', action='store_true', default=False, help='Use UCNK sources')
argparser.add_argument('--patch', dest='patch_path', action='store',
default=None, help='Path to UCNK Manatee patch')
argparser.add_argument('--manatee-version', dest='manatee_version',
action='store', default=MANATEE_VER, help='Set Manatee version')
argparser.add_argument('--no-safe-http', dest='no_cert_check', action='store_true',
default=False, help='Do not verify HTTPS certificates when downloading packages')
argparser.add_argument('-v', dest='verbose', action='store_true',
default=False, help='Verbose mode')
args = argparser.parse_args()
stdout = None if args.verbose else open(os.devnull, 'wb')
stderr = None
subprocess.call(['systemctl', 'stop', 'rq-all.target'])
subprocess.call(['systemctl', 'stop', 'rqscheduler'])
# install prerequisites
print('Installing requirements...')
try:
subprocess.check_call(['locale-gen', 'en_US.UTF-8'], stdout=stdout)
subprocess.check_call(['apt-get', 'update', '-y'], stdout=stdout)
subprocess.check_call(['apt-get', 'install', '-y'] + REQUIREMENTS, stdout=stdout)
subprocess.check_call(['python3', '-m', 'pip', 'install',
'pip', '--upgrade'], stdout=stdout)
subprocess.check_call(['pip3 install simplejson signalfd -r requirements.txt'],
cwd=KONTEXT_PATH, stdout=stdout, shell=True)
subprocess.check_call(
'curl -sL https://deb.nodesource.com/setup_16.x | sudo -E bash -', shell=True)
subprocess.check_call('sudo apt-get install -y nodejs', shell=True)
except Exception as ex:
print(f'failed to install dependencies: {ex}')
# import steps here, because some depend on packages installed by this script
import steps
# run installation steps
steps.SetupBgCalc(KONTEXT_PATH, stdout, stderr).run()
steps.SetupNginx(KONTEXT_PATH, stdout, stderr).run()
steps.SetupManatee(KONTEXT_PATH, stdout, stderr, args.no_cert_check).run(
args.manatee_version, args.patch_path, ucnk_manatee=args.ucnk)
steps.SetupKontext(
kontext_path=KONTEXT_PATH, kontext_conf=KONTEXT_INSTALL_CONF,
scheduler_conf=SCHEDULER_INSTALL_CONF, stdout=stdout, stderr=stderr).run()
steps.SetupDefaultUsers(KONTEXT_PATH, stdout, stderr).run()
# finalize instalation
print('Initializing Rq...')
subprocess.check_call(['systemctl', 'start', 'rq-all.target'], stdout=stdout)
subprocess.check_call(['systemctl', 'start', 'rqscheduler'], stdout=stdout)
print('Initializing Nginx...')
subprocess.check_call(['systemctl', 'restart', 'nginx'], stdout=stdout)
# print final messages
print(inspect.cleandoc(f'''
{steps.bcolors.BOLD}{steps.bcolors.OKGREEN}
KonText installation successfully completed.
To start KonText, enter the following command in the KonText install root directory (i.e. {KONTEXT_PATH}):
sudo -u {steps.WEBSERVER_USER} python3 public/app.py --address 127.0.0.1 --port 8080
(--address and --port parameters are optional; default serving address is 127.0.0.1:5000)
{steps.bcolors.ENDC}{steps.bcolors.ENDC}
'''))
for message in steps.InstallationStep.final_messages:
print(inspect.cleandoc(message))