예제 #1
0
def oxauth_server():
    if request.method == "POST":
        hostname = request.form.get("hostname")
        gluu_server = request.form.get("gluu_server")

        if gluu_server == "true":
            gluu_server = True
        else:
            gluu_server = False

        if not hostname:
            return jsonify({
                "status": 400,
                "message": "Invalid data",
                "params": "hostname can't be empty",
            }), 400

        server = Server()
        server.hostname = hostname
        server.gluu_server = gluu_server
        db.session.add(server)
        db.session.commit()
        return jsonify({
            "id": server.id,
            "hostname": server.hostname,
            "gluu_server": server.gluu_server,
        }), 201

    servers = [{
        "id": srv.id,
        "hostname": srv.hostname,
        "gluu_server": srv.gluu_server,
    } for srv in Server.query]
    return jsonify(servers)
예제 #2
0
    def test_db_with_data_loads_dashboard(self):
        s1 = Server()
        s1.hostname = 'test.example.com'
        s1.gluu_server = True
        s1.ip = '0.0.0.0'
        with self.app.app_context():
            db.session.add(s1)
            db.session.commit()

        rv = self.client.get('/')
        self.assertIn('Dashboard', rv.data)
        self.assertIn('test.example.com', rv.data)
예제 #3
0
def remove():
    """This view will remove monitoring components"""

    servers = Server.query.all()
    appconf = AppConfiguration.query.first()
    if not appconf:
        flash(
            "The application needs to be configured first. Kindly set the "
            "values before attempting clustering.", "warning")
        return redirect(url_for("index.app_configuration"))

    if not servers:
        flash("Add servers to the cluster before attempting to manage cache",
              "warning")
        return redirect(url_for('index.home'))

    servers = Server.query.all()
    local_id = 100000000
    local_server = Server(hostname='localhost', id=local_id)
    servers.append(local_server)

    task = remove_monitoring.delay(local_id=local_id)
    return render_template('monitoring_remove_logger.html',
                           step=1,
                           task_id=task.id,
                           servers=servers)
예제 #4
0
def setup_local():
    """This view provides setting up monitoring components on local machine"""
    server = Server(hostname='localhost', id=0)

    task = install_local.delay()
    return render_template('monitoring_setup_logger.html',
                           step=2,
                           task_id=task.id,
                           servers=[server])
예제 #5
0
def index():
    """Route for URL /server/. GET returns ServerForm to add a server,
    POST accepts the ServerForm, validates and creates a new Server object
    """
    appconfig = AppConfiguration.query.first()
    if not appconfig:
        flash(
            "Kindly set default values for the application before adding"
            " servers.", "info")
        return redirect(url_for('index.app_configuration', next="/server/"))

    form = ServerForm()
    header = "New Server"
    primary_server = Server.query.filter(
        Server.primary_server.is_(True)).first()

    if primary_server:
        del form.ldap_password
        del form.ldap_password_confirm
    else:
        header = "New Server - Primary Server"

    if form.validate_on_submit():
        server = Server()
        server.hostname = form.hostname.data.strip()
        server.ip = form.ip.data.strip()
        server.mmr = False
        if primary_server:
            server.ldap_password = primary_server.ldap_password
        else:
            server.ldap_password = form.ldap_password.data.strip()
            server.primary_server = True
        db.session.add(server)
        db.session.commit()

        # start the background job to get system details
        collect_server_details.delay(server.id)
        return redirect(url_for('index.home'))

    return render_template('new_server.html', form=form, header=header)
예제 #6
0
def index():
    """Route for URL /server/. GET returns ServerForm to add a server,
    POST accepts the ServerForm, validates and creates a new Server object
    """
    appconfig = AppConfiguration.query.first()
    if not appconfig:
        flash(
            "Kindly set default values for the application before adding"
            " servers.", "info")
        return redirect(url_for('index.app_configuration', next="/server/"))
    form = ServerForm()

    pr_server = get_primary_server_id()
    if pr_server:
        form.primary_server.render_kw = {'disabled': 'disabled'}

    if form.validate_on_submit():
        server = Server()
        server.gluu_server = form.gluu_server.data
        server.hostname = form.hostname.data
        server.ip = form.ip.data
        server.ldap_password = form.ldap_password.data
        server.mmr = False
        server.primary_server = form.primary_server.data
        db.session.add(server)
        db.session.commit()

        # start the background job to get system details
        collect_server_details.delay(server.id)
        return redirect(url_for('index.home'))

    flash(
        'Cluster Manager will connect to this server via SSH to perform its'
        ' tasks. Ensure the server running Cluster Manager has'
        '"Password-less" SSH access via shared keys to the server.', 'info')
    return render_template('new_server.html', form=form, header="New Server")
예제 #7
0
def index():
    """Route for URL /server/. GET returns ServerForm to add a server,
    POST accepts the ServerForm, validates and creates a new Server object
    """

    appconfig = AppConfiguration.query.first()
    if not appconfig:
        flash(
            "Kindly set default values for the application before adding"
            " servers.", "info")
        return redirect(url_for('index.app_configuration', next="/server/"))

    form = ServerForm()
    header = "New Server"
    primary_server = Server.query.filter(
        Server.primary_server.is_(True)).first()

    if primary_server:
        del form.ldap_password
        del form.ldap_password_confirm
    else:
        header = "New Server - Primary Server"

    if form.validate_on_submit():

        server = Server()
        server.hostname = form.hostname.data.strip()
        server.ip = form.ip.data.strip()
        server.mmr = False
        ask_passphrase = False

        server_exist = Server.query.filter_by(
            hostname=form.hostname.data.strip()).first()

        if server_exist:
            flash(
                "Server with hostname {} is already in cluster".format(
                    server_exist.hostname), "warning")
            return redirect(url_for('index.home'))

        c = RemoteClient(server.hostname, server.ip)
        try:
            c.startup()

        except ClientNotSetupException as e:

            if str(e) == 'Pubkey is encrypted.':
                ask_passphrase = True
                flash(
                    "Pubkey seems to password protected. "
                    "After setting your passphrase re-submit this form.",
                    'warning')
            elif str(e) == 'Could not deserialize key data.':
                ask_passphrase = True
                flash(
                    "Password your provided for pubkey did not work. "
                    "After setting your passphrase re-submit this form.",
                    'warning')
            else:
                flash(
                    "SSH connection to {} failed. Please check if your pub key is "
                    "added to /root/.ssh/authorized_keys on this server. Reason: {}"
                    .format(server.hostname, e), 'error')

        #except:
        #    flash("SSH connection to {} failed. Please check if your pub key is "
        #        "asdded to /root/.ssh/authorized_keys on this server".format(
        #                                            server.hostname))

            print "ask_passphrase", ask_passphrase

            return render_template('new_server.html',
                                   form=form,
                                   header=header,
                                   server_id=None,
                                   ask_passphrase=ask_passphrase,
                                   next=url_for('server.index'))

        if primary_server:
            server.ldap_password = primary_server.ldap_password
        else:
            server.ldap_password = form.ldap_password.data.strip()
            server.primary_server = True

        if not server.hostname == appconfig.nginx_host:
            db.session.add(server)
            db.session.commit()
            # start the background job to get system details
            collect_server_details.delay(server.id)
            return redirect(url_for('index.home'))

        else:
            flash("Load balancer can't be used as gluu server", 'danger')

    return render_template('new_server.html',
                           form=form,
                           header=header,
                           server_id=None)
예제 #8
0
def restart_services(self, method):
    tid = self.request.id
    servers = Server.query.filter(Server.redis.is_(True)).filter(
        Server.stunnel.is_(True)).all()
    appconf = AppConfiguration.query.first()
    chdir = "/opt/gluu-server-" + appconf.gluu_version
    ips = []

    for server in servers:
        ips.append(server.ip)
        wlogger.log(tid, "(Re)Starting services ... ", "info",
                    server_id=server.id)
        rc = __get_remote_client(server, tid)
        if not rc:
            continue

        def get_cmd(cmd):
            if server.gluu_server and not server.os == "CentOS 7":
                return 'chroot {0} /bin/bash -c "{1}"'.format(chdir, cmd)
            elif "CentOS 7" == server.os:
                parts = ["ssh", "-o IdentityFile=/etc/gluu/keys/gluu-console",
                         "-o Port=60022", "-o LogLevel=QUIET",
                         "-o StrictHostKeyChecking=no",
                         "-o UserKnownHostsFile=/dev/null",
                         "-o PubkeyAuthentication=yes",
                         "root@localhost", "'{0}'".format(cmd)]
                return " ".join(parts)
            return cmd

        # Common restarts for all
        if server.os == 'CentOS 6':
            run_and_log(rc, 'service redis restart', tid, server.id)
            run_and_log(rc, 'service stunnel4 restart', tid, server.id)
        elif server.os == 'CentOS 7' or server.os == 'RHEL 7':
            run_and_log(rc, 'systemctl restart redis', tid, server.id)
            run_and_log(rc, 'systemctl restart stunnel', tid, server.id)
        else:
            run_and_log(rc, 'service redis-server restart', tid, server.id)
            run_and_log(rc, 'service stunnel4 restart', tid, server.id)
            # sometime apache service is stopped (happened in Ubuntu 16)
            # when install_cache_components task is executed; hence we also need to
            # restart the service
            run_and_log(rc, get_cmd('service apache2 restart'), tid, server.id)

        run_and_log(rc, get_cmd('service oxauth restart'), tid, server.id)
        run_and_log(rc, get_cmd('service identity restart'), tid, server.id)
        rc.close()

    if method != 'STANDALONE':
        wlogger.log(tid, "All services restarted.", "success")
        return

    host = appconf.nginx_host
    mock_server = Server()
    mock_server.hostname = host
    rc = __get_remote_client(mock_server, tid)
    if not rc:
        wlogger.log(tid, "Couldn't connect to proxy server to restart services"
                    "fail")
        return
    mock_server.os = get_os_type(rc)
    if mock_server.os in ['Ubuntu 14', 'Ubuntu 16', 'CentOS 6']:
        run_and_log(rc, "service stunnel4 restart", tid, None)
        run_and_log(rc, "service nutcracker restart", tid, None)
    if mock_server.os in ["CentOS 7", "RHEL 7"]:
        run_and_log(rc, "systemctl restart stunnel", tid, None)
        run_and_log(rc, "systemctl restart nutcracker", tid, None)
    rc.close()
예제 #9
0
def setup_proxied(tid):
    """Configures the servers to use the Twemproxy installed in proxy server
    for Redis caching securely via stunnel.

    :param tid: task id for log identification
    :return: None
    """
    servers = Server.query.filter(Server.redis.is_(True)).filter(
        Server.stunnel.is_(True)).all()
    appconf = AppConfiguration.query.first()
    chdir = "/opt/gluu-server-" + appconf.gluu_version
    stunnel_base_conf = [
        "cert = /etc/stunnel/cert.pem",
        "pid = /var/run/stunnel.pid",
        "output = /var/log/stunnel4/stunnel.log"
    ]
    proxy_stunnel_conf = stunnel_base_conf
    twemproxy_servers = []
    proxy_ip = socket.gethostbyname(appconf.nginx_host)
    primary = Server.query.filter(Server.primary_server.is_(True)).first()
    if not primary:
        wlogger.log(tid, "Primary Server is not setup yet. Cannot setup "
                    "clustered caching.", "error")


    # Setup Stunnel and Redis in each server
    for server in servers:
        __update_LDAP_cache_method(tid, server, 'localhost:7000', 'STANDALONE')
        stunnel_conf = [
            "[redis-server]",
            "client = no",
            "accept = {0}:7777".format(server.ip),
            "connect = 127.0.0.1:6379",
            "[twemproxy]",
            "client = yes",
            "accept = 127.0.0.1:7000",
            "connect = {0}:8888".format(proxy_ip)
        ]
        stunnel_conf = stunnel_base_conf + stunnel_conf
        status = __configure_stunnel(tid, server, stunnel_conf, chdir)
        if not status:
            continue

        # if the setup was successful add the server to the list of stunnel
        # clients in the proxy server configuration
        client_conf = [
            "[client{0}]".format(server.id),
            "client = yes",
            "accept = 127.0.0.1:{0}".format(7000+server.id),
            "connect = {0}:7777".format(server.ip)
        ]
        proxy_stunnel_conf.extend(client_conf)
        twemproxy_servers.append("   - 127.0.0.1:{0}:1".format(7000+server.id))


    wlogger.log(tid, "Configuring the proxy server ...")
    # Setup Stunnel in the proxy server
    mock_server = Server()
    mock_server.hostname = appconf.nginx_host
    mock_server.ip = proxy_ip
    rc = __get_remote_client(mock_server, tid)
    if not rc:
        wlogger.log(tid, "Couldn't connect to proxy server. Twemproxy setup "
                    "failed.", "error")
        return
    mock_server.os = get_os_type(rc)
    # Download the setup.properties file from the primary server
    local = os.path.join(app.instance_path, "setup.properties")
    remote = os.path.join("/opt/gluu-server-"+appconf.gluu_version,
                          "install", "community-edition-setup",
                          "setup.properties.last")
    prc = __get_remote_client(primary, tid)
    prc.download(remote, local)
    prc.close()
    rc.upload(local, "/tmp/setup.properties")

    twem_server_conf = [
        "[twemproxy]",
        "client = no",
        "accept = {0}:8888".format(proxy_ip),
        "connect = 127.0.0.1:2222"
    ]
    proxy_stunnel_conf.extend(twem_server_conf)
    status = __configure_stunnel(tid, mock_server, proxy_stunnel_conf, None,
                                 "/tmp/setup.properties")
    if not status:
        return False

    # Setup Twemproxy
    wlogger.log(tid, "Writing Twemproxy configuration")
    twemproxy_conf = [
        "alpha:",
        "  listen: 127.0.0.1:2222",
        "  hash: fnv1a_64",
        "  distribution: ketama",
        "  auto_eject_hosts: true",
        "  redis: true",
        "  server_failure_limit: 2",
        "  timeout: 400",
        "  preconnect: true",
        "  servers:"
    ]
    twemproxy_conf.extend(twemproxy_servers)
    remote = "/etc/nutcracker/nutcracker.yml"
    rc.put_file(remote, "\n".join(twemproxy_conf))

    wlogger.log(tid, "Configuration complete", "success")
예제 #10
0
def install_cache_components(self, method):
    """Celery task that installs the redis, stunnel and twemproxy applications
    in the required servers.

    Redis and stunnel are installed in all the servers in the cluster.
    Twemproxy is installed in the load-balancer/proxy server

    :param self: the celery task
    :param method: either STANDALONE, SHARDED

    :return: the number of servers where both stunnel and redis were installed
        successfully
    """
    tid = self.request.id
    installed = 0
    servers = Server.query.all()
    for server in servers:
        wlogger.log(tid, "Installing Redis in server {0}".format(
            server.hostname), "info", server_id=server.id)
        ri = RedisInstaller(server, tid)
        redis_installed = ri.install()
        if redis_installed:
            server.redis = True
            wlogger.log(tid, "Redis install successful", "success",
                        server_id=server.id)
        else:
            server.redis = False
            wlogger.log(tid, "Redis install failed", "fail",
                        server_id=server.id)

        wlogger.log(tid, "Installing Stunnel", "info", server_id=server.id)
        si = StunnelInstaller(server, tid)
        stunnel_installed = si.install()
        if stunnel_installed:
            server.stunnel = True
            wlogger.log(tid, "Stunnel install successful", "success",
                        server_id=server.id)
        else:
            server.stunnel = False
            wlogger.log(tid, "Stunnel install failed", "fail",
                        server_id=server.id)
        # Save the redis and stunnel install situation to the db
        db.session.commit()

        if redis_installed and stunnel_installed:
            installed += 1

    if method != 'STANDALONE':
        # No need to install twemproxy for "SHARDED" configuration
        return True

    # Install twemproxy in the Nginx load balancing proxy server
    app_conf = AppConfiguration.query.first()
    host = app_conf.nginx_host
    rc = RemoteClient(host)
    try:
        rc.startup()
    except Exception as e:
        wlogger.log(tid, "Could not connect to {0}".format(e), "error")
        return False

    server_os = get_os_type(rc)

    mock_server = Server()
    mock_server.hostname = host
    wlogger.log(tid, "Installing Stunnel in proxy server")
    si = StunnelInstaller(mock_server, tid)
    stunnel_installed = si.install()
    if stunnel_installed:
        wlogger.log(tid, "Stunnel install successful", "success")
    else:
        wlogger.log(tid, "Stunnel install failed", "fail")

    wlogger.log(tid, "Cluster manager will now try to build Twemproxy")
    # 1. Setup the development tools for installation
    if server_os in ["Ubuntu 16", "Ubuntu 14"]:
        run_and_log(rc, "apt-get update", tid)
        run_and_log(rc, "apt-get install -y build-essential autoconf libtool",
                    tid)
    elif server_os in ["CentOS 6", "CentOS 7", "RHEL 7"]:
        run_and_log(rc, "yum install -y wget", tid)
        run_and_log(rc, "yum groupinstall -y 'Development tools'", tid)

    if server_os == "CentOS 6":
        run_and_log(rc, "wget http://ftp.gnu.org/gnu/autoconf/autoconf-2.69.tar.gz",
                    tid)
        run_and_log(rc, "tar xvfvz autoconf-2.69.tar.gz", tid)
        run_and_log(rc, "cd autoconf-2.69 && ./configure", tid)
        run_and_log(rc, "cd autoconf-2.69 && make", tid)
        run_and_log(rc, "cd autoconf-2.69 && make install", tid)

    # 2. Get the source, build & install the nutcracker binaries
    run_and_log(rc, "wget https://github.com/twitter/twemproxy/archive/v0.4.1.tar.gz",
                tid)
    run_and_log(rc, "tar -xf v0.4.1.tar.gz", tid)
    run_and_log(rc, "cd twemproxy-0.4.1", tid)
    run_and_log(rc, "cd twemproxy-0.4.1 && autoreconf -fvi", tid)
    run_and_log(rc, "cd twemproxy-0.4.1 && ./configure --prefix=/usr", tid)
    run_and_log(rc, "cd twemproxy-0.4.1 && make", tid)
    run_and_log(rc, "cd twemproxy-0.4.1 && make install", tid)

    # 3. Post installation - setup user and logging
    run_and_log(rc, "useradd nutcracker", tid)
    run_and_log(rc, "mkdir /var/log/nutcracker", tid)
    run_and_log(rc, "touch /var/log/nutcracker/nutcracker.log", tid)
    run_and_log(rc, "chown -R nutcracker:nutcracker /var/log/nutcracker",
                tid)
    logrotate_conf = ["/var/log/nutcracker/nutcracker*.log {", "\tweekly",
                      "\tmissingok", "\trotate 12", "\tcompress",
                      "\tnotifempty", "}"]
    rc.put_file("/etc/logrotate.d/nutcracker", "\n".join(logrotate_conf))

    # 4. Add init/service scripts to run nutcracker as a service
    if server_os in ["Ubuntu 16", "CentOS 7", "RHEL 7"]:
        local = os.path.join(app.root_path, "templates", "twemproxy",
                             "twemproxy.service")
        remote = "/lib/systemd/system/nutcracker.service"
        rc.upload(local, remote)
        run_and_log(rc, "systemctl enable nutcracker", tid, None)
    elif server_os == "Ubuntu 14":
        local = os.path.join(app.root_path, "templates", "twemproxy",
                             "nutcracker.init")
        remote = "/etc/init.d/nutcracker"
        rc.upload(local, remote)
        run_and_log(rc, 'chmod +x /etc/init.d/nutcracker', tid)
        run_and_log(rc, "update-rc.d nutcracker defaults", tid)
    elif server_os == "CentOS 6":
        local = os.path.join(app.root_path, "templates", "twemproxy",
                             "nutcracker.centos.init")
        remote = "/etc/rc.d/init.d/nutcracker"
        rc.upload(local, remote)
        run_and_log(rc, "chmod +x /etc/init.d/nutcracker", tid)
        run_and_log(rc, "chkconfig --add nutcracker", tid)
        run_and_log(rc, "chkconfig nutcracker on", tid)

    # 5. Create the default configuration file referenced in the init scripts
    run_and_log(rc, "mkdir -p /etc/nutcracker", tid)
    run_and_log(rc, "touch /etc/nutcracker/nutcracker.yml", tid)

    rc.close()
    return installed
예제 #11
0
def step1():

    pserver = Server.query.filter_by(primary_server=True).first()
    if pserver and request.args.get('pass_set') != 'true':
        flash("Oops this service is not for you.", 'warning')
        return redirect(url_for('index.home'))

    wform = WizardStep1()

    if request.method == 'POST':
        if wform.validate_on_submit():
            replication_pw = uuid.uuid4().hex
            app_conf = AppConfiguration()
            app_conf.nginx_host = wform.new_hostname.data.strip()
            app_conf.replication_pw = replication_pw
            app_conf.nginx_ip = wform.nginx_ip.data.strip()
            app_conf.modify_hosts = True
            db.session.add(app_conf)

            server = Server()
            server.ip = wform.ip.data.strip()
            server.hostname = wform.current_hostname.data.strip()
            server.primary_server = True

            db.session.add(app_conf)
            db.session.add(server)
            db.session.commit()

    if request.method == 'POST' or request.args.get('pass_set') == 'true':

        servers = Server.query.all()

        ask_passphrase = False

        c = RemoteClient(servers[0].ip, servers[0].hostname)
        try:
            c.startup()

        except ClientNotSetupException as e:

            if str(e) == 'Pubkey is encrypted.':
                ask_passphrase = True
                flash(
                    "Pubkey seems to password protected. "
                    "Please set passphrase.", 'warning')
            elif str(e) == 'Could not deserialize key data.':
                ask_passphrase = True
                flash(
                    "Password your provided for pubkey did not work. "
                    "Please set valid passphrase.", 'warning')
            else:
                flash(
                    "SSH connection to {} failed. Please check if your pub key is "
                    "added to /root/.ssh/authorized_keys on this server. Reason: {}"
                    .format(servers[0].hostname, e), 'error')

            return render_template(
                'index_passphrase.html',
                e=e,
                ask_passphrase=ask_passphrase,
                next=url_for('wizard.step1', pass_set='true'),
                warning_text="Error accessing Stand Allone Server")

        task = wizard_step1.delay()
        print "TASK STARTED", task.id

        servers = Server.query.all()
        return render_template('wizard/wizard_logger.html',
                               step=1,
                               task_id=task.id,
                               servers=servers)

    return render_template('wizard/step1.html', wform=wform)
예제 #12
0
파일: cache.py 프로젝트: pks-os/cluster-mgr
def setup_proxied(tid, server_id_list):
    """Configures the servers to use the Twemproxy installed in proxy server
    for Redis caching securely via stunnel.

    :param tid: task id for log identification
    :return: None
    """

    servers = []

    for server_id in server_id_list:
        qserver = Server.query.filter(Server.redis.is_(True)).filter(
            Server.stunnel.is_(True)).filter(Server.id.is_(server_id)).first()
        if qserver:
            servers.append(qserver)

    appconf = AppConfiguration.query.first()
    chdir = "/opt/gluu-server-" + appconf.gluu_version

    if appconf.external_load_balancer:
        cache_ip = appconf.cache_ip
    else:
        cache_ip = appconf.nginx_ip

    primary = Server.query.filter(Server.primary_server.is_(True)).first()

    if not primary:
        wlogger.log(
            tid, "Primary Server is not setup yet. Cannot setup "
            "clustered caching.", "error")

    # Setup Stunnel and Redis in each server
    for server in servers:
        #Since replication is active, we only need to update on primary server
        if server.primary_server:
            __update_LDAP_cache_method(tid, server, 'localhost:7000',
                                       'STANDALONE')

        stunnel_conf = [
            "cert = /etc/stunnel/cert.pem", "pid = /var/run/stunnel.pid",
            "output = /var/log/stunnel4/stunnel.log", "[redis-server]",
            "client = no", "accept = {0}:7777".format(server.ip),
            "connect = 127.0.0.1:6379", "[twemproxy]", "client = yes",
            "accept = 127.0.0.1:7000", "connect = {0}:8888".format(cache_ip)
        ]

        status = __configure_stunnel(tid, server, stunnel_conf, chdir)

        if not status:
            continue

    wlogger.log(tid, "Configuring the cahce server ...")

    # Setup Stunnel in the proxy server
    mock_server = Server()

    if appconf.external_load_balancer:
        mock_server.hostname = appconf.cache_host
        mock_server.ip = appconf.cache_ip
    else:
        mock_server.hostname = appconf.nginx_host
        mock_server.ip = appconf.nginx_ip

    rc = __get_remote_client(mock_server, tid)

    if not rc:
        wlogger.log(
            tid, "Couldn't connect to proxy server. Twemproxy setup "
            "failed.", "error")
        return

    mock_server.os = get_os_type(rc)

    if rc.exists('/usr/bin/redis-server') or rc.exists('/bin/redis-server'):
        wlogger.log(
            tid, "Redis was already installed on server {0}".format(
                mock_server.hostname), "info")
    else:
        wlogger.log(
            tid, "Installing Redis in server {0}".format(mock_server.hostname),
            "info")
        ri = RedisInstaller(mock_server, tid)
        redis_installed = ri.install()
        if redis_installed:
            mock_server.redis = True
            wlogger.log(tid, "Redis install successful", "success")
        else:
            mock_server.redis = False
            wlogger.log(tid, "Redis install failed", "fail")

    # Download the setup.properties file from the primary server
    local = os.path.join(app.instance_path, "setup.properties")
    remote = os.path.join("/opt/gluu-server-" + appconf.gluu_version,
                          "install", "community-edition-setup",
                          "setup.properties.last")
    prc = __get_remote_client(primary, tid)
    prc.download(remote, local)
    prc.close()
    rc.upload(local, "/tmp/setup.properties")

    proxy_stunnel_conf = make_proxy_stunnel_conf()

    status = __configure_stunnel(tid, mock_server, proxy_stunnel_conf, None,
                                 "/tmp/setup.properties")
    if not status:
        return False

    # Setup Twemproxy
    wlogger.log(tid, "Writing Twemproxy configuration")
    twemproxy_conf = make_twem_proxy_conf()
    remote = "/etc/nutcracker/nutcracker.yml"
    rc.put_file(remote, twemproxy_conf)
    run_command(tid, rc, 'service nutcracker restart')

    wlogger.log(tid, "Configuration complete", "success")
예제 #13
0
파일: cache.py 프로젝트: pks-os/cluster-mgr
def install_cache_components(self, method, server_id_list):
    """Celery task that installs the redis, stunnel and twemproxy applications
    in the required servers.

    Redis and stunnel are installed in all the servers in the cluster.
    Twemproxy is installed in the load-balancer/proxy server

    :param self: the celery task
    :param method: either STANDALONE, SHARDED

    :return: the number of servers where both stunnel and redis were installed
        successfully
    """

    tid = self.request.id
    installed = 0

    servers = []

    for server_id in server_id_list:

        server = Server.query.get(server_id)

        ri = RedisInstaller(server, tid)
        ri.rc.startup()
        if ri.rc.exists('/usr/bin/redis-server') or ri.rc.exists(
                '/bin/redis-server'):
            server.redis = True
            redis_installed = 1
            wlogger.log(tid,
                        "Redis was already installed on server {0}".format(
                            server.hostname),
                        "info",
                        server_id=server.id)
        else:
            wlogger.log(tid,
                        "Installing Redis in server {0}".format(
                            server.hostname),
                        "info",
                        server_id=server.id)
            redis_installed = ri.install()
            if redis_installed:
                server.redis = True
                wlogger.log(tid,
                            "Redis install successful",
                            "success",
                            server_id=server.id)
            else:
                server.redis = False
                wlogger.log(tid,
                            "Redis install failed",
                            "fail",
                            server_id=server.id)

        si = StunnelInstaller(server, tid)
        si.rc.startup()
        if si.rc.exists('/usr/bin/stunnel') or si.rc.exists('/bin/stunnel'):
            wlogger.log(tid,
                        "Stunnel was allready installed",
                        "info",
                        server_id=server.id)
            server.stunnel = True
            stunnel_installed = 1
        else:
            wlogger.log(tid, "Installing Stunnel", "info", server_id=server.id)

            stunnel_installed = si.install()
            if stunnel_installed:
                server.stunnel = True
                wlogger.log(tid,
                            "Stunnel install successful",
                            "success",
                            server_id=server.id)
            else:
                server.stunnel = False
                wlogger.log(tid,
                            "Stunnel install failed",
                            "fail",
                            server_id=server.id)
            # Save the redis and stunnel install situation to the db

        if redis_installed and stunnel_installed:
            installed += 1

        db.session.commit()
    if method != 'STANDALONE':
        # No need to install twemproxy for "SHARDED" configuration
        return True

    # Install twemproxy in the Nginx load balancing proxy server
    app_conf = AppConfiguration.query.first()

    mock_server = Server()

    if app_conf.external_load_balancer:
        mock_server.hostname = app_conf.cache_host
        mock_server.ip = app_conf.cache_ip
    else:
        mock_server.hostname = app_conf.nginx_host
        mock_server.ip = app_conf.nginx_ip

    rc = RemoteClient(mock_server.hostname)

    try:
        rc.startup()
    except Exception as e:
        wlogger.log(tid, "Could not connect to {0}".format(e), "error")
        return False

    server_os = get_os_type(rc)

    si = StunnelInstaller(mock_server, tid)
    si.rc.startup()
    stunnel_installed = 0
    if si.rc.exists('/usr/bin/stunnel') or si.rc.exists('/bin/stunnel'):
        wlogger.log(tid, "Stunnel was already installed on cache server")
        stunnel_installed = 1
    else:
        wlogger.log(tid, "Installing Stunnel in cache server")
        stunnel_installed = si.install()
        if stunnel_installed:
            wlogger.log(tid, "Stunnel install successful", "success")
        else:
            wlogger.log(tid, "Stunnel install failed", "fail")

    print rc.exists('/usr/sbin/nutcracker')

    if not rc.exists('/usr/sbin/nutcracker'):

        wlogger.log(tid, "Installing Twemproxy")
        # 1. Setup the development tools for installation
        if server_os == "Ubuntu 14":
            run_and_log(rc, "apt-get update", tid)
            run_and_log(
                rc,
                'wget http://ftp.debian.org/debian/pool/main/n/nutcracker/nutcracker_0.4.0+dfsg-1_amd64.deb -O /tmp/nutcracker_0.4.0+dfsg-1_amd64.deb',
                tid)
            run_and_log(rc, "dpkg -i /tmp/nutcracker_0.4.0+dfsg-1_amd64.deb",
                        tid)
        elif server_os == "Ubuntu 16":
            run_and_log(rc, "apt-get update", tid)
            run_and_log(
                rc,
                "DEBIAN_FRONTEND=noninteractive apt-get install -y nutcracker",
                tid)
        elif server_os in ["CentOS 7", "RHEL 7"]:
            run_and_log(
                rc,
                'yum install -y https://raw.githubusercontent.com/mbaser/gluu/master/nutcracker-0.4.1-1.gluu.centos7.x86_64.rpm',
                tid)
            run_and_log(rc, 'chkconfig nutcracker on', tid)
        elif server_os in ['CentOS 6', 'RHEL 6']:
            run_and_log(
                rc,
                'yum install -y https://raw.githubusercontent.com/mbaser/gluu/master/nutcracker-0.4.1-1.gluu.centos6.x86_64.rpm',
                tid)
            run_and_log(rc, 'chkconfig nutcracker on', tid)

        # 5. Create the default configuration file referenced in the init scripts
        #run_and_log(rc, "mkdir -p /etc/nutcracker", tid)
        run_and_log(rc, "touch /etc/nutcracker/nutcracker.yml", tid)
    else:
        wlogger.log(tid, "Twemproxy was already installed on cache server")
    rc.close()
    return installed