Esempio n. 1
0
def install_tmpfilesd():
    '''Install systemd-tmpfiles configuration for ovs vhost-user sockets'''
    # NOTE(jamespage): Only do this if libvirt is actually installed
    if (init_is_systemd() and user_exists('libvirt-qemu')
            and group_exists('kvm')):
        shutil.copy('files/nova-ovs-vhost-user.conf', '/etc/tmpfiles.d')
        subprocess.check_call(['systemd-tmpfiles', '--create'])
def create_user_and_group_if_not_exists(user, group):
    """Create documize user & group if not exists
    """
    if not group_exists(group):
        add_group(group)
    if not user_exists(user):
        adduser(user, system_user=True)
Esempio n. 3
0
def _install_mattermost():
    # Backup existing installation if it exists
    backup_path = None
    if os.path.isdir('/opt/mattermost'):
        backup_path = "/opt/mattermost.back{}".format(str(datetime.datetime.now()))
        shutil.move('/opt/mattermost', backup_path)
    # Create mattermost user & group if not exists
    if not group_exists('mattermost'):
        add_group("mattermost")
    if not user_exists('mattermost'):
        adduser("mattermost", system_user=True)
    # Get and uppack resource
    mattermost_bdist = resource_get('bdist')
    extract_tarfile(mattermost_bdist, destpath="/opt")

    # Render systemd template
    render(source="mattermost.service.tmpl",
           target="/etc/systemd/system/mattermost.service",
           perms=0o644,
           owner="root",
           context={})
    check_call(['systemctl', 'daemon-reload'])
    if backup_path:
        shutil.move(
            '{}/config/config.json'.format(backup_path),
            '/opt/mattermost/config/config.json')
        shutil.move(
            '{}/data'.format(backup_path),
            '/opt/mattermost/')
    # Create dirs that don't exist yet
    for folder in ("data", "logs", "config"):
        os.makedirs("/opt/mattermost/{}".format(folder),
                    mode=0o700,
                    exist_ok=True)
    chownr("/opt/mattermost", "mattermost", "mattermost", chowntopdir=True)
Esempio n. 4
0
def _install_mattermost():
    # Backup existing installation if it exists
    backup_path = None
    if os.path.isdir('/opt/mattermost'):
        backup_path = "/opt/mattermost.back{}".format(
            str(datetime.datetime.now()))
        shutil.move('/opt/mattermost', backup_path)
    # Create mattermost user & group if not exists
    if not group_exists('mattermost'):
        add_group("mattermost")
    if not user_exists('mattermost'):
        adduser("mattermost", system_user=True)
    # Get and uppack resource
    mattermost_bdist = resource_get('bdist')
    extract_tarfile(mattermost_bdist, destpath="/opt")

    # Render systemd template
    render(source="mattermost.service.tmpl",
           target="/etc/systemd/system/mattermost.service",
           perms=0o644,
           owner="root",
           context={})
    check_call(['systemctl', 'daemon-reload'])
    if backup_path:
        shutil.move('{}/config/config.json'.format(backup_path),
                    '/opt/mattermost/config/config.json')
        shutil.move('{}/data'.format(backup_path), '/opt/mattermost/')
    # Create dirs that don't exist yet
    for folder in ("data", "logs", "config"):
        os.makedirs("/opt/mattermost/{}".format(folder),
                    mode=0o700,
                    exist_ok=True)
    chownr("/opt/mattermost", "mattermost", "mattermost", chowntopdir=True)
def install_tmpfilesd():
    '''Install systemd-tmpfiles configuration for ovs vhost-user sockets'''
    # NOTE(jamespage): Only do this if libvirt is actually installed
    if (init_is_systemd() and
            user_exists('libvirt-qemu') and
            group_exists('kvm')):
        shutil.copy('files/nova-ovs-vhost-user.conf',
                    '/etc/tmpfiles.d')
        subprocess.check_call(['systemd-tmpfiles', '--create'])
def create_prometheus_user():
    if not group_exists('prometheus'):
        add_group('prometheus', system_group=True)
    if not user_exists('prometheus'):
        adduser(
            'prometheus',
            shell='/bin/false',
            system_user=True,
            primary_group='prometheus',
            home_dir='/var/lib/prometheus',
        )
    set_state('prometheus.user.available')
 def configure_installdir(self):
     ''' Create and fix permissions on install dir'''
     if not os.path.exists(self.installdir):
         os.makedirs(self.installdir)
     hookenv.log("Fixing data dir permissions: {}".format(
         self.installdir), 'DEBUG')
     if host.user_exists(self.user) and host.group_exists(self.user):
         host.chownr(self.installdir, self.user,
                     self.user, chowntopdir=True)
     else:
         hookenv.log("Skipping chown because user/group {} is missing".format(
             self.installdir), 'DEBUG')
Esempio n. 8
0
def fix_supervisord():
    # setup supervisord
    if not user_exists('contrail'):
        adduser('contrail', system_user=True)

    shutil.copy('files/supervisor-webui.conf', '/etc/init')
    shutil.copy('files/supervisord_webui.conf', '/etc/contrail')
    pw = pwd.getpwnam('contrail')
    os.chown('/etc/contrail/supervisord_webui.conf', pw.pw_uid, pw.pw_gid)
    mkdir('/etc/contrail/supervisord_webui_files', owner='contrail',
          group='contrail', perms=0o755)

    mkdir('/var/log/contrail', owner='contrail', group='adm', perms=0o750)
Esempio n. 9
0
    def perms():
        for p in paths:
            makedirs(p[0], exist_ok=True)

            try:
                getgrnam(p[2])
            except KeyError:
                add_group(p[2], system_group=True)

            if not user_exists(p[1]):
                adduser(p[1], shell='/bin/false', system_user=True,
                        primary_group=p[2])

            # Ensure path is owned appropriately
            chownr(path=p[0], owner=p[1], group=p[2], chowntopdir=True)
Esempio n. 10
0
def fix_supervisord():
    # setup supervisord
    if not user_exists('contrail'):
        adduser('contrail', system_user=True)

    shutil.copy('files/supervisor-webui.conf', '/etc/init')
    shutil.copy('files/supervisord_webui.conf', '/etc/contrail')
    pw = pwd.getpwnam('contrail')
    os.chown('/etc/contrail/supervisord_webui.conf', pw.pw_uid, pw.pw_gid)
    mkdir('/etc/contrail/supervisord_webui_files',
          owner='contrail',
          group='contrail',
          perms=0o755)

    mkdir('/var/log/contrail', owner='contrail', group='adm', perms=0o750)
Esempio n. 11
0
    def perms():
        for p in paths:
            makedirs(p[0], exist_ok=True)

            try:
                getgrnam(p[2])
            except KeyError:
                add_group(p[2], system_group=True)

            if not user_exists(p[1]):
                adduser(p[1],
                        shell='/bin/false',
                        system_user=True,
                        primary_group=p[2])

            # Ensure path is owned appropriately
            chownr(path=p[0], owner=p[1], group=p[2], chowntopdir=True)
def install_mattermost():
    """Grab the mattermost binary, unpack, install
    to /srv.
    """

    status_set('maintenance', "Installing Mattermost")

    # Create mattermost user & group if not exists
    if not group_exists('mattermost'):
        add_group("mattermost")
    if not user_exists('mattermost'):
        adduser("mattermost", system_user=True)

    # Get and uppack resource
    if os.path.exists('/srv/mattermost'):
        shutil.rmtree('/srv/mattermost')

    mattermost_bdist = resource_get('bdist')
    extract_tarfile(mattermost_bdist, destpath="/srv")

    # Create data + log + config dirs
    for dir in ("data", "logs", "config"):
        os.makedirs(os.path.join("/srv/mattermost", dir),
                    mode=0o700,
                    exist_ok=True)
        shutil.chown(os.path.join("/srv/mattermost", dir),
                     user="******",
                     group="mattermost")

    # Render systemd template
    render(source="mattermost.service.tmpl",
           target="/etc/systemd/system/mattermost.service",
           perms=0o644,
           owner="root",
           context={})
    check_call(['systemctl', 'daemon-reload'])
    set_state('mattermost.installed')
    status_set('active', 'Mattermost installation complete')
def get_user():
    """Helper to ensure our user exists and return the username.
    """
    if not user_exists(USER):
        adduser(USER, shell='/bin/false', system_user=True)
    return USER
Esempio n. 14
0
def install_etcd():
    ''' Attempt resource get on the "etcd" and "etcdctl" resources. If no
    resources are provided attempt to install from the archive only on the
    16.04 (xenial) series. '''
    status_set('maintenance', 'Installing etcd.')

    codename = host.lsb_release()['DISTRIB_CODENAME']

    try:
        etcd_path = resource_get('etcd')
        etcdctl_path = resource_get('etcdctl')
    # Not obvious but this blocks juju 1.25 clients
    except NotImplementedError:
        status_set(
            'blocked',
            'This charm requires the resource feature available in juju 2+'
        )  # noqa
        return

    if not etcd_path or not etcdctl_path:
        if codename == 'xenial':
            # edge case where archive allows us a nice fallback on xenial
            status_set('maintenance', 'Attempting install of etcd from apt')
            pkg_list = ['etcd']
            apt_update()
            apt_install(pkg_list, fatal=True)
            # Stop the service and remove the defaults
            # I hate that I have to do this. Sorry short-lived local data #RIP
            # State control is to prevent upgrade-charm from nuking cluster
            # data.
            if not is_state('etcd.package.adjusted'):
                host.service('stop', 'etcd')
                if os.path.exists('/var/lib/etcd/default'):
                    shutil.rmtree('/var/lib/etcd/default')
                set_state('etcd.package.adjusted')
            set_state('etcd.installed')
            return
        else:
            # edge case
            status_set('blocked', 'Missing Resource: see README')
    else:
        install(etcd_path, '/usr/bin/etcd')
        install(etcdctl_path, '/usr/bin/etcdctl')

        host.add_group('etcd')

        if not host.user_exists('etcd'):
            host.adduser('etcd')
            host.add_user_to_group('etcd', 'etcd')

        os.makedirs('/var/lib/etcd/', exist_ok=True)
        etcd_uid = getpwnam('etcd').pw_uid

        os.chmod('/var/lib/etcd/', 0o775)
        os.chown('/var/lib/etcd/', etcd_uid, -1)

        # Trusty was the EOL for upstart, render its template if required
        if codename == 'trusty':
            render('upstart',
                   '/etc/init/etcd.conf', {},
                   owner='root',
                   group='root')
            set_state('etcd.installed')
            return

        if not os.path.exists('/etc/systemd/system/etcd.service'):
            render('systemd',
                   '/etc/systemd/system/etcd.service', {},
                   owner='root',
                   group='root')
            # This will cause some greif if its been run before
            # so allow it to be chatty and fail if we ever re-render
            # and attempt re-enablement.
            try:
                check_call(split('systemctl enable etcd'))
            except CalledProcessError:
                pass

        set_state('etcd.installed')