Opinionated / sensible / recommended default tools for charms

Michael Nelson michael.nelson at canonical.com
Tue Nov 1 16:29:49 UTC 2011


A few months ago I wrote a formula/charm for a personal project (just
a first attempt at deploying a django + psql app [1] based on a rails
formula that I found), but there were quite a few points in my hooks
where I saw that there must be better ways/tools to use for what the
hook was doing. I think it's great that hooks can be written with any
tool - but I'm wondering if there are any docs/recommendations for
doing standard tasks such as setting config files or enabling
configuration options for a charm. I'm currently looking at
experimenting with a project at work, and so wanted to check for the
following specific situations:

Getting the instance in a certain state
Currently my install hook does:
ensemble-log "Installing required packages via apt-get."
apt-get -y install apache2 libapache2-mod-wsgi bzr fabric ....
... (then later in my db-relation-changed hook)
ensemble-log "Setting up the wsgi alias."
echo 'Alias /site_media/
/opt/open-goal-tracker/current/media-root-dev/\nWSGIScriptAlias /
/opt/open-goal-tracker/current/ogt_project/apache/django.wsgi' >>

It looks like the kind of stuff for which puppet is made. Has anybody
written charms using serverless puppet for this (or even, in a way
that it can work serverless, but will use a puppet master if one is
defined/set [2]).

Writing config files from templates
Currently my db-relation-changed hook also does:

ensemble-log "Updating local_settings.py."
cd /opt/open-goal-tracker/current/ogt_project
sed -e "s/DATABASE_USER/$user/" \
-e "s/DATABASE_PASSWORD/$password/" \
-e "s/DATABASE_HOST/$host/" \
-e "s/DATABASE_NAME/$database/" \
$hooksdir/local_settings-template.py > local_settings.py
chown www-data local_settings.py

Again, this seems like something for which puppet already has tools
[3]. Of course there are many tools to solve this problem (sed
included), but if an example used puppet to get the machine into a
certain state with packages, it may make sense to continue along those
lines (especially if your IS group is using puppet already :) ).

Setting the IP address
Currently my db-relation-changed hook it does (again, copied from
another formula):
IP=`ifconfig | grep 'inet addr:'| grep -v '' | cut -d: -f2 |
awk '{print $1}'|head -n 1`
ensemble-log "setting ip to $IP"
relation-set ip=$IP

Enabling a configurable charm

Ideally, I'd like to write a `django-pg` charm which can be re-used by
various projects (by passing in a particular code and config branch),
rather than a specific charm for a specific application - if possible.
I'm not sure if that's what the service configuration draft is
intended [4].

Anyway, if anyone has any recommendations, or can point me at a good
example of a charm that sets a good example for me to follow, I'd love
to hear from you - but I'll continue on in the mean-time.

[1] https://code.launchpad.net/~michael.nelson/open-goal-tracker/ensemble_deploy/+merge/69078
[2] I want to apply this to a GPL project at work. So I'd like the
charm to work for anyone in the community, while still enabling IS to
customise the puppet config etc., if possible.
[3] statik told me about
[4] https://juju.ubuntu.com/docs/drafts/service-config.html#service-configuration

Michael Nelson
Canonical Ltd.
+49 176 491 53481 (mob)
michael.nelson at canonical.com
IRC nick: noodles (noodles775 on Freenode)
Ubuntu - Linux for human beings | www.ubuntu.com | www.canonical.com

More information about the Juju mailing list