Question - Creating first Charm

Matt Bruzek matthew.bruzek at canonical.com
Sat Mar 5 00:42:15 UTC 2016


Hello Gilbert,

Thanks for the email. I have added the Juju list so others can chime too.

Because Oracle-XE 11gR2 version requires accepting a license agreement to
> download from Oracle.com...
>
​​We are going to introduce a new concept in Juju 2.0 called "terms" where
you can run an "accept" command for software with proprietary ​software.
You would put "terms" key in your metadata.yaml. Check the release notes
for some tips on this feature:
https://jujucharms.com/docs/devel/temp-release-notes

Alternately you could make a configuration option where the user could
accept the license on the Oracle page, and put the key in a configuration
option, where the charm would not install if the key is empty or invalid.​

So my install hook is taking shape kinda like this (and works):​ ...
>
​I would really encourage you to look at our new Developer documents (
https://jujucharms.com/docs/devel/developer-getting-started ) that
introduce charm layers and a reactive framework. From my experience it is
much more "natural" to write charms this way where you can define states
and react to them. As an example you could define: 'oracle.downloaded',
'oracle.configured', and 'oracle.available' and the code could react to
different states.

My question is, what is the best way to automate this last step for charm
> deployment?

​Non interactive install scripts are the bane of my existence! ​I have a
number of techniques to work around these, such as piping the "yes" command
to a script, or redirecting strings into the interactive bits. The best
approach is on a case to case basis, but you may have to re-write this
script. I

...to just use the default values and to use some hardcoded default
> password.
>
Hard coded passwords are never the right way to go and against Charm Store
policy ( https://jujucharms.com/docs/devel/authors-charm-policy ).  Either
randomly generate a password that the user can retrieve or have that set as
a configuration option but remember all configuration options must be able
to change at any time (mutability). I have used some template technologies
to put charm configuration options in places where the script would prompt
users.

So I'm thinking one obvious way would be to just have some sed and awk
> steps to just change the oracle-xe script to just non-interactively use the
> default ports

Make the ports configurable, so that you can deploy the service and know
the port where it is being served. The user could change it if they know
that port is being used.

Database charms are the most complex for *me* to understand, but I
encourage you to look at the "mysql" charm for tips on database. It was
written by one of our best charmers who knows how to install databases. You
will find many answers to your questions in that charm.

If you have any further questions please share them with
juju at lists.ubuntu.com so the whole community has the benefit of the
information, and other database charmers can pipe in.

   - Matt Bruzek <matthew.bruzek at canonical.com>

On Fri, Mar 4, 2016 at 1:36 PM, Gilbert Standen <gilstanden at hotmail.com>
wrote:

> Hey I'm sorry to bug you with another question but I'm trying to find my
> way along to get through creating my first charm.
>
> Because Oracle-XE 11gR2 version requires accepting a license agreement to
> download from Oracle.com (adding a level of complexity to creating my first
> charm) I stepped back even further to Oracle-XE 10gR2 which actually is
> still available from a DEB repository.   I realize 10gR2 is pretty old but
> for purposes of learning how to charm, it's great, because it's available
> from a ppa still and it's pretty easy to deploy from a manual steps
> perspective, so it should be a good "first charm" exercise for me.
>
> So my install hook is taking shape kinda like this (and works):
>
> # GLS start
> echo 'deb http://oss.oracle.com/debian/ unstable main non-free' | sudo
> tee --append /etc/apt/sources.list
> echo 'deb-src http://oss.oracle.com/debian/ unstable main' | sudo tee
> --append /etc/apt/sources.list
> wget http://oss.oracle.com/el4/RPM-GPG-KEY-oracle  -O- | sudo apt-key add
> -
> apt-get update
> apt-get install -y  oracle-xe --force-yes
> # GLS end
>
> all of the above works great.  However, oracle-xe has a configuration
> script that has to be run at this point (as many db's do) which sets some
> ports and the admin password.  That script comes with it and is
> '/etc/init.d/oracle-xe" and it is run interactively (typically) as shown
> below:
>
> /etc/init.d/oracle-xe configure
>
> which goes like this (interactively):
>
> --- snip start----
>
> root at W520:/etc/init.d# ./oracle-xe configure
>
> Oracle Database 10g Express Edition Configuration
> -------------------------------------------------
> This will configure on-boot properties of Oracle Database 10g Express
> Edition.  The following questions will determine whether the database
> should
> be starting upon system boot, the ports it will use, and the passwords
> that
> will be used for database accounts.  Press <Enter> to accept the defaults.
> Ctrl-C will abort.
>
> Specify the HTTP port that will be used for Oracle Application Express
> [8080]:
>
> Specify a port that will be used for the database listener [1521]:
>
> Specify a password to be used for database accounts.  Note that the same
> password will be used for SYS and SYSTEM.  Oracle recommends the use of
> different passwords for each database account.  This can be done after
> initial configuration:
> Confirm the password:
>
> Do you want Oracle Database 10g Express Edition to be started on boot
> (y/n) [y]:
>
> Starting Oracle Net Listener...Done
> Configuring Database...Done
> Starting Oracle Database 10g Express Edition Instance...Done
> Installation Completed Successfully.
> To access the Database Home Page go to "http://127.0.0.1:8080/apex"
> root at W520:/etc/init.d#
>
> ---snip end---
>
> My question is, what is the best way to automate this last step for charm
> deployment?  One way would be for me to just do some kind of sed or awk and
> replace the interactive steps in the /etc/init.d/oracle-xe script to just
> use the default values and to use some hardcoded default password.
>
> However, the script does some checking to verify that the default ports of
> 8080 and 1521 are not already in use which again would involve some
> interactive steps, which pretty much we don't want in a charm, correct?.
>
> So I guess what I am wondering is what is the best way to handle these
> kind of configuration steps.  I downloaded the couchdb charm, and it has
> steps like this which look like they are doing similar config steps (all
> the stuff starting with DEFAULT_ADMIN_PASSWORD for example:
>
> ---snip start---
>
> apt-get install -y couchdb facter facter-customfacts-plugin uuid
> python-couchdb pwgen
>
> DEFAULT_ADMIN_PASSWORD=`pwgen -N1`
> DEFAULT_REPLICATION_PASSWORD=`pwgen -N1`
>
> fact-add couchdb_hostname `facter fqdn`
> fact-add couchdb_ip `facter ipaddress`
> fact-add couchdb_port 5984
> fact-add couchdb_replication ${DEFAULT_REPLICATION_PASSWORD}
> fact-add couchdb_admin ${DEFAULT_ADMIN_PASSWORD}
>
> sed -i.bak -e "s/bind_address =.*/bind_address = `facter couchdb_ip`/"
> /etc/couchdb/default.ini
> sed -i.bak -e "s/;port =.*/port = `facter couchdb_port`/" \
>            -e "s/;bind_address.*/bind_address = `facter couchdb_ip`/" \
>            -e "s/; require_valid_user = false/require_valid_user = true/" \
>            -e "s/;admin =.*/admin = ${DEFAULT_ADMIN_PASSWORD}/" \
>            /etc/couchdb/local.ini
>
> echo "replication = ${DEFAULT_REPLICATION_PASSWORD}" >>
> /etc/couchdb/local.ini
>
> service couchdb status && service couchdb restart || service couchdb start
>
> open-port `facter couchdb_port`/TCP
>
> ---snip stop---
>
> So I'm thinking one obvious way would be to just have some sed and awk
> steps to just change the oracle-xe script to just non-interactively use the
> default ports, but I'd still have to pass in the default passwords for SYS
> and SYSTEM.
>
> Any pointers to some documentation on different ways to solve this type of
> challenge would be helpful.
>
> Thanks,
>
> Gilbert
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.ubuntu.com/archives/juju/attachments/20160304/90a0f41c/attachment.html>


More information about the Juju mailing list