Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm writing a charm that requires a mysql database, I found from looking at other charms that this (below) is how I get the info about the database:

user=`relation-get user`
password=`relation-get password`
mysqlhost=`relation-get private-address` 

But I just found that from reading the wordpress charm example, is there a way to show all the relation variables that I can use?

Also, while debugging my db-relation-changed script, I wanted to ssh into my host and interactively run those commands, for example relation-get user, but it didn't work. I resorted to having to restart everything and use juju log to print them out. This wasted a lot of time. Is there a way to print out these relations, either from my dev box or from the instance running my charm? (Below is what happens when I tried to interactively run relation-get):

ubuntu@mfisch-local-tracks-0:~$ relation-get user
usage: relation-get [-h] [-o OUTPUT] [-s SOCKET] [--client-id CLIENT_ID]
                    [--format FORMAT] [--log-file FILE]
                    [--log-level CRITICAL|DEBUG|INFO|ERROR|WARNING]
                    [-r RELATION ID]
                    [settings_name] [unit_name]
No JUJU_AGENT_SOCKET/-s option found

I tried juju debug-hooks tracks/0 -e local, that dropped me into a shell and relation-get still failed.

share|improve this question

I've run into a variant of this with config-get on the juju unit. I find that if I set a config value from the deployer machine, then I no longer get the JUJU_AGENT_SOCKET error message:

    juju bootstrap
    juju deploy local:wordress # local:$charm
    juju get wordpress # $charm, gets config.yaml
    juju set wordpress name=value # set any $charm name

    juju debug-hooks wordpress/0 # $charm/$int
    $charm-$int: config-get # get config.yaml

Without doing a 'juju set' on the deployer machine, config-get will return the JUJU_AGENT_SOCKET error. Afterwards, you get all the current values.

Not an answer, but a workaround. When I know more about relations, maybe a variant works with that too.

share|improve this answer

A way to interactively debug your charm is to use debug-hooks ( ):

For example:

juju deploy wordpress

( Let's say that the above command deploys wordpress/0 )

juju debug-hooks wordpress/0

That will open a tmux session where the hooks can be run manually. It also sets up the environment so relation-* can be run ( relation-get, relation-list, etc. )

Try running relation-get ... it should give you all of the available variables for that particular charm/relation.

NOTE: You actually have to cause a hook to fire once you start the juju debug-hooks. So, add/modify a relationship at this point. (I typically just remove-relationship and then add it right back.) This will create additional hook-specific windows within tmux that DO have JUJU_ setting context and will respond to relation-get relation-set commands.

share|improve this answer
I tried this just now and I get the same error as before: juju debug-hooks tracks/0 -e local, that dropped me into a shell and relation-get still failed. – mfisch Nov 24 '12 at 23:19

Try this:

juju ssh servicename/instance_id sudo apt-get install juju-jitsu
juju ssh servicename/instance_id
sudo grep -R JUJU_ENV_UUID /etc
# take result and export
ubuntu@ip-10-204-237-189:~$ jitsu run-as-hook lamp/0 config-get database-user


# I attached collectd to this instance
jitsu run-as-hook lamp/0 relation-ids collectd-server
$ echo $?

It didn't return anything because I hadn't related it yet, note that it didn't explode either. Hope this helps.

share|improve this answer

When you execute juju debug-hooks service/#, it does a juju ssh into a tmux session. However, that first window of the tmux session (which is like screen) has no JUJU session info. (You can demonstrate this by executing set|grep JUJU and you shouldn't see any settings returned.) There will only be a 0:~ window within TMUX initially.

Once a relation is added (from another window/terminal) via something like:

juju add-relation wordpress mysql

an ADDITIONAL tmux window should be created and become active. The name of the hook being debugged will be embedded in the TMUX title (at the bottom of the screen), something like:

1: db-relation-changed

You can now run relation-get or better yet:

set|grep JUJU


(this for the rsetter charm related to rgetter, not wordpress/mysql)

You can then debug (including executing the hooks that would normally be launched as you should be in the parent directory of the charm, so hooks/HOOKNAME)

share|improve this answer
oh and yes, "relation-get" in that new TMUX on-demand created window will get you all relation settings. "relation-get --format json" may make them more readable. Embedding "relation-get -o /tmp/DEBUGGING_RELATION_SETTINGS.json --format json" in one of your hooks will leave them on the node. Relation settings are per relation and per direction. You can't "get" relations you have set unless you go to the other service.... it's like a pipe in that respect. – med Feb 17 '13 at 1:46

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.