Skip to content

Instantly share code, notes, and snippets.

@fvanderbiest
Created May 2, 2014 06:45
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save fvanderbiest/f5d5e467c7ca004ce73b to your computer and use it in GitHub Desktop.
Save fvanderbiest/f5d5e467c7ca004ce73b to your computer and use it in GitHub Desktop.
geoserver reload script
#!/usr/bin/env python
#-*- coding: utf-8 -*-
"""This is a script that we use to reload geoserver catalogs when load balancing them"""
"""
Copyright 2014 Camptocamp. All rights reserved.
Redistribution and use in source and binary forms, with or without modification, are
permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this list of
conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice, this list
of conditions and the following disclaimer in the documentation and/or other materials
provided with the distribution.
THIS SOFTWARE IS PROVIDED BY CAMPTOCAMP ``AS IS'' AND ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL CAMPTOCAMP OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
The views and conclusions contained in the software and documentation are those of the
authors and should not be interpreted as representing official policies, either expressed
or implied, of Camptocamp.
"""
config = {
'geoserver': [
'127.0.0.1:8180',
'127.0.0.1:8181',
#'', # next one
]
}
# DO NOT MODIFY ANYTHING BELOW THIS #
# (unless you know what you're doing)
import cgi
import sys, os
import urllib2
#curl -H "sec-roles:ROLE_ADMINISTRATOR" -H 'sec-username:fake_user' -v -XPOST http://127.0.0.1:8181/geoserver/rest/reload?recurse=true
headers = {
"sec-roles": "ROLE_ADMINISTRATOR",
"sec-username": "fake_user",
}
failures = []
for host in config['geoserver']:
req = urllib2.Request("http://"+host+"/geoserver/rest/reload?recurse=true", "nothing", headers)
try:
r = urllib2.urlopen(req)
except urllib2.URLError as e:
failures.append((host, e.reason))
if len(failures) == 0:
print "Status: 200 OK"
print ""
print "Reload OK"
else:
print "Status: 500 Internal Server Error"
print ""
for f in failures:
print "Reload failed for host %s, reason is '%s'" % f
@jometho
Copy link

jometho commented Jan 25, 2018

Hi @fvanderbiest, I know this script if from long ago but I really need something like this. However, I don't seem to understand your usage of headers = { sec-roles": "ROLE_ADMINISTRATOR", "sec-username": "fake_user", }
What does this mean in Geoserver? how does it work?

Your help will be highly appreciated.

@fvanderbiest
Copy link
Author

Hi @jometho, sorry I did not see your comment before.
The headers are required for a geOrchestra compatible GeoServer, in which a GeoServerRequestHeaderAuthenticationFilter filter has been configured like this.
This allows to initiate the request as an administrator. This does not apply to the general case !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment