-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathinstall_geoserver.py
207 lines (153 loc) · 5.98 KB
/
install_geoserver.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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
"""Install new Geoserver system wide
Usage:
sudo python install_geoserver.py
"""
import sys, os, commands
from config import geoserver, java_home, geoserver_url, geoserver_rest_plugin, geoserver_rest_plugin_url, webdir, workdir
from utilities import run, makedir, header
def install_ubuntu_packages():
"""Get required Ubuntu packages for geoserver.
It is OK if they are already installed
"""
header('Installing Ubuntu packages')
s = 'apt-get clean'
run(s, verbose=True)
for package in ['apache2', 'openjdk-6-jre-lib', 'gdal-bin', 'curl', 'python-pycurl', 'python-gdal', 'python-setuptools']:
s = 'apt-get -y install %s' % package
log_base = workdir + '/' + '%s_install' % package
try:
run(s,
stdout=log_base + '.out',
stderr=log_base + '.err',
verbose=True)
except:
msg = 'Installation of package %s failed. ' % package
msg += 'See log file %s.out and %s.err for details' % (log_base, log_base)
raise Exception(msg)
def install_python_packages():
"""Python packages that are not part of Ubuntu
"""
# OWSLIB frozen at r1672 (5 August 2010)
try:
import owslib
except:
cmd = 'cd /tmp; svn co -r 1672 http://svn.gispython.org/svn/gispy/OWSLib/trunk OWSLib'
run(cmd)
cmd = 'cd /tmp/OWSLib; sudo python setup.py install'
run(cmd)
#def get_packages_from_source():
# """Get packages that shouldn't come from the Ubuntu repository - such as newer versions
# """
#
#
# # GDAL 1.6.3
# gdal_version = '1.6.3'
# s = commands.getoutput('gdalinfo --version')
# print s
# if s.find(version) > 0:
# # Nothing to do
# return
#
# archive = 'gdal-%s.tar.gz' % gdal_version
# path = 'http://download.osgeo.org/gdal/%s' % archive
#
# if not os.path.isfile(archive):
# # FIXME: Should also check integrity of tgz file.
# cmd = 'wget ' + path
# run(cmd, verbose=True)
#
# cmd = 'tar -zvxf %s' % archive
# run(cmd, verbose=True)
#
# cmd = 'cd gdal-%s; ./configure --with-static-proj4=/usr/local/lib --with-threads --with-libtiff=internal --with-geotiff=internal --with-jpeg=internal --with-gif=internal --with-png=internal --with-libz=internal' % gdal_version
# run(cmd, verbose=True)
#
# cmd = 'cd gdal-%s; make; make install' % gdal_version
# run(cmd, verbose=True)
def download_and_unpack():
"""Download geoserver OS independent files
"""
archive = workdir + '/' + geoserver + '-bin.zip'
path = os.path.join(geoserver_url, archive)
if not os.path.isfile(archive):
# FIXME: Should also check integrity of zip file.
cmd = 'cd %s; wget %s' % (workdir, path)
run(cmd, verbose=True)
# Clean out
s = '/bin/rm -rf /usr/local/%s' % geoserver
run(s, verbose=True)
# Unpack
s = 'unzip %s -d /usr/local' % archive
run(s, verbose=True)
def get_plugins():
"""Get plugins such as REST
"""
path = geoserver_rest_plugin_url
archive = workdir + '/' + geoserver_rest_plugin
print 'Archive', archive
if not os.path.isfile(archive):
# FIXME: Should also check integrity of zip file.
cmd = 'cd %s; wget %s' % (workdir, path)
run(cmd, verbose=True)
# Unpack into geoserver installation
s = 'unzip %s -d /usr/local/%s/webapps/geoserver/WEB-INF/lib' % (archive,
geoserver)
run(s, verbose=True)
def change_permissions():
"""Make ../data_dir/www writable to all and make web dir
"""
s = 'chmod -R a+w /usr/local/%s/data_dir/www' % geoserver
run(s, verbose=True)
makedir(webdir)
s = 'chown -R www-data:www-data %s' % webdir
run(s, verbose=True)
s = 'chmod -R a+w %s' % webdir
run(s, verbose=True)
def set_environment():
"""Set up /etc/default/geoserver
"""
fid = open('/etc/default/geoserver', 'wb')
fid.write('USER=geoserver\n')
fid.write('GEOSERVER_DATA_DIR=/usr/local/%s/data_dir\n' % geoserver)
fid.write('GEOSERVER_HOME=/usr/local/%s\n' % geoserver)
fid.write('JAVA_HOME=%s\n' % java_home)
fid.write('JAVA_OPTS="-Xms128m -Xmx512m"\n')
#GEOSERVER_DATA_DIR=/home/$USER/data_dir
#GEOSERVER_HOME=/home/$USER/geoserver
fid.close()
def run_startup():
"""Run geoserver startup script
"""
geo_home = '/usr/local/%s' % geoserver
cmd = 'export JAVA_HOME=%s; export GEOSERVER_HOME=%s; $GEOSERVER_HOME/bin/startup.sh' % (java_home,
geo_home)
os.system(cmd)
def install_openlayers():
"""Install OpenLayers locally
This will allow web frontend to run without Internet access
"""
ol_dir = '/var/www/openlayers'
cmd = 'svn checkout http://svn.openlayers.org/trunk/openlayers/ %s' % ol_dir
run(cmd, verbose=True)
cmd = 'chown -R www-data:www-data %s' % ol_dir
run(cmd, verbose=True)
if __name__ == '__main__':
s = commands.getoutput('whoami')
if s != 'root':
print
print 'Script must be run as root e.g. using: sudo python %s' % sys.argv[0]
import sys; sys.exit()
print ' - Installing new Geoserver'
# Create area for logs and downloads
makedir(workdir)
# Install GeoServer and dependencies
install_ubuntu_packages()
install_python_packages()
download_and_unpack()
get_plugins()
change_permissions()
set_environment()
install_openlayers()
print 'Geoserver installed. To start it run'
print 'python start_geoserver.py'
#run_startup()