Changeset bac7876 in rattail-fabric2


Ignore:
Timestamp:
02/19/19 22:36:35 (10 months ago)
Author:
Lance Edgar <ledgar@…>
Branches:
master
Children:
72c03a8
Parents:
0a33e75
git-author:
Lance Edgar <ledgar@…> (02/19/19 22:36:24)
git-committer:
Lance Edgar <ledgar@…> (02/19/19 22:36:35)
Message:

Fix how we run sudo commands as postgres user

File:
1 edited

Legend:

Unmodified
Added
Removed
  • rattail_fabric2/postgresql.py

    r0a33e75 rbac7876  
    4343    Execute some SQL as the 'postgres' user.
    4444    """
    45     cmd = 'sudo -u postgres psql {port} --tuples-only --no-align --command="{sql}" {database}'.format(
     45    cmd = 'psql {port} --tuples-only --no-align --command="{sql}" {database}'.format(
    4646        port='--port={}'.format(port) if port else '',
    4747        sql=sql, database=database)
    48     return c.sudo(cmd, shell=False)
     48    return c.sudo(cmd, user='postgres')
    4949
    5050
     
    6262    """
    6363    if not checkfirst or not user_exists(c, name, port=port):
    64         c.sudo('sudo -u postgres createuser {port} {createdb} --no-createrole --no-superuser {name}'.format(
     64        cmd = 'createuser {port} {createdb} --no-createrole --no-superuser {name}'.format(
    6565            port='--port={}'.format(port) if port else '',
    6666            createdb='--{}createdb'.format('' if createdb else 'no-'),
    67             name=name))
     67            name=name)
     68        c.sudo(cmd, user='postgres')
    6869        if password:
    6970            set_user_password(c, name, password, port=port)
     
    9293    """
    9394    if not checkfirst or not db_exists(c, name, port=port):
    94         cmd = 'sudo -u postgres createdb {port} {owner} {name}'.format(
     95        cmd = 'createdb {port} {owner} {name}'.format(
    9596            port='--port={}'.format(port) if port else '',
    9697            owner='--owner={}'.format(owner) if owner else '',
    9798            name=name)
    98         c.sudo(cmd)
     99        c.sudo(cmd, user='postgres')
    99100
    100101
     
    104105    """
    105106    if not checkfirst or db_exists(c, name):
    106         c.sudo('sudo -u postgres dropdb {}'.format(name))
     107        c.sudo('dropdb {}'.format(name), user='postgres')
    107108
    108109
     
    115116    c.run('touch {}.sql'.format(name))
    116117    c.run('chmod 0666 {}.sql'.format(name))
    117     c.sudo('sudo -u postgres pg_dump {port} {exclude_tables} --file={name}.sql {name}'.format(
     118    cmd = 'pg_dump {port} {exclude_tables} --file={name}.sql {name}'.format(
    118119        name=name,
    119120        port='--port={}'.format(port) if port else '',
    120         exclude_tables='--exclude-table-data={}'.format(exclude_tables) if exclude_tables else '',
    121     ))
     121        exclude_tables='--exclude-table-data={}'.format(exclude_tables) if exclude_tables else '')
     122    c.sudo(cmd, user='postgres')
    122123    c.run('gzip --force {}.sql'.format(name))
    123124    c.get('{}.sql.gz'.format(name), destination)
     
    156157    # restore database on target server
    157158    c.run('gunzip --force {}.sql.gz'.format(name))
    158     c.sudo('sudo -u postgres psql --echo-errors --file={0}.sql {0}'.format(name))
     159    c.sudo('psql --echo-errors --file={0}.sql {0}'.format(name), user='postgres')
    159160    c.run('rm {}.sql'.format(name))
Note: See TracChangeset for help on using the changeset viewer.