~cf-charmers/charms/trusty/cf-cloud-controller/trunk

« back to all changes in this revision

Viewing changes to hooks/install

  • Committer: Al. Lomov
  • Date: 2014-04-03 09:04:04 UTC
  • Revision ID: lomov.as@gmail.com-20140403090404-f9336xt5e6p3qsqd
return to refactored version

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/env python
 
2
# vim: et ai ts=4 sw=4:
 
3
import os
 
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
 
9
)
 
10
from charmhelpers.contrib.cloudfoundry.upstart_helper import (
 
11
    install_upstart_scripts
 
12
)
 
13
 
 
14
from config import *
 
15
 
 
16
 
 
17
def cc_db_migrate():
 
18
    log("Starting db:migrate...", DEBUG)
 
19
    os.chdir(CC_DIR)
 
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'])
 
24
 
 
25
 
 
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'):
 
30
        try:
 
31
            os.remove('/etc/init.d/nginx')
 
32
        except OSError:
 
33
            pass
 
34
    run(['update-rc.d', '-f', 'nginx', 'remove'])
 
35
 
 
36
 
 
37
def install():
 
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']
 
47
    for item in dirs:
 
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()
 
53
    cc_db_migrate()