Example #1
0
    def repmgr(self, args):
        args = vars(args)
        environ = os.environ.copy()
        environ['PATH'] = '/usr/lib/pgclust:' + environ['PATH']
        (psqlstatus, psqout) = shell('sudo /etc/init.d/postgresql status', err=True, retcode=True, environment=environ)

        cmd = 'sudo -u postgres PATH="' + environ['PATH'] + '" repmgr'
        if args['type'] == 'master' and args['action'] == 'stop':
            (retcode, output) = shell('sudo /etc/init.d/postgresql stop', err=True, retcode=True)
            return retcode

        if args['type'] == 'master' and args['action'] != 'register':
            raise Exception('Incorrect action "%s" for type master' % (args['action'],))
        if args['action'] != 'clone':
            # If postgres is not running - start
            if psqlstatus != 0:
                shell('sudo /etc/init.d/postgresql start')
            cmd += ' -f /etc/postgresql/9.1/main/repmgr.conf %(type)s %(action)s' % args
        else:
            if args['node'] == '':
                raise Exception('Node to clone from should be specified when performing "standby clone" action')
            shell('sudo /etc/init.d/postgresql stop')
            cmd += ' -D /var/lib/postgresql/9.1/main -d repmgr -p 5432 -U repmgr -R postgres --verbose --force standby clone %(node)s' % args

        (retcode, output) = shell(cmd, err=True, retcode=True, environment=environ)
        if args['action'] == 'clone' and retcode == 0:
            (retcode, output1) = shell('sudo /etc/init.d/postgresql start', err=True, retcode=True)
            output += output1
        print output
        return retcode
Example #2
0
    def remove(self, args):
        args = vars(args)
        names = []
        nodes = self.config.nodes()
        conf = self.config.config()
        if args['type'] == 'cluster':
            names = nodes
        elif args['type'] == 'master':
            names = filter(lambda x: conf[x]['type'] == 'master', nodes)
        elif args['type'] == 'slave':
            names = filter(lambda x: conf[x]['type'] == 'slave', nodes)
        else:
            names = [args['type'],]

        for name in names:
            if not name in self.config.nodes():
                raise Exception('Such node does not exist')
            node = self.config.config(name)
            self.config.remove_node(name)
            self.config.save()
            shell('rm -rf "%(privkey)s" "%(pubkey)s"' % node)
Example #3
0
 def run(self, cmd):
     if self.node['local'] == 'true':
         return local.shell(cmd)
     else:
         return self.connection.execute(cmd)