PageRenderTime 6ms CodeModel.GetById 1ms app.highlight 2ms RepoModel.GetById 1ms app.codeStats 0ms

/scripts/galaxy_messaging/server/setup_rabbitmq.py

https://bitbucket.org/cistrome/cistrome-harvard/
Python | 38 lines | 24 code | 5 blank | 9 comment | 4 complexity | e04cf8253c530741fd16b743d41ecec3 MD5 | raw file
 1#
 2# Configuration script for RabbitMQ in Galaxy
 3#
 4# Requirements:
 5# - set the rabbitmqctl_path variable in the 'galaxy_amqp' section in Galaxy config file
 6#
 7# Usage:
 8# $ python setup_rabbitmq.py <Galaxy config file>
 9#
10
11import os, sys, csv, ConfigParser
12
13def main( config_file ):
14    try:
15        config = ConfigParser.ConfigParser()
16        config.read( config_file )
17        rabbitmqctl_path = config.get( 'galaxy_amqp', 'rabbitmqctl_path' )
18        username = config.get( 'galaxy_amqp', 'userid' )
19        password = config.get( 'galaxy_amqp', 'password' )
20        virtual_host = config.get( 'galaxy_amqp', 'virtual_host' )
21    except Exception, e:
22        print 'Fatal error:', str(e)
23        sys.exit(1)
24        
25    cmd_list = [
26                'add_user %s %s' % ( username, password ),
27                'add_vhost %s' % virtual_host,
28                'set_permissions -p %s %s ".*" ".*" ".*"' % ( virtual_host, username )
29               ]
30    
31    for cmd in cmd_list:
32        retval = os.system( rabbitmqctl_path + ' ' + cmd )
33        if retval:
34            print "Failed command: %s" % cmd
35            sys.exit(1)
36    
37if __name__ == '__main__':
38    main( sys.argv[1] )