~canonical-ci-engineering/charms/precise/ubuntu-ci-services-itself/rabbitmq-server

« back to all changes in this revision

Viewing changes to hooks/rabbitmq-common

  • Committer: Adam Gandelman
  • Date: 2013-06-24 22:25:45 UTC
  • mfrom: (37.3.10 rabbitmq-server)
  • Revision ID: adamg@canonical.com-20130624222545-5p7dt00wfm5600fn
Merge HA work + Python rewrite.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#!/bin/bash
2
 
#
3
 
#  rabbitmq-common - common formula shell functions and config variables
4
 
#
5
 
#  Copyright (C) 2011  Canonical Ltd.
6
 
#  Author: Adam Gandelman <adam.gandelman@canonical.com>
7
 
#
8
 
#  This program is free software: you can redistribute it and/or modify
9
 
#  it under the terms of the GNU General Public License as published by
10
 
#  the Free Software Foundation, either version 3 of the License, or
11
 
#  (at your option) any later version.
12
 
#
13
 
# This program is distributed in the hope that it will be useful,
14
 
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
 
#  GNU General Public License for more details.
17
 
#
18
 
#  You should have received a copy of the GNU General Public License
19
 
#  along with this program.  If not, see <http://www.gnu.org/licenses/>.
20
 
 
21
 
RABBIT_CTL='rabbitmqctl'
22
 
HOSTNAME=`hostname -f`
23
 
ERLANG_COOKIE="/var/lib/rabbitmq/.erlang.cookie"
24
 
 
25
 
function user_exists {
26
 
  $RABBIT_CTL list_users | grep -wq "^$1"
27
 
}
28
 
 
29
 
function user_is_admin {
30
 
  $RABBIT_CTL list_users | grep -w "^$1" | grep -q "administrator"
31
 
}
32
 
 
33
 
function vhost_exists {
34
 
  $RABBIT_CTL list_vhosts | grep "^$VHOST\$" >/dev/null
35
 
}
36
 
 
37
 
function create_vhost {
38
 
  $RABBIT_CTL add_vhost $VHOST
39
 
}
40
 
 
41
 
function user_create {
42
 
  juju-log "rabbitmq: Creating user $1."
43
 
 
44
 
  $RABBIT_CTL add_user $1 $PASSWORD || return 1
45
 
 
46
 
  # grant the user all permissions on the default vhost /
47
 
  # TODO: investigate sane permissions
48
 
  juju-log "rabbitmq: Granting permission to $1 on vhost /"
49
 
  $RABBIT_CTL set_permissions -p $VHOST $1 ".*" ".*" ".*"
50
 
 
51
 
  if [[ $2 == 'admin' ]]  ; then
52
 
    user_is_admin $1 && return 0
53
 
    juju-log "rabbitmq: Granting user $1 admin access"
54
 
    $RABBIT_CTL set_user_tags "$1" administrator || return 1
55
 
  fi
56
 
}