Opinionated / sensible / recommended default tools for charms

Michael Nelson michael.nelson at canonical.com
Wed Nov 2 11:53:29 UTC 2011


On Wed, Nov 2, 2011 at 2:46 AM, Mark Mims <mark.mims at canonical.com> wrote:
> On 11/01/2011 10:29 AM, Michael Nelson wrote:
>>
>> Hi!
>>
>> 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.
>
> Awesome!
> Standard practices are still evolving.  Are you at UDS?  We've got a session
> that should include this topic.  The blueprint is
> https://blueprints.launchpad.net/ubuntu/+spec/community-juju-charm-docs
>
>> 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'>>
>> /etc/apache2/httpd.conf
>> }}}
>>
>> 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 :) ).
>
> various templating tools are used in charms... I've seen cheetah, augeas
> lenses, erb... but no standard.
>
> We should definitely take an opinionated approach in the docs/examples just
> for simplicity.  We can always add the disclaimer at the bottom "but you can
> swap out for the tool you want."  Always a tough line to walk, showcase
> flexibility -vs- just help me get it done.
>
>>
>> Setting the IP address
>> ==================
>> Currently my db-relation-changed hook it does (again, copied from
>> another formula):
>> IP=`ifconfig | grep 'inet addr:'| grep -v '127.0.0.1' | cut -d: -f2 |
>> awk '{print $1}'|head -n 1`
>> ensemble-log "setting ip to $IP"
>> relation-set ip=$IP
>
> totally revamped...
> I can get my address,
>    unit-get private-address
> and a related service's address
>    relation-get private-address
> for free now everywhere.

Sweet - much nicer :)

>
>>
>> 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.
>> Thanks,
>> -Michael
>
> We've got a couple of node.js (lp:charm/node-app) and rails charms that try
> to accomplish the same thing (the charm pulls the app code from a branch
> specified in config.yaml).
>
> These charms need to be updated to reflect the latest juju trunk, but it
> sounds similar to what you're wanting to do.

Great - I'll check those out again. It was the rails charm that I
initially used as a base, but that was a while ago now.

>
> I'd love to discuss these "framework" or application "wrapper" charms in
> person in orlando or on #juju if you've got the time.

That would be great... there are a bunch of us (some ISD, some
Consumer App server) in Boca VIII if you have time to pop by (or ping
to organise a time). Clint was around yesterday afternoon which really
helped a lot of things click for some of us who had just started
playing with juju.

Thanks!

-Michael

>
>>
>> [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
>> http://projects.puppetlabs.com/projects/1/wiki/Puppet_Augeas
>> [4]
>> https://juju.ubuntu.com/docs/drafts/service-config.html#service-configuration
>>
>
>
> --
> Mark Mims, Ph.D.
> Canonical Ltd.
> mark.mims at canonical.com
> +1(512)981-6467
>
> --
> Juju mailing list
> Juju at lists.ubuntu.com
> Modify settings or unsubscribe at:
> https://lists.ubuntu.com/mailman/listinfo/juju
>



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