Ubuntu Pastebin

Paste from Cory at Fri, 11 Dec 2015 15:06:36 +0000

Download as text
 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
# Copyright 2015 Canonical Ltd.
#
# This file is part of the PostgreSQL Charm for Juju.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 3, as
# published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranties of
# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
# PURPOSE.  See the GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

import glob
import os.path

from charmhelpers import context
from charmhelpers.core import hookenv, host, templating

from charms.reactive.decorators import when
from charms.reactive.helpers import data_changed
from charms.reactive.bus import set_state, remove_state


@when('syslog.available', 'postgresql.cluster.configured')
def configure_syslog(syslog, pgsql):
    loggers = syslog.get_loggers()
    log_line_prefix = pgsql.get_log_line_prefix()
    state = {'loggers': loggers, 'llp': log_line_prefix}
    if not data_changed('syslog.state', state):
        return
    programname = hookenv.local_unit().replace('/', '_')
    for remote_unit, remote_addr in loggers.items():
        conf_path = _rsyslog_conf_path(remote_unit)
        templating.render('rsyslog_forward.conf', conf_path,
                          dict(local_unit=hookenv.local_unit(),
                               remote_unit=remote_unit,
                               remote_addr=remote_addr,
                               programname=programname))
        syslog.send_config(remote_unit, programname, log_line_prefix)
    set_state('syslog.needs_restart')
    

def _rsyslog_conf_path(self, remote_unit):
    # Use both the local unit and remote unit in the config file
    # path to avoid conflicts with subordinates.
    rsyslog_conf_dir = '/etc/rsyslog.d'
    local = hookenv.local_unit().replace('/', '_')
    remote = remote_unit.replace('/', '_')
    return os.path.join(rsyslog_conf_dir,
                        'juju-{}-{}.conf'.format(local, remote))

@when('syslog.needs_restart')
def restart_rsyslog():
    host.service_restart('rsyslog')
    remove_state('syslog.needs_restart')
Download as text