Skip to content

Instantly share code, notes, and snippets.

@marcoceppi
Last active October 11, 2016 14:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save marcoceppi/2eb1cf988f7f64eb535b290b1de29632 to your computer and use it in GitHub Desktop.
Save marcoceppi/2eb1cf988f7f64eb535b290b1de29632 to your computer and use it in GitHub Desktop.
juju
# This is a commnet, you can delete it
#
# layer-apt automatically takes care of things like additional repositories
# and any complexity needed to install packages. You can install packages a number
# of ways, documented in the README https://git.launchpad.net/layer-apt/tree/README.md
#
# We add your PPA here, in the config.yaml, so that it will be installed prior to any
# hooks that run
options:
install_sources:
default: |
- ppa:ondrej/php
install_keys:
default: |
- null
from charms.reactive import when, when_not, set_state
from subprocess import check_call
from charmhelpers.core.hookenv import status_set
from charmhelpers.core.host import add_group
from charmhelpers.core.host import adduser
from charmhelpers.fetch import apt_install
from charmhelpers.fetch import apt_update
# This is a comment, you can delete me
# Layers also emmit states you can react to. Most states are prefixed with the name
# So, apt.installed.cpanminus tells us that the apt layer has successfully installed
# cpanm. We could also add decorators for things like `apt.installed.php5.6` or any
# package we requested the apt layer to install in the `layer.yaml` or via
# `charms.apt.queue_install`
@when('apt.installed.cpanminus')
@when_not('sme.installed')
def install():
status_set('maintenance', 'Installing CPAN Packages')
cpan_packages = [
'Test::Simple',
'Test::Warn',
'Class::Accessor',
'XML::Parser::EasyTree',
'CGI::Ajax',
'Date::Format',
'Date::Parse',
'Date::Manip',
'IO::Tty'
]
for i in cpan_packages:
status_set('maintenance', 'Installing CPAN Package: {}'.format(i))
check_call(['cpanm', i])
set_state('sme.nstalled')
status_set('maintenance', 'CPAN Packages installed')
@when('sme.installed')
@when_not('sme.groups_added')
def add_groups():
status_set('maintenance', 'Creating system groups')
groups = [
'smestorage',
'smeconfiguser',
'defaultstore',
'sme'
]
# This is a comment, you can delete me
# If you find yourself using subprocess a lot, odds are there is a helper method
# in charmhelpers for that. The documentation can be a bit unwieldy, but check out
# http://pythonhosted.org/charmhelpers/api/charmhelpers.html and use the search
# to try to map to things you're subprocessing for
for group in groups:
add_group(group)
status_set('maintenance', 'System groups created')
set_state('sme.groups_added')
@when('sme.groups_added')
@when_not('sme.ready')
def add_users():
status_set('maintenance', 'Creating user accounts')
# This is a comment, you can delete me
# There is a charmhelpers.core.host.adduser method however you can not set the HOME
# For the created user. This needs to be requested / patched in the charmhelpers library
# http://pythonhosted.org/charmhelpers/api/charmhelpers.core.host.html#charmhelpers.core.host.adduser
check_call(['useradd', '-m', '-p', '$6$mQM0S5fe$01X38ZTeOBEHkVovBYJ2Qn2NQKHdVRkpQmHItCx/lkTfNUZ8ge2v/aYHIm9y8LcxvjeMmzcHdFd0Y48B25NSq/', '-g', '5000', '-d', '/var/www/smestorage' ])
#check_call(['useradd', '-m', '-p', '',])
#check_call(['useradd', '-m', '-p', '',])
#check_call(['useradd', '-m', '-p', '',])
set_state('sme.ready')
status_set('active', 'Ready')
# This is a commnet, you can delete me
#
# layer.yaml outlines all the dependencies and build-time configuration
# parameters for the charm. When you run `charm build` it'll pull in the
# code for the apt layer. There's actually quite a large number of layers
# like layer-apt that you can build upon. They are listed here:
# http://interfaces.juju.solutions/ Each should have a README outlining how
# to use that layer
includes:
- 'layer:basic'
- 'layer:apt'
options:
basic:
packages:
- build-essential
apt:
packages:
- apache2
- vim
- iptables
- iftop
- git
- iptraf-ng
- apache2
- wget
- unzip
- mc
- apache2-utils
- htop
- nano
- psmisc
- php5.6-cli
- libnet-dns-perl
- cifs-utils
- ntp
- apache2-suexec-custom
- python-pexpect
- python-crypto
- mcstrans
- memcached
- cpanminus
- php5.6
- php5.6-fpm
- php5.6-curl
- php5.6-xml
- php-pear
- php5.6-imap
- php5.6-ldap
- php5.6-mcrypt
- php5.6-soap
- php5.6-xmlrpc
- vsftpd
- telnet
- lftp
- zip
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment