diff --git a/machines/theo-server/deploy/rattail/catapult/freetds.conf.mako b/machines/theo-server/deploy/rattail/catapult/freetds.conf.mako index 6f7a235..33f85ed 100644 --- a/machines/theo-server/deploy/rattail/catapult/freetds.conf.mako +++ b/machines/theo-server/deploy/rattail/catapult/freetds.conf.mako @@ -1,6 +1,6 @@ ## -*- mode: conf; -*- -[catapult-default] +[catapult-production] host = ${env.catapult_host} port = 2638 # https://www.freetds.org/userguide/ChoosingTdsProtocol.html diff --git a/machines/theo-server/deploy/rattail/catapult/odbc.ini b/machines/theo-server/deploy/rattail/catapult/odbc.ini index ffac956..89542ba 100644 --- a/machines/theo-server/deploy/rattail/catapult/odbc.ini +++ b/machines/theo-server/deploy/rattail/catapult/odbc.ini @@ -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] diff --git a/machines/theo-server/deploy/theo-common/catapult-mirror.conf b/machines/theo-server/deploy/theo-common/catapult-mirror.conf new file mode 100644 index 0000000..3554b76 --- /dev/null +++ b/machines/theo-server/deploy/theo-common/catapult-mirror.conf @@ -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 diff --git a/machines/theo-server/deploy/theo-common/mirror-catapult-first.sh.mako b/machines/theo-server/deploy/theo-common/mirror-catapult-first.sh.mako new file mode 100755 index 0000000..0f6c541 --- /dev/null +++ b/machines/theo-server/deploy/theo-common/mirror-catapult-first.sh.mako @@ -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 diff --git a/machines/theo-server/deploy/theo-common/rattail.conf.mako b/machines/theo-server/deploy/theo-common/rattail.conf.mako index e0a0e4d..6214c22 100644 --- a/machines/theo-server/deploy/theo-common/rattail.conf.mako +++ b/machines/theo-server/deploy/theo-common/rattail.conf.mako @@ -45,8 +45,23 @@ default.pool_recycle = 3600 # Catapult <%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 diff --git a/machines/theo-server/fabenv.py.dist b/machines/theo-server/fabenv.py.dist index b764f84..6c7ab0b 100644 --- a/machines/theo-server/fabenv.py.dist +++ b/machines/theo-server/fabenv.py.dist @@ -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' diff --git a/machines/theo-server/fabfile.py b/machines/theo-server/fabfile.py index 65954d9..d79cb3c 100644 --- a/machines/theo-server/fabfile.py +++ b/machines/theo-server/fabfile.py @@ -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})