aboutsummaryrefslogtreecommitdiffstats
path: root/fabtools/require
diff options
context:
space:
mode:
Diffstat (limited to 'fabtools/require')
-rw-r--r--fabtools/require/postgres.py37
-rw-r--r--fabtools/require/system.py12
2 files changed, 32 insertions, 17 deletions
diff --git a/fabtools/require/postgres.py b/fabtools/require/postgres.py
index 6a0be8e..77cfec9 100644
--- a/fabtools/require/postgres.py
+++ b/fabtools/require/postgres.py
@@ -4,12 +4,24 @@ PostgreSQL users and databases
"""
from __future__ import with_statement
-import os.path
-
-from fabtools.files import is_file
+from fabtools.files import is_file, watch
from fabtools.postgres import *
from fabtools.require.deb import package
-from fabtools.require.service import started
+from fabtools.require.service import started, restarted
+from fabtools.require.system import locale as require_locale
+
+
+def _service_name(version=None):
+
+ if is_file('/etc/init.d/postgresql'):
+ return 'postgresql'
+
+ if version and is_file('/etc/init.d/postgresql-%s' % version):
+ return 'postgresql-%s' % version
+
+ with cd('/etc/init.d'):
+ with settings(hide('running', 'stdout')):
+ return run('ls postgresql-*').splitlines()[0]
def server(version=None):
@@ -29,16 +41,7 @@ def server(version=None):
pkg_name = 'postgresql'
package(pkg_name)
- if is_file('/etc/init.d/postgresql'):
- service_name = 'postgresql'
- else:
- if version and is_file('/etc/init.d/postgresql-%s' % version):
- service_name = 'postgresql-%s' % version
- else:
- with cd('/etc/init.d'):
- with settings(hide('running', 'stdout')):
- service_name = run('ls postgresql-*').splitlines()[0]
- started(service_name)
+ started(_service_name(version))
def user(name, password):
@@ -69,5 +72,11 @@ def database(name, owner, template='template0', encoding='UTF8',
"""
if not database_exists(name):
+
+ with watch('/etc/locale.gen') as locales:
+ require_locale(locale)
+ if locales.changed:
+ restarted(_service_name())
+
create_database(name, owner, template=template, encoding=encoding,
locale=locale)
diff --git a/fabtools/require/system.py b/fabtools/require/system.py
index bb1a651..f7ff1ed 100644
--- a/fabtools/require/system.py
+++ b/fabtools/require/system.py
@@ -4,10 +4,12 @@ System settings
"""
from __future__ import with_statement
+from re import escape
+
from fabric.api import sudo, warn
-from fabric.contrib.files import append
+from fabric.contrib.files import append, uncomment
-from fabtools.files import watch
+from fabtools.files import is_file, watch
from fabtools.system import (
get_hostname, set_hostname,
get_sysctl, set_sysctl,
@@ -48,6 +50,9 @@ def locales(names):
config_file = '/var/lib/locales/supported.d/local'
+ if not is_file(config_file):
+ config_file = '/etc/locale.gen'
+
# Regenerate locales if config file changes
with watch(config_file, use_sudo=True) as config:
@@ -57,12 +62,13 @@ def locales(names):
if name in supported:
charset = supported[name]
locale = "%s %s" % (name, charset)
+ uncomment(config_file, escape(locale), use_sudo=True)
append(config_file, locale, use_sudo=True)
else:
warn('Unsupported locale name "%s"' % name)
if config.changed:
- sudo('dpkg-reconfigure locales')
+ sudo('dpkg-reconfigure --frontend=noninteractive locales')
def locale(name):