Skip to content

Instantly share code, notes, and snippets.

@marcoceppi
Last active March 19, 2017 01:45
Show Gist options
  • Save marcoceppi/519379c091312323872882f38ac0d02f to your computer and use it in GitHub Desktop.
Save marcoceppi/519379c091312323872882f38ac0d02f to your computer and use it in GitHub Desktop.
import os
import tarfile
from charmhelpers.core.hookenv import (
config,
status_set,
open_port,
)
from charms.reactive import (
when,
when_not,
set_flag,
remove_flag,
)
from charmhelpers.core.host import chownr
from charmhelpers.core.templating import render
from charms.layer import (
php,
git,
nginx,
)
@when('php.ready')
@when_not('silph-road.installed')
def install_thesilphroad():
web_path = '/srv/web'
git.clone(config().get('source'), web_path)
create_paths = {
'app/tmp/cache/pokedex_cache': 0o777,
'app/tmp/cache/persistent': 0o777,
'app/tmp/cache/models': 0o777,
'app/tmp/logs': 0o777,
'app/webroot/img/user-verification-photos': 0o777,
}
for path, perm in create_paths.items():
os.makedirs(os.path.join(web_path, path), perm)
chownr(web_path, 'www-data', 'www-data')
set_flag('silph-road.installed')
@when('config.changed.source')
def update_cfg():
remove_flag('silph-road.installed')
remove_flag('silph-road.ready')
@when('nginx.available')
@when('silph-road.installed')
@when_not('silph-road.nginx.ready')
def setup_vhost():
nginx.configure_site(
'silphroad',
'silphroad-vhost.conf',
socket=php.socket(),
)
service_restart('nginx')
set_flag('silph-road.nginx.ready')
@when('silph-road.installed')
@when('database.available')
@when_not('silph-road.db.ready')
def configure_db(db):
ctx = {'database': db}
render(source='database.php.j2',
target='/srv/web/app/Config/database.php',
owner='www-data',
group='www-data',
perms=0o640,
context=ctx
)
set_flag('silph-road.db.ready')
@when('silph-road.nginx.ready')
@when('silph-road.db.ready')
@when_not('silph-road.ready')
def ready_freddie():
open_port(80)
status_set('active', 'ready')
set_flag('silph-road.ready')
@when('silph-road.ready')
@when('website.available')
def send_port(http):
http.configure(80)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment