diff --git a/fabfile.py b/fabfile.py index 4a4ba4961f88d3a3bfbdaf6daf8b157d40b65dcf..2fcda520bcd76276a590b6b9c32d110d0a55a469 100644 --- a/fabfile.py +++ b/fabfile.py @@ -96,6 +96,28 @@ def create_user(overwrite=None): sudo('usermod --home /var/lib/rattail --move-home --shell /bin/false rattail') +def configure_rattail_lib(overwrite=None): + """ + Configure basic Rattail "library" files. + """ + + overwrite = get_overwrite(overwrite) + + if not exists('/etc/default/rattail') or overwrite: + put('data/etc/default/rattail', '/etc/default', use_sudo=True) + sudo('chown root: /etc/default/rattail') + + if not exists('/var/lib/rattail'): + create_user(overwrite=True) + + if not exists('/var/lib/rattail/init.d'): + sudo('mkdir /var/lib/rattail/init.d', user='rattail') + + if not exists('/var/run/rattail'): + sudo('mkdir /var/run/rattail') + sudo('chown rattail: /var/run/rattail') + + @task def configure_filemon(name=None, desc=None, envdir=None, overwrite=None): """ @@ -120,16 +142,7 @@ def configure_filemon(name=None, desc=None, envdir=None, overwrite=None): envdir = envdir.strip() or default_envdir overwrite = get_overwrite(overwrite) - - if not exists('/etc/default/rattail') or overwrite: - put('data/etc/default/rattail', '/etc/default', use_sudo=True) - sudo('chown root: /etc/default/rattail') - - if not exists('/var/lib/rattail'): - create_user(overwrite=True) - - if not exists('/var/lib/rattail/init.d'): - sudo('mkdir /var/lib/rattail/init.d', user='rattail') + configure_rattail_lib(overwrite) if not exists('/var/lib/rattail/init.d/filemon') or overwrite: put('data/var/lib/rattail/init.d/filemon', '/var/lib/rattail/init.d', use_sudo=True) @@ -142,6 +155,40 @@ def configure_filemon(name=None, desc=None, envdir=None, overwrite=None): sudo('chown root: {0}'.format(script)) sudo('insserv {0}'.format(script)) - if not exists('/var/run/rattail'): - sudo('mkdir /var/run/rattail') - sudo('chown rattail: /var/run/rattail') + +@task +def configure_dbsync(name=None, desc=None, envdir=None, overwrite=None): + """ + Configure a Rattail Database Synchonizer daemon. + """ + + if name is None: + default_name = 'rattail-dbsync' + name = raw_input("Enter a name for the service [{0}]: ".format(default_name)) + name = name.strip() or default_name + + if desc is None: + default_desc = prettify(name.replace('dbsync', 'database-synchronizer')) + desc = raw_input("Enter a description [{0}]: ".format(default_desc)) + desc = desc.strip() or default_desc + + if envdir is None: + default_envdir = name.replace('-dbsync', '') + default_envdir = default_envdir.replace('-', '.') + default_envdir = '/srv/envs/{0}'.format(default_envdir) + envdir = raw_input("Enter a virtual environment path [{0}]: ".format(default_envdir)) + envdir = envdir.strip() or default_envdir + + overwrite = get_overwrite(overwrite) + configure_rattail_lib(overwrite) + + if not exists('/var/lib/rattail/init.d/dbsync') or overwrite: + put('data/var/lib/rattail/init.d/dbsync', '/var/lib/rattail/init.d', use_sudo=True) + sudo('chown rattail: /var/lib/rattail/init.d/dbsync') + + script = '/etc/init.d/{0}'.format(name) + if not exists(script) or overwrite: + upload_template('data/etc/init.d/rattail-dbsync_tmpl', script, + context=locals(), use_sudo=True, mode=0755) + sudo('chown root: {0}'.format(script)) + sudo('insserv {0}'.format(script))