コード例 #1
0
    def setup(self):
        self.install_packages()
        self.start_services().enable_services()

        repo = '/home/{0}/fabkit-repo'.format(env.user)
        filer.mkdir(repo, use_sudo=False)
        git.setup()
        git.sync('https://github.com/fabrickit/fabkit.git',
                 dest='{0}/fabfile'.format(repo))

        python = Python('/opt/fabkit')
        python.setup()
        python.install(
            requirements='{0}/fabfile/requirements.txt'.format(repo))

        run('cd {0} && /opt/fabkit/bin/fab genconfig:fabfile.ini &&'
            ' sed -i "/^\[web\]/,/^\[/s/#hostname =.*/hostname = */g" fabfile.ini'.format(repo))

        data = {
            'port': 80,
            'repo': repo,
            'user': env.user,
            'group': env.user,
            'python_path': python.get_site_packages(),
            'processes': 5,
            'threads': 1,
        }

        run('cd {0}/fabfile/core/webapp/ &&'
            ' /opt/fabkit/bin/python manage.py migrate &&'
            ' echo "from django.contrib.auth.models import User;'
            '       User.objects.create_superuser(\'admin\', \'admin@localhost\', \'admin\')"'
            '       | /opt/fabkit/bin/python manage.py shell &&'
            ' /opt/fabkit/bin/python manage.py collectstatic --noinput'.format(repo))

        sudo('chmod 755 /home/{0}'.format(env.user))

        if re.match('CentOS .*', env.node['os']):
            log_prefix = '/var/log/httpd/{0}'.format(env.user)
            data['error_log'] = '{0}-error.log'.format(log_prefix)
            data['custom_log'] = '{0}-access.log'.format(log_prefix)

            if filer.template(src='httpd.conf',
                              dest='/etc/httpd/conf.d/{0}_httpd.conf'.format(env.user),
                              data=data):
                self.handlers['restart_httpd'] = True

        elif re.match('Ubuntu .*', env.node['os']):
            log_prefix = '/var/log/apache2/{0}'.format(env.user)
            data['error_log'] = '{0}-error.log'.format(log_prefix)
            data['custom_log'] = '{0}-access.log'.format(log_prefix)

            if filer.template(src='httpd.conf',
                              dest='/etc/apache2/sites-enabled/{0}_httpd.conf'.format(env.user),
                              data=data):
                self.handlers['restart_apache2'] = True

        self.exec_handlers()

        # install
        sudo('npm install -g coffee-script'.format(repo))
        sudo('cd {0}/fabfile/core/webapp && npm install'.format(repo))

        # install node packages for develop
        sudo('npm install -g grunt-cli'.format(repo))
        sudo('cd {0}/fabfile/core/webapp/node_chat && npm install'.format(repo))
コード例 #2
0
    def setup(self):
        self.install_packages()
        self.start_services().enable_services()

        repo = '/home/{0}/fabkit-repo'.format(env.user)
        filer.mkdir(repo, use_sudo=False)
        git.setup()
        git.sync('https://github.com/fabrickit/fabkit.git',
                 dest='{0}/fabfile'.format(repo))

        python = Python('/opt/fabkit')
        python.setup()
        python.install(
            requirements='{0}/fabfile/requirements.txt'.format(repo))

        run('cd {0} && /opt/fabkit/bin/fab genconfig:fabfile.ini &&'
            ' sed -i "/^\[web\]/,/^\[/s/#hostname =.*/hostname = */g" fabfile.ini'
            .format(repo))

        data = {
            'port': 80,
            'repo': repo,
            'user': env.user,
            'group': env.user,
            'python_path': python.get_site_packages(),
            'processes': 5,
            'threads': 1,
        }

        run('cd {0}/fabfile/core/webapp/ &&'
            ' /opt/fabkit/bin/python manage.py migrate &&'
            ' echo "from django.contrib.auth.models import User;'
            '       User.objects.create_superuser(\'admin\', \'admin@localhost\', \'admin\')"'
            '       | /opt/fabkit/bin/python manage.py shell &&'
            ' /opt/fabkit/bin/python manage.py collectstatic --noinput'.format(
                repo))

        sudo('chmod 755 /home/{0}'.format(env.user))

        if re.match('CentOS .*', env.node['os']):
            log_prefix = '/var/log/httpd/{0}'.format(env.user)
            data['error_log'] = '{0}-error.log'.format(log_prefix)
            data['custom_log'] = '{0}-access.log'.format(log_prefix)

            if filer.template(src='httpd.conf',
                              dest='/etc/httpd/conf.d/{0}_httpd.conf'.format(
                                  env.user),
                              data=data):
                self.handlers['restart_httpd'] = True

        elif re.match('Ubuntu .*', env.node['os']):
            log_prefix = '/var/log/apache2/{0}'.format(env.user)
            data['error_log'] = '{0}-error.log'.format(log_prefix)
            data['custom_log'] = '{0}-access.log'.format(log_prefix)

            if filer.template(
                    src='httpd.conf',
                    dest='/etc/apache2/sites-enabled/{0}_httpd.conf'.format(
                        env.user),
                    data=data):
                self.handlers['restart_apache2'] = True

        self.exec_handlers()

        # install
        sudo('npm install -g coffee-script'.format(repo))
        sudo('cd {0}/fabfile/core/webapp && npm install'.format(repo))

        # install node packages for develop
        sudo('npm install -g grunt-cli'.format(repo))
        sudo(
            'cd {0}/fabfile/core/webapp/node_chat && npm install'.format(repo))
コード例 #3
0
class FabServer(SimpleBase):
    def __init__(self):
        self.data_key = 'fabkit_tools'

        self.data = {
            'port': 8080,
            'user': '******',
            'group': 'nobody',
            'prefix': '/opt/fabkit',
            'task_patterns': 'local.*,check.*',
            'processes': 5,
            'threads': 1,
        }

        self.packages = {
            'CentOS Linux 7.*': [
                'epel-release',
                'httpd',
                'mod_wsgi',
                'nodejs',
                'npm',
            ],
            'Ubuntu 14.*': [
                'apache2',
                'libapache2-mod-wsgi',
                'nodejs',
                'npm',
            ]
        }

        self.services = {
            'CentOS Linux 7.*': [
                'httpd',
                'fabnode',
            ],
            'Ubuntu 14.*': [
                'apache2',
            ]
        }

    def init_before(self):
        self.python = Python(self.data['prefix'])

    def init_after(self):
        self.data['owner'] = '{0}:{1}'.format(self.data['user'], self.data['group'])
        self.data['host'] = env.host

    def setup(self):
        data = self.init()
        self.install_packages()

        var_dir = CONF.client.package_var_dir
        common_repo = '{0}/fabkit-repo-common'.format(var_dir)
        server_repo = '{0}/fabkit-repo-server'.format(var_dir)
        filer.template('{0}/fabfile.ini'.format(server_repo), data=data)

        sudo('rm -rf {0}/fabfile && '
             'cp -r {1}/fabfile {0}/fabfile && '
             'chown -R {2}:{3} {0}/fabfile'.format(
                 server_repo, common_repo, data['user'], data['group']))

        if re.match('CentOS .*', env.node['os']):
            log_prefix = '/var/log/httpd/{0}'.format(env.user)
            data.update({
                'repo': server_repo,
                'python_path': self.python.get_site_packages(),
                'error_log': 'fabkit-error.log'.format(log_prefix),
                'custom_log': 'fabkit-access.log'.format(log_prefix),
            })

            if filer.template(src='httpd.conf',
                              dest='/etc/httpd/conf.d/fabkit_httpd.conf'.format(env.user),
                              data=data):
                self.handlers['restart_httpd'] = True

        self.exec_handlers()

        if env.host == env.hosts[0]:
            sudo("cd {0}/fabfile/core/webapp && "
                 "{1}/bin/python manage.py migrate --noinput".format(
                     server_repo, CONF.client.package_prefix))

            sudo("cd {0}/fabfile/core/webapp && "
                 "echo \"from django.contrib.auth.models import User;"
                 "User.objects.create_superuser('admin', '*****@*****.**', 'admin')\""
                 " | {1}/bin/python manage.py shell".format(
                     server_repo, CONF.client.package_prefix))

        self.start_services().enable_services()

        self.restart_services()

        sudo('/opt/fabkit/bin/fabserver -l')
コード例 #4
0
class FabServer(SimpleBase):
    def __init__(self):
        self.data_key = 'fabkit_tools'

        self.data = {
            'port': 8080,
            'user': '******',
            'group': 'nobody',
            'prefix': '/opt/fabkit',
            'task_patterns': 'local.*,check.*',
            'processes': 5,
            'threads': 1,
        }

        self.packages = {
            'CentOS Linux 7.*': [
                'epel-release',
                'httpd',
                'mod_wsgi',
                'nodejs',
                'npm',
            ],
            'Ubuntu 14.*': [
                'apache2',
                'libapache2-mod-wsgi',
                'nodejs',
                'npm',
            ]
        }

        self.services = {
            'CentOS Linux 7.*': [
                'httpd',
                'fabnode',
            ],
            'Ubuntu 14.*': [
                'apache2',
            ]
        }

    def init_before(self):
        self.python = Python(self.data['prefix'])

    def init_after(self):
        self.data['owner'] = '{0}:{1}'.format(self.data['user'],
                                              self.data['group'])
        self.data['host'] = env.host

    def setup(self):
        data = self.init()
        self.install_packages()

        var_dir = CONF.client.package_var_dir
        common_repo = '{0}/fabkit-repo-common'.format(var_dir)
        server_repo = '{0}/fabkit-repo-server'.format(var_dir)
        filer.template('{0}/fabfile.ini'.format(server_repo), data=data)

        sudo('rm -rf {0}/fabfile && '
             'cp -r {1}/fabfile {0}/fabfile && '
             'chown -R {2}:{3} {0}/fabfile'.format(server_repo, common_repo,
                                                   data['user'],
                                                   data['group']))

        if re.match('CentOS .*', env.node['os']):
            log_prefix = '/var/log/httpd/{0}'.format(env.user)
            data.update({
                'repo': server_repo,
                'python_path': self.python.get_site_packages(),
                'error_log': 'fabkit-error.log'.format(log_prefix),
                'custom_log': 'fabkit-access.log'.format(log_prefix),
            })

            if filer.template(
                    src='httpd.conf',
                    dest='/etc/httpd/conf.d/fabkit_httpd.conf'.format(
                        env.user),
                    data=data):
                self.handlers['restart_httpd'] = True

        self.exec_handlers()

        if env.host == env.hosts[0]:
            sudo("cd {0}/fabfile/core/webapp && "
                 "{1}/bin/python manage.py migrate --noinput".format(
                     server_repo, CONF.client.package_prefix))

            sudo(
                "cd {0}/fabfile/core/webapp && "
                "echo \"from django.contrib.auth.models import User;"
                "User.objects.create_superuser('admin', '*****@*****.**', 'admin')\""
                " | {1}/bin/python manage.py shell".format(
                    server_repo, CONF.client.package_prefix))

        self.start_services().enable_services()

        self.restart_services()

        sudo('/opt/fabkit/bin/fabserver -l')