Files
@ 331f775512a6
Branch filter:
Location: rattail-project/rattail/fabfile.py - annotation
331f775512a6
4.5 KiB
text/x-python
Added (Linux) file monitor configuration to Fabric script.
Also improved `create_user` to allow overwriting some settings.
Also improved `create_user` to allow overwriting some settings.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 | ce10ee7d7ef8 ce10ee7d7ef8 ce10ee7d7ef8 ce10ee7d7ef8 ce10ee7d7ef8 ce10ee7d7ef8 ce10ee7d7ef8 ce10ee7d7ef8 ce10ee7d7ef8 ce10ee7d7ef8 ce10ee7d7ef8 ce10ee7d7ef8 ce10ee7d7ef8 ce10ee7d7ef8 ce10ee7d7ef8 ce10ee7d7ef8 ce10ee7d7ef8 ce10ee7d7ef8 ce10ee7d7ef8 ce10ee7d7ef8 ce10ee7d7ef8 ce10ee7d7ef8 ce10ee7d7ef8 ce10ee7d7ef8 ce10ee7d7ef8 b24cd9b8fac0 ce10ee7d7ef8 ce10ee7d7ef8 331f775512a6 ce10ee7d7ef8 ce10ee7d7ef8 ce10ee7d7ef8 ce10ee7d7ef8 ce10ee7d7ef8 331f775512a6 331f775512a6 331f775512a6 331f775512a6 331f775512a6 331f775512a6 331f775512a6 331f775512a6 331f775512a6 331f775512a6 331f775512a6 331f775512a6 331f775512a6 331f775512a6 331f775512a6 331f775512a6 331f775512a6 331f775512a6 331f775512a6 331f775512a6 331f775512a6 331f775512a6 331f775512a6 331f775512a6 331f775512a6 331f775512a6 331f775512a6 331f775512a6 331f775512a6 ce10ee7d7ef8 ce10ee7d7ef8 ce10ee7d7ef8 ce10ee7d7ef8 ce10ee7d7ef8 ce10ee7d7ef8 b24cd9b8fac0 4ae4989cb7e7 ce10ee7d7ef8 ce10ee7d7ef8 ce10ee7d7ef8 ce10ee7d7ef8 ce10ee7d7ef8 ce10ee7d7ef8 ce10ee7d7ef8 0128177a4f14 0128177a4f14 0128177a4f14 331f775512a6 0128177a4f14 0128177a4f14 0128177a4f14 0128177a4f14 331f775512a6 331f775512a6 331f775512a6 331f775512a6 331f775512a6 331f775512a6 331f775512a6 331f775512a6 331f775512a6 331f775512a6 331f775512a6 331f775512a6 331f775512a6 331f775512a6 331f775512a6 331f775512a6 331f775512a6 331f775512a6 331f775512a6 331f775512a6 331f775512a6 331f775512a6 331f775512a6 331f775512a6 331f775512a6 331f775512a6 331f775512a6 331f775512a6 331f775512a6 331f775512a6 331f775512a6 331f775512a6 331f775512a6 331f775512a6 331f775512a6 331f775512a6 331f775512a6 331f775512a6 331f775512a6 331f775512a6 331f775512a6 331f775512a6 331f775512a6 331f775512a6 331f775512a6 331f775512a6 331f775512a6 331f775512a6 331f775512a6 331f775512a6 331f775512a6 331f775512a6 331f775512a6 331f775512a6 331f775512a6 331f775512a6 331f775512a6 331f775512a6 331f775512a6 331f775512a6 331f775512a6 | #!/usr/bin/env python
# -*- coding: utf-8 -*-
################################################################################
#
# Rattail -- Retail Software Framework
# Copyright © 2010-2012 Lance Edgar
#
# This file is part of Rattail.
#
# Rattail is free software: you can redistribute it and/or modify it under the
# terms of the GNU Affero General Public License as published by the Free
# Software Foundation, either version 3 of the License, or (at your option)
# any later version.
#
# Rattail is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for
# more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with Rattail. If not, see <http://www.gnu.org/licenses/>.
#
################################################################################
import os.path
import shutil
from fabric.api import *
from fabric.contrib.files import exists, upload_template
execfile(os.path.join(os.path.dirname(__file__), 'rattail', '_version.py'))
def get_overwrite(overwrite=None):
"""
Obtain a canonical "overwrite" directive.
"""
if overwrite in (True, False):
return overwrite
if overwrite is None:
overwrite = raw_input("Overwrite as needed? [y/N]: ")
overwrite = overwrite.strip().lower()
else:
overwrite = overwrite.lower()
return overwrite.startswith('y')
def prettify(text):
"""
Return a "prettified" version of text.
This is basically copied from ``edbob.util``.
"""
text = text.replace('_', ' ')
text = text.replace('-', ' ')
words = text.split()
return ' '.join([x.capitalize() for x in words])
@task
def release():
"""
Release a new version of 'rattail'.
"""
shutil.rmtree('rattail.egg-info')
local('python setup.py sdist --formats=gztar register upload')
filename = 'rattail-{0}.tar.gz'.format(__version__)
put(os.path.join('dist', filename), '/srv/pypi/{0}'.format(filename))
with cd('/srv/pypi'):
run('rm --recursive --force simple')
run('compoze index')
@task
def create_user(overwrite=None):
"""
Create the 'rattail' user account.
"""
overwrite = get_overwrite(overwrite)
with settings(warn_only=True):
result = run('id rattail')
if result.return_code: # user doesn't exist
sudo('adduser --system --home /var/lib/rattail --group rattail')
elif overwrite:
sudo('usermod --home /var/lib/rattail --move-home --shell /bin/false rattail')
@task
def configure_filemon(name=None, desc=None, envdir=None, overwrite=None):
"""
Configure a Rattail File Monitor daemon.
"""
if name is None:
default_name = 'rattail-filemon'
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('filemon', 'file-monitor'))
desc = raw_input("Enter a description [{0}]: ".format(default_desc))
desc = desc.strip() or default_desc
if envdir is None:
default_envdir = name.replace('-filemon', '')
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)
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/lib/rattail/init.d/filemon') or overwrite:
put('data/var/lib/rattail/init.d/filemon', '/var/lib/rattail/init.d', use_sudo=True)
sudo('chown rattail: /var/lib/rattail/init.d/filemon')
script = '/etc/init.d/{0}'.format(name)
if not exists(script) or overwrite:
upload_template('data/etc/init.d/rattail-filemon_tmpl', script,
context=locals(), use_sudo=True, mode=0755)
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')
|