Update SOLR check in prerun
This commit is contained in:
parent
754f201942
commit
e47474de97
|
@ -5,6 +5,7 @@ import psycopg2
|
||||||
import urllib2
|
import urllib2
|
||||||
import re
|
import re
|
||||||
|
|
||||||
|
import time
|
||||||
|
|
||||||
ckan_ini = os.environ.get('CKAN_INI', '/srv/app/production.ini')
|
ckan_ini = os.environ.get('CKAN_INI', '/srv/app/production.ini')
|
||||||
|
|
||||||
|
@ -12,6 +13,8 @@ RETRY = 5
|
||||||
|
|
||||||
def check_db_connection(retry=None):
|
def check_db_connection(retry=None):
|
||||||
|
|
||||||
|
print '[prerun] Start check_db_connection...'
|
||||||
|
|
||||||
if retry is None:
|
if retry is None:
|
||||||
retry = RETRY
|
retry = RETRY
|
||||||
elif retry == 0:
|
elif retry == 0:
|
||||||
|
@ -33,6 +36,8 @@ def check_db_connection(retry=None):
|
||||||
|
|
||||||
def check_solr_connection(retry=None):
|
def check_solr_connection(retry=None):
|
||||||
|
|
||||||
|
print '[prerun] Start check_solr_connection...'
|
||||||
|
|
||||||
if retry is None:
|
if retry is None:
|
||||||
retry = RETRY
|
retry = RETRY
|
||||||
elif retry == 0:
|
elif retry == 0:
|
||||||
|
@ -51,16 +56,22 @@ def check_solr_connection(retry=None):
|
||||||
time.sleep(10)
|
time.sleep(10)
|
||||||
check_solr_connection(retry = retry - 1)
|
check_solr_connection(retry = retry - 1)
|
||||||
else:
|
else:
|
||||||
eval(connection.read())
|
import re
|
||||||
|
conn_info = connection.read()
|
||||||
|
conn_info = re.sub(r'"zkConnected":true', '"zkConnected":True', conn_info)
|
||||||
|
eval(conn_info)
|
||||||
|
|
||||||
def init_db():
|
def init_db():
|
||||||
|
|
||||||
db_command = ['paster', '--plugin=ckan', 'db',
|
print '[prerun] Start init_db...'
|
||||||
'init', '-c', ckan_ini]
|
|
||||||
print '[prerun] Initializing or upgrading db - start'
|
db_command = ['paster', '--plugin=ckan', 'db', 'init', '-c', ckan_ini]
|
||||||
|
|
||||||
|
print '[prerun] Initializing or upgrading db - start using paster db init'
|
||||||
try:
|
try:
|
||||||
|
# run init scripts
|
||||||
subprocess.check_output(db_command, stderr=subprocess.STDOUT)
|
subprocess.check_output(db_command, stderr=subprocess.STDOUT)
|
||||||
|
|
||||||
print '[prerun] Initializing or upgrading db - end'
|
print '[prerun] Initializing or upgrading db - end'
|
||||||
except subprocess.CalledProcessError, e:
|
except subprocess.CalledProcessError, e:
|
||||||
if 'OperationalError' in e.output:
|
if 'OperationalError' in e.output:
|
||||||
|
@ -72,10 +83,12 @@ def init_db():
|
||||||
else:
|
else:
|
||||||
print e.output
|
print e.output
|
||||||
raise e
|
raise e
|
||||||
|
print '[prerun] Initializing or upgrading db - finish'
|
||||||
|
|
||||||
def create_sysadmin():
|
def create_sysadmin():
|
||||||
|
|
||||||
|
print '[prerun] Start create_sysadmin...'
|
||||||
|
|
||||||
name = os.environ.get('CKAN_SYSADMIN_NAME')
|
name = os.environ.get('CKAN_SYSADMIN_NAME')
|
||||||
password = os.environ.get('CKAN_SYSADMIN_PASSWORD')
|
password = os.environ.get('CKAN_SYSADMIN_PASSWORD')
|
||||||
email = os.environ.get('CKAN_SYSADMIN_EMAIL')
|
email = os.environ.get('CKAN_SYSADMIN_EMAIL')
|
||||||
|
@ -108,7 +121,6 @@ def create_sysadmin():
|
||||||
subprocess.call(command)
|
subprocess.call(command)
|
||||||
print '[prerun] Made user {0} a sysadmin'.format(name)
|
print '[prerun] Made user {0} a sysadmin'.format(name)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|
||||||
maintenance = os.environ.get('MAINTENANCE_MODE', '').lower() == 'true'
|
maintenance = os.environ.get('MAINTENANCE_MODE', '').lower() == 'true'
|
||||||
|
@ -120,3 +132,4 @@ if __name__ == '__main__':
|
||||||
check_solr_connection()
|
check_solr_connection()
|
||||||
init_db()
|
init_db()
|
||||||
create_sysadmin()
|
create_sysadmin()
|
||||||
|
#time.sleep(60000) # don't end the prerun script to allow container dock and debug
|
||||||
|
|
Loading…
Reference in New Issue