Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

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
add comment

4 Answers 4

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
add comment

A way to interactively debug your charm is to use debug-hooks ( https://juju.ubuntu.com/docs/write-charm.html#debugging-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
add comment

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
juju-user

also,

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

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
add comment

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

JUJU_AGENT_SOCKET=/var/lib/juju/units/rsetter-1/.juju.hookcli.sock
JUJU_CLIENT_ID=constant
JUJU_DEBUG=/tmp/tmp.ZiobnuyhQh
JUJU_ENV_UUID=b4123455644323333333336d6f8383d
JUJU_PYTHONPATH=:/usr/lib/python2.7/dist-packages:/usr/lib/python2.7:/usr/lib/python2.7/plat-linux2:/usr/lib/python2.7/lib-tk:/usr/lib/python2.7/lib-old:/usr/lib/python2.7/lib-dynload:/usr/local/lib/python2.7/dist-packages:/usr/lib/pymodules/python2.7
JUJU_RELATION=rtest
JUJU_RELATION_ID=rtest:12
JUJU_REMOTE_UNIT=rgetter/1
JUJU_UNIT_NAME=rsetter/1
_JUJU_CHARM_FORMAT=1

(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
add comment

Your Answer

 
discard

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.