diff options
| author | LV-426 <lv-426@taproot.org.il> | 2015-04-27 16:31:33 +0300 |
|---|---|---|
| committer | LV-426 <lv-426@taproot.org.il> | 2015-04-29 17:54:49 +0300 |
| commit | 51f525e8424f445a4daeb5cdeba7ceb89cd9ad02 (patch) | |
| tree | 1a39d3f8a93a688f56e1e3c56b076f510413fe6a /src/local/rz-mux | |
| parent | 7f3e4f1762cedd7b20c211ddbc6f3b0a05b19414 (diff) | |
wip: widen tool scope: neo4j-mux -> rz-mux
Diffstat (limited to 'src/local/rz-mux')
| -rw-r--r-- | src/local/rz-mux/rz-mux-tool.py | 89 | ||||
| -rw-r--r-- | src/local/rz-mux/rz-mux-tool.sh | 143 |
2 files changed, 232 insertions, 0 deletions
diff --git a/src/local/rz-mux/rz-mux-tool.py b/src/local/rz-mux/rz-mux-tool.py new file mode 100644 index 00000000..9c5ad9c0 --- /dev/null +++ b/src/local/rz-mux/rz-mux-tool.py @@ -0,0 +1,89 @@ +""" + Multiplexed-Rhizi instance configuration generator: + - setup Neo4J domain instance + - setup Rhizi domain instance +""" +import argparse +from jinja2 import Environment, FileSystemLoader +import os +import pwd +import random + + +class Template_Task(): + + def __init__(self, template_path, dst_path, kv_set): + self.jinja_tmpl = env.get_template(template_path) + self.dst_path = dst_path + self.kv_set = kv_set + + def do_exec(self): + + dst_dir = os.path.dirname(self.dst_path) + if not os.path.exists(dst_dir): + print('rz-mux-tool: warning: target dir missing, installing: %s, please adjust usr/grp' % (dst_dir)) + os.makedirs(dst_dir) + + with open(self.dst_path, 'w') as f_out: + f_out.write(self.jinja_tmpl.render(**self.kv_set)) + + print('rz-mux-tool: generated: %s' % (f_out.name)) + +def gen_dom_config__neo4j(domain_name): + """ + Generate domain-specific neo4j configuration file set + """ + + neo4j_template_path_prefix = 'neo4j-conf-template.d' + target_dir = os.path.join('etc/neo4j/instance-conf.d', args.domain) + port_seed = 10000 + random.randint(1000, 9990) + + conf_task_set = [Template_Task(os.path.join(neo4j_template_path_prefix, 'neo4j-server.properties.jinja'), + os.path.join(install_prefix, target_dir, 'neo4j-server.properties'), + {'org_neo4j_server_webserver_https_port': port_seed, + 'org_neo4j_server_webserver_port': port_seed + 1}), + Template_Task(os.path.join(neo4j_template_path_prefix, 'neo4j.properties.jinja'), + os.path.join(install_prefix, target_dir, 'neo4j.properties'), + {'remote_shell_port': port_seed + 2}), + Template_Task(os.path.join(neo4j_template_path_prefix, 'neo4j-service_deomain-init-script.jinja'), + os.path.join(install_prefix, 'etc/init.d/', 'neo4j-service__%s' % (domain_name)), + {'domain_name': domain_name}), + ] + + for conf_task_obj in conf_task_set: + conf_task_obj.do_exec() + +def gen_dom_config__apache(domain_name): + """ + Generate domain-specific neo4j configuration file set + """ + apache_template_path_prefix = 'apache-conf-template.d' + rhizi_top_domain_name = 'rhizi.net' + domain_fqdn = '%s.%s' % (domain_name, rhizi_top_domain_name) + + conf_task_set = [Template_Task(os.path.join(apache_template_path_prefix, 'x.%s.conf' % (rhizi_top_domain_name)), + os.path.join(install_prefix, 'etc/apache/sites-available', domain_fqdn), + {'domain_name': domain_name}), + ] + + for conf_task_obj in conf_task_set: + conf_task_obj.do_exec() + +def gen_dom_config__rhizi(domain_name): + pass + +if __name__ == '__main__': + global env + global install_prefix + + p = argparse.ArgumentParser(description='rz-cli tool') + p.add_argument('-d', '--domain', required=True, help='target domain name') + p.add_argument('--install-prefix', default='/', help='install dir path prefix, default=\'/\'') + p.add_argument('--template-dir', default='conf-template.d', help='path to template dir') # default devied from installed pkg layout + args = p.parse_args() + + install_prefix = args.install_prefix + + env = Environment(loader=FileSystemLoader(args.template_dir)) + gen_dom_config__neo4j(domain_name=args.domain) + gen_dom_config__apache(domain_name=args.domain) diff --git a/src/local/rz-mux/rz-mux-tool.sh b/src/local/rz-mux/rz-mux-tool.sh new file mode 100644 index 00000000..5dc597f0 --- /dev/null +++ b/src/local/rz-mux/rz-mux-tool.sh @@ -0,0 +1,143 @@ +#!/bin/bash + +# +# Multiplexed Neo4J instance installer +# +# generated config dir structure: +# +# /etc/neo4j/mux-conf.d/ +# └── dom-x +# ├── neo4j.properties +# ├── neo4j-server.properties +# └── ... +# +# generated root dir structure: +# +# /var/lib/neo4j/mux-root.d/ +# └── dom-x +# ├── data/ +# ├── bin -> /var/lib/neo4j/bin +# ├── conf -> /etc/neo4j/mux-conf.d/dom-y +# ├── lib -> /usr/share/neo4j/lib +# ├── plugins -> /usr/share/neo4j/plugins +# └── system -> /usr/share/neo4j/system +# + +die() { + echo $1 1>&2; exit 1 +} + +install_instance__neo4j() { + + [[ -e "/etc/init.d/${RZ_NEO4J_SVC_NAME}" ]] && die "${RZ_NEO4J_SVC_NAME} already installed." + + install -v --owner=${NEO4J_USER} --group=adm --directory /etc/neo4j/mux-conf.d/${RZ_INSTANCE_NAME} + install -v --owner=${NEO4J_USER} --group=adm --directory /etc/neo4j/mux-conf.d/${RZ_INSTANCE_NAME} + install -v --owner=${NEO4J_USER} --group=adm --directory /etc/neo4j/mux-conf.d/${RZ_INSTANCE_NAME}/ssl + install -v --owner=${NEO4J_USER} --group=adm --directory /var/lib/neo4j/mux-root.d/${RZ_INSTANCE_NAME} + install -v --owner=${NEO4J_USER} --group=adm --directory /var/lib/neo4j/mux-root.d/${RZ_INSTANCE_NAME}/data + + cp /etc/neo4j/custom-logback.xml \ + /etc/neo4j/jmx.access \ + /etc/neo4j/jmx.password \ + /etc/neo4j/logging.properties \ + /etc/neo4j/neo4j-http-logging.xml \ + /etc/neo4j/neo4j.properties \ + /etc/neo4j/neo4j-server.properties \ + /etc/neo4j/neo4j-wrapper.conf \ + /etc/neo4j/mux-conf.d/${RZ_INSTANCE_NAME} + + cp /etc/neo4j/custom-logback.xml \ + /etc/neo4j/ssl/snakeoil.cert \ + /etc/neo4j/ssl/snakeoil.key \ + /etc/neo4j/mux-conf.d/${RZ_INSTANCE_NAME}/ssl + + ln -vs -T /etc/neo4j/mux-conf.d/${RZ_INSTANCE_NAME} /var/lib/neo4j/mux-root.d/${RZ_INSTANCE_NAME}/conf + ln -vs -T /var/lib/neo4j/bin /var/lib/neo4j/mux-root.d/${RZ_INSTANCE_NAME}/bin + ln -vs -T /usr/share/neo4j/lib /var/lib/neo4j/mux-root.d/${RZ_INSTANCE_NAME}/lib + ln -vs -T /usr/share/neo4j/plugins /var/lib/neo4j/mux-root.d/${RZ_INSTANCE_NAME}/plugins + ln -vs -T /usr/share/neo4j/system /var/lib/neo4j/mux-root.d/${RZ_INSTANCE_NAME}/system + + python /tmp/neo-m/neo4j-mux-tool.py --domain ${RZ_INSTANCE_NAME} + + # set modes, ownership + chmod +x ${SVC_INIT_SCRIPT_PATH} +} + +install_instance__apache() { + install -v --owner=${APACHE_USER} --group=${APACHE_USER} --directory /srv/rhizi/mux-root.d/${RZ_INSTANCE_NAME} + install -v --owner=${APACHE_USER} --group=${APACHE_USER} --directory /srv/rhizi/mux-root.d/${RZ_INSTANCE_NAME}/webapp + install -v --owner=${APACHE_USER} --group=${APACHE_USER} --directory /srv/rhizi/mux-root.d/${RZ_INSTANCE_NAME}/auth + + ln -vs -T /etc/rhizi/mux-conf.d/${RZ_INSTANCE_NAME} /srv/rhizi/mux-root.d/${RZ_INSTANCE_NAME}/webapp/etc + ln -vs -T /usr/share/rhizi/webapp/static/ /srv/rhizi/mux-root.d/${RZ_INSTANCE_NAME}/webapp/static + ln -vs -T /usr/share/rhizi/webapp/templates/ /srv/rhizi/mux-root.d/${RZ_INSTANCE_NAME}/webapp/templates + + apache_site_conf=${RZ_INSTANCE_NAME}.${RZ_TOP_DOMAIN_NAME} + ln -vs -T /etc/apache/sites-available/${apache_site_conf} /etc/apache/sites-enabled/${apache_site_conf} + ln -vs -T /etc/apache/sites-available/${apache_site_conf} /etc/apache/sites-enabled/${apache_site_conf} +} + +install_instance__rz() { + install -v --owner=${NEO4J_USER} --group=adm --directory /etc/rhizi/mux-conf.d/${RZ_INSTANCE_NAME} + + cp /etc/rhizi/rhizi-server.conf.example /etc/rhizi/mux-conf.d/${RZ_INSTANCE_NAME}/ +} + +uninstall_instance__apache() { + rm -rvf /srv/rhizi/mux-root.d/${RZ_INSTANCE_NAME} +} + +uninstall_instance__neo4j() { + rm ${SVC_INIT_SCRIPT_PATH} + rm -rf /etc/neo4j/mux-conf.d/${RZ_INSTANCE_NAME} + rm -rf /var/lib/neo4j/mux-root.d/${RZ_INSTANCE_NAME} +} + +uninstall_instance__rz() { + rm -rvf /etc/rhizi/mux-conf.d/${RZ_INSTANCE_NAME} +} + +DEFAULT_USER='neo4j' + +NEO4J_HOME=`(cd $(dirname $0)/.. && pwd)` +NEO4J_USER=neo4j + +APACHE_USER=www-data + +SCRIPT_NAME="${NEO4J_HOME}/bin/neo4j" + +RZ_TOP_DOMAIN_NAME=rhizi.net +RZ_NEO4J_SVC_NAME='neo4j-service__domain-x' +SVC_INIT_SCRIPT_PATH=/etc/init.d/${RZ_NEO4J_SVC_NAME} + +PID_FILE=/var/run/${RZ_NEO4J_SVC_NAME} + +RZ_INSTANCE_NAME=$2 + +[ $UID != 0 ] && die 'must be root to continue.' +[ -z ${RZ_INSTANCE_NAME} ] && die 'RZ_INSTANCE_NAME arg missing, aborting' +[ -e "$PID_FILE" ] && die '${RZ_NEO4J_SVC_NAME} already running, please stop it before continuing' + +case $1 in + install) + install_instance__apache + install_instance__neo4j + install_instance__rz + + tree /srv/www/rhizi/ + tree /var/lib/neo4j/mux-root.d/ + tree /etc/neo4j/mux-conf.d/ + tree /srv/www/rhizi/mux-root.d/ + + echo "please edit & enable rz_config at /etc/rhizi/mux-conf.d/${RZ_INSTANCE_NAME}/" + ;; + uninstall) + uninstall_instance__apache + uninstall_instance__neo4j + uninstall_instance__rz + ;; + *) + echo "Usage: $0 <install|remove>" + ;; +esac |
