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
|
@ -1,6 +1,6 @@
|
|||
## -*- mode: conf; -*-
|
||||
|
||||
[catapult-default]
|
||||
[catapult-production]
|
||||
host = ${env.catapult_host}
|
||||
port = 2638
|
||||
# https://www.freetds.org/userguide/ChoosingTdsProtocol.html
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
|
||||
[catapult-default]
|
||||
[catapult-production]
|
||||
Description = ECRS Catapult
|
||||
Driver = /usr/local/lib/libtdsodbc.so
|
||||
ServerName = catapult-default
|
||||
ServerName = catapult-production
|
||||
ServerDSN = prototype
|
||||
|
||||
# [catapult-tj-default]
|
||||
|
|
23
machines/theo-server/deploy/theo-common/catapult-mirror.conf
Normal file
23
machines/theo-server/deploy/theo-common/catapult-mirror.conf
Normal file
|
@ -0,0 +1,23 @@
|
|||
|
||||
############################################################
|
||||
#
|
||||
# config for Catapult "mirror" DB
|
||||
#
|
||||
############################################################
|
||||
|
||||
|
||||
##############################
|
||||
# rattail
|
||||
##############################
|
||||
|
||||
[rattail.config]
|
||||
include = %(here)s/rattail.conf
|
||||
|
||||
|
||||
##############################
|
||||
# alembic
|
||||
##############################
|
||||
|
||||
[alembic]
|
||||
script_location = rattail_onager.catapult.db:alembic
|
||||
version_locations = rattail_onager.catapult.db:alembic/versions
|
16
machines/theo-server/deploy/theo-common/mirror-catapult-first.sh.mako
Executable file
16
machines/theo-server/deploy/theo-common/mirror-catapult-first.sh.mako
Executable file
|
@ -0,0 +1,16 @@
|
|||
#!/bin/sh -e
|
||||
|
||||
# sanity check
|
||||
if [ "$USER" != 'rattail' ]; then
|
||||
echo ''
|
||||
echo "Please run this script as 'rattail' user:"
|
||||
echo ''
|
||||
echo " sudo -u rattail $0"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
cd ${envroot}
|
||||
|
||||
RATTAIL_ONAGER='bin/rattail-onager -c app/quiet.conf -P --no-versioning'
|
||||
|
||||
$RATTAIL_ONAGER import-catapult --dbkey production --warnings
|
|
@ -45,8 +45,23 @@ default.pool_recycle = 3600
|
|||
# Catapult
|
||||
<%text>##############################</%text>
|
||||
|
||||
[catapult]
|
||||
url = https://${env.catapult_host}/weboffice/
|
||||
|
||||
[catapult.db]
|
||||
default.url = catapult://${env.catapult_odbc_username}:${env.catapult_odbc_password}@catapult-default
|
||||
% if env.theo_mirror_posdb == 'mysql':
|
||||
keys = default, mirror, production
|
||||
default.url = mysql+mysqlconnector://rattail:${env.password_mysql_rattail}@localhost/${mirrordb}
|
||||
mirror.url = mysql+mysqlconnector://rattail:${env.password_mysql_rattail}@localhost/${mirrordb}
|
||||
production.url = catapult://${env.catapult_odbc_username}:${env.catapult_odbc_password}@catapult-production
|
||||
% elif env.theo_mirror_posdb == 'postgresql':
|
||||
keys = default, mirror, production
|
||||
default.url = postgresql://rattail:${env.password_postgresql_rattail}@localhost/${mirrordb}
|
||||
mirror.url = postgresql://rattail:${env.password_postgresql_rattail}@localhost/${mirrordb}
|
||||
production.url = catapult://${env.catapult_odbc_username}:${env.catapult_odbc_password}@catapult-production
|
||||
% else:
|
||||
default.url = catapult://${env.catapult_odbc_username}:${env.catapult_odbc_password}@catapult-production
|
||||
% endif
|
||||
|
||||
## end catapult
|
||||
% endif
|
||||
|
|
|
@ -21,20 +21,27 @@ env.machine_is_live = False
|
|||
# stable
|
||||
##############################
|
||||
|
||||
# for a list of possible time zone values, see
|
||||
# https://en.wikipedia.org/wiki/List_of_tz_database_time_zones#List
|
||||
env.timezone = 'America/Chicago'
|
||||
|
||||
# set this to the POS system you wish to integrate with, if any
|
||||
env.theo_integrates_with = None
|
||||
#env.theo_integrates_with = 'corepos'
|
||||
#env.theo_integrates_with = 'catapult'
|
||||
#env.theo_integrates_with = 'locsms'
|
||||
|
||||
# if you wish to "mirror" your POS DB, set this to the type of DB service which
|
||||
# should contain the mirror. this mirror DB will exist alongside Theo, i.e. on
|
||||
# the same machine. (note that this feature only works for Catapult)
|
||||
env.theo_mirror_posdb = None
|
||||
#env.theo_mirror_posdb = 'mysql'
|
||||
#env.theo_mirror_posdb = 'postgresql'
|
||||
|
||||
# default admin user credentials for Theo web app
|
||||
env.theo_admin_username = 'username'
|
||||
env.theo_admin_password = 'password'
|
||||
|
||||
# for a list of possible time zone values, see
|
||||
# https://en.wikipedia.org/wiki/List_of_tz_database_time_zones#List
|
||||
env.timezone = 'America/Chicago'
|
||||
|
||||
# default sender and recipients for all emails
|
||||
env.email_default_sender = 'rattail@localhost'
|
||||
env.email_default_recipients = ['root@localhost']
|
||||
|
@ -42,6 +49,9 @@ env.email_default_recipients = ['root@localhost']
|
|||
# this is for the 'rattail' user within PostgreSQL
|
||||
env.password_postgresql_rattail = 'password'
|
||||
|
||||
# this is for the 'rattail' user within MySQL (if needed for mirror DB)
|
||||
env.password_mysql_rattail = 'password'
|
||||
|
||||
# this is used to secure the user session and/or cookie for the web app
|
||||
env.theo_beaker_secret = 'ABCDEFGHIJKLMNOPQRST'
|
||||
|
||||
|
|
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…
Reference in a new issue