2
# vim: et ai ts=4 sw=4:
5
from charmhelpers.core import hookenv, host
6
from charmhelpers.core.hookenv import log
7
from charmhelpers.contrib.cloudfoundry.common import (
8
chownr, run, prepare_cloudfoundry_environment
10
from charmhelpers.contrib.cloudfoundry.upstart_helper import (
11
install_upstart_scripts
18
log("Starting db:migrate...", DEBUG)
20
#TODO: make it idempotent by deleting existing db if exists
21
run(['sudo', '-u', 'vcap', '-g', 'vcap',
22
'CLOUD_CONTROLLER_NG_CONFIG={}'.format(CC_CONFIG_FILE),
23
'bundle', 'exec', 'rake', 'db:migrate'])
26
def disable_nginx_service():
27
# reconfigure NGINX as upstart job and use specific config file
28
host.service_stop('nginx')
29
if os.path.isfile('/etc/init.d/nginx'):
31
os.remove('/etc/init.d/nginx')
34
run(['update-rc.d', '-f', 'nginx', 'remove'])
38
# TODO build of directory service
39
prepare_cloudfoundry_environment(hookenv.config(), CC_PACKAGES)
40
if not os.path.isfile(CC_DB_FILE):
41
# TODO check permission hear
42
host.write_file(CC_DB_FILE, '', owner='vcap', group='vcap', perms=0664)
43
dirs = [CC_RUN_DIR, NGINX_RUN_DIR, CC_LOG_DIR, NGINX_LOG_DIR,
44
'/var/vcap/data/cloud_controller_ng/tmp/uploads',
45
'/var/vcap/data/cloud_controller_ng/tmp/staged_droplet_uploads',
46
'/var/vcap/nfs/store']
48
host.mkdir(item, owner='vcap', group='vcap', perms=0775)
49
chownr('/var/vcap', owner='vcap', group='vcap')
50
chownr(CF_DIR, owner='vcap', group='vcap')
51
disable_nginx_service()
52
install_upstart_scripts()