Add basic feature to mirror POS DB in mysql or postgresql
but only supported for Catapult so far
This commit is contained in:
parent
3e66aa79da
commit
48960d961b
7 changed files with 107 additions and 10 deletions
37
machines/theo-server/fabfile.py
vendored
37
machines/theo-server/fabfile.py
vendored
|
@ -10,7 +10,7 @@ import datetime
|
|||
from fabric2 import task
|
||||
|
||||
from rattail.core import Object
|
||||
from rattail_fabric2 import make_deploy, apt, postfix, postgresql, exists, make_system_user, mkdir
|
||||
from rattail_fabric2 import make_deploy, apt, mysql, postfix, postgresql, exists, make_system_user, mkdir
|
||||
|
||||
|
||||
env = Object()
|
||||
|
@ -54,6 +54,11 @@ def bootstrap_base(c):
|
|||
postgresql.install(c)
|
||||
postgresql.create_user(c, 'rattail', password=env.password_postgresql_rattail)
|
||||
|
||||
# mysql (maybe)
|
||||
if env.theo_mirror_posdb == 'mysql':
|
||||
mysql.install(c)
|
||||
mysql.create_user(c, 'rattail', password=env.password_mysql_rattail)
|
||||
|
||||
# python
|
||||
mkdir(c, '/srv/envs', use_sudo=True, owner='rattail:')
|
||||
apt.install(
|
||||
|
@ -132,6 +137,10 @@ def install_theo_app(c, envname, production, port, from_source=False,
|
|||
safename = envname.replace('-', '_')
|
||||
envroot = '/srv/envs/{}'.format(envname)
|
||||
|
||||
mirrordb = None
|
||||
if env.theo_integrates_with == 'catapult':
|
||||
mirrordb = 'catapult-mirror' if production else 'catapult-mirror-stage'
|
||||
|
||||
c.sudo('supervisorctl stop {}:'.format(safename), warn=True)
|
||||
|
||||
# virtualenv
|
||||
|
@ -143,6 +152,8 @@ def install_theo_app(c, envname, production, port, from_source=False,
|
|||
context={'env': env, 'envroot': envroot})
|
||||
c.sudo('touch {}/pip.log'.format(envroot), user='rattail')
|
||||
c.sudo('chmod 0600 {}/pip.log'.format(envroot))
|
||||
c.sudo('PIP_CONFIG_FILE={0}/pip.conf {0}/bin/pip install ipdb'.format(envroot),
|
||||
user='rattail')
|
||||
|
||||
# theo
|
||||
if from_source:
|
||||
|
@ -168,7 +179,8 @@ def install_theo_app(c, envname, production, port, from_source=False,
|
|||
# config
|
||||
deploy(c, 'theo-common/rattail.conf.mako', '{}/app/rattail.conf'.format(envroot),
|
||||
use_sudo=True, owner='rattail:', mode='0600',
|
||||
context={'env': env, 'envroot': envroot, 'dbname': dbname, 'production': production})
|
||||
context={'env': env, 'envroot': envroot, 'dbname': dbname,
|
||||
'production': production, 'mirrordb': mirrordb})
|
||||
if not exists(c, '{}/app/quiet.conf'.format(envroot)):
|
||||
c.sudo("bash -c 'cd {} && bin/rattail make-config -T quiet -O app/'".format(envroot),
|
||||
user='rattail')
|
||||
|
@ -178,6 +190,10 @@ def install_theo_app(c, envname, production, port, from_source=False,
|
|||
deploy(c, 'theo-common/cron.conf.mako', '{}/app/cron.conf'.format(envroot),
|
||||
use_sudo=True, owner='rattail:',
|
||||
context={'envroot': envroot})
|
||||
if env.theo_mirror_posdb:
|
||||
if env.theo_integrates_with == 'catapult':
|
||||
deploy(c, 'theo-common/catapult-mirror.conf', '{}/app/catapult-mirror.conf'.format(envroot),
|
||||
use_sudo=True, owner='rattail:')
|
||||
|
||||
# scripts
|
||||
deploy(c, 'theo-common/upgrade.sh.mako', '{}/app/upgrade.sh'.format(envroot),
|
||||
|
@ -200,6 +216,10 @@ def install_theo_app(c, envname, production, port, from_source=False,
|
|||
deploy(c, 'theo-common/import-catapult-first.sh.mako', '{}/app/import-catapult-first.sh'.format(envroot),
|
||||
use_sudo=True, owner='rattail:', mode='0755',
|
||||
context={'envroot': envroot})
|
||||
if env.theo_mirror_posdb:
|
||||
deploy(c, 'theo-common/mirror-catapult-first.sh.mako', '{}/app/mirror-catapult-first.sh'.format(envroot),
|
||||
use_sudo=True, owner='rattail:', mode='0755',
|
||||
context={'envroot': envroot})
|
||||
elif env.theo_integrates_with == 'locsms':
|
||||
deploy(c, 'theo-common/import-locsms-first.sh.mako', '{}/app/import-locsms-first.sh'.format(envroot),
|
||||
use_sudo=True, owner='rattail:', mode='0755',
|
||||
|
@ -241,6 +261,19 @@ def install_theo_app(c, envname, production, port, from_source=False,
|
|||
c.sudo("bash -c 'cd {} && bin/rattail -c app/quiet.conf --runas theo make-user --no-password locsms'".format(envroot),
|
||||
user='rattail')
|
||||
|
||||
# tweaks for mirror DB
|
||||
if env.theo_mirror_posdb and env.theo_integrates_with == 'catapult':
|
||||
postgresql.sql(c, "insert into setting values ('tailbone.engines.catapult.pretend_default', 'mirror')",
|
||||
database=dbname)
|
||||
|
||||
# maybe establish the mirror DB
|
||||
if env.theo_mirror_posdb == 'mysql':
|
||||
if env.theo_integrates_with == 'catapult':
|
||||
if not mysql.db_exists(c, mirrordb):
|
||||
mysql.create_db(c, mirrordb, checkfirst=False, user='rattail@localhost')
|
||||
c.sudo("bash -c 'cd {} && bin/alembic -c app/catapult-mirror.conf upgrade heads'".format(envroot),
|
||||
user='rattail')
|
||||
|
||||
# supervisor
|
||||
deploy(c, 'theo-common/supervisor.conf.mako', '/etc/supervisor/conf.d/{}.conf'.format(safename),
|
||||
use_sudo=True, context={'envroot': envroot, 'safename': safename})
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue