Created
May 2, 2014 06:45
-
-
Save fvanderbiest/f5d5e467c7ca004ce73b to your computer and use it in GitHub Desktop.
geoserver reload script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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 !