From 89de48c8dee8bad200230192ca723ceb968e870c Mon Sep 17 00:00:00 2001 From: "Alexey.Golubev" Date: Mon, 11 Jul 2016 11:47:22 +0300 Subject: [PATCH] added data container for onlyoffice-documentserver --- docker-compose.yml | 42 +++++--- run-document-server.sh | 214 +++++++++++++++++++++++++---------------- 2 files changed, 158 insertions(+), 98 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index a1f44b6..292f7cc 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,11 +1,8 @@ version: '2' services: - onlyoffice-document: + onlyoffice-documentserver-data: + container_name: onlyoffice-documentserver-data image: onlyoffice/4testing-documentserver:latest - depends_on: - - onlyoffice-mysql - - onlyoffice-redis - - onlyoffice-rabbitmq environment: - MYSQL_SERVER_HOST=onlyoffice-mysql - MYSQL_SERVER_PORT=3306 @@ -16,6 +13,26 @@ services: - RABBITMQ_SERVER_PASS=guest - REDIS_SERVER_HOST=onlyoffice-redis - REDIS_SERVER_PORT=6379 + stdin_open: true + tty: true + restart: always + networks: + - onlyoffice + volumes: + - /var/www/onlyoffice/Data + - /var/log/onlyoffice + - /var/lib/onlyoffice/documentserver/App_Data/cache/files + - /var/www/onlyoffice/documentserver-example/public/files + - /usr/share/fonts + + onlyoffice-documentserver: + image: onlyoffice/4testing-documentserver:latest + depends_on: + - onlyoffice-documentserver-data + - onlyoffice-mysql + - onlyoffice-redis + - onlyoffice-rabbitmq + environment: - HTTP_CHECK=HEAD /healthcheck - EXTRA_SETTINGS=http-check expect status 200 stdin_open: true @@ -26,24 +43,21 @@ services: expose: - '80' - '443' - volumes: - - document_data:/var/www/onlyoffice/Data - - document_log:/var/log/onlyoffice - - document_files:/var/lib/onlyoffice/documentserver/App_Data/cache/files - - document_example_files:/var/www/onlyoffice/documentserver-example/public/files + volumes_from: + - onlyoffice-documentserver-data: onlyoffice-haproxy: container_name: onlyoffice-haproxy image: dockercloud/haproxy:1.2.1 depends_on: - - onlyoffice-document + - onlyoffice-documentserver environment: - MODE=tcp - TCP_PORTS="80, 443" stdin_open: true tty: true links: - - onlyoffice-document + - onlyoffice-documentserver volumes: - /var/run/docker.sock:/var/run/docker.sock restart: always @@ -93,7 +107,3 @@ networks: volumes: mysql_data: - document_data: - document_log: - document_files: - document_example_files: diff --git a/run-document-server.sh b/run-document-server.sh index 89a0bcc..901ad09 100644 --- a/run-document-server.sh +++ b/run-document-server.sh @@ -4,7 +4,7 @@ APP_DIR="/var/www/onlyoffice/documentserver" DATA_DIR="/var/www/onlyoffice/Data" LOG_DIR="/var/log/onlyoffice/documentserver" -ONLYOFFICE_HTTPS=${ONLYOFFICE_HTTPS:-false} +ONLYOFFICE_DATA_CONTAINER=${ONLYOFFICE_DATA_CONTAINER:-false} SSL_CERTIFICATES_DIR="${DATA_DIR}/certs" SSL_CERTIFICATE_PATH=${SSL_CERTIFICATE_PATH:-${SSL_CERTIFICATES_DIR}/onlyoffice.crt} @@ -24,76 +24,62 @@ NGINX_WORKER_CONNECTIONS=${NGINX_WORKER_CONNECTIONS:-$(ulimit -n)} ONLYOFFICE_DEFAULT_CONFIG=/etc/onlyoffice/documentserver/default.json -MYSQL_SERVER_HOST=${MYSQL_SERVER_HOST:-"localhost"} -MYSQL_SERVER_PORT=${MYSQL_SERVER_PORT:-"3306"} -MYSQL_SERVER_DB_NAME=${MYSQL_SERVER_DB_NAME:-"onlyoffice"} -MYSQL_SERVER_USER=${MYSQL_SERVER_USER:-"root"} -MYSQL_SERVER_PASS=${MYSQL_SERVER_PASS:-""} +JSON="json -q -f ${ONLYOFFICE_DEFAULT_CONFIG}" -RABBITMQ_SERVER_HOST=${RABBITMQ_SERVER_HOST:-"localhost"} -RABBITMQ_SERVER_USER=${RABBITMQ_SERVER_USER:-"guest"} -RABBITMQ_SERVER_PASS=${RABBITMQ_SERVER_PASS:-"guest"} +MYSQL_SERVER_HOST=${MYSQL_SERVER_HOST:-$(${JSON} services.CoAuthoring.sql.dbHost)} +MYSQL_SERVER_PORT=${MYSQL_SERVER_PORT:-$(${JSON} services.CoAuthoring.sql.dbPort)} +MYSQL_SERVER_DB_NAME=${MYSQL_SERVER_DB_NAME:-$(${JSON} services.CoAuthoring.sql.dbName)} +MYSQL_SERVER_USER=${MYSQL_SERVER_USER:-$(${JSON} services.CoAuthoring.sql.dbUser)} +MYSQL_SERVER_PASS=${MYSQL_SERVER_PASS:-$(${JSON} services.CoAuthoring.sql.dbPass)} -REDIS_SERVER_HOST=${REDIS_SERVER_HOST:-"localhost"} -REDIS_SERVER_PORT=${REDIS_SERVER_PORT:-"6379"} +RABBITMQ_SERVER_URL=$(${JSON} rabbitmq.url) +RABBITMQ_SERVER_HOST=${RABBITMQ_SERVER_HOST:-${RABBITMQ_SERVER_URL#'amqp://'}} +RABBITMQ_SERVER_USER=${RABBITMQ_SERVER_USER:-$(${JSON} rabbitmq.login)} +RABBITMQ_SERVER_PASS=${RABBITMQ_SERVER_PASS:-$(${JSON} rabbitmq.password)} +RABBITMQ_SERVER_PORT=${RABBITMQ_SERVER_PORT:-"5672"} -# create base folders -for i in converter docservice spellchecker metrics gc; do - mkdir -p "${LOG_DIR}/$i" -done +REDIS_SERVER_HOST=${REDIS_SERVER_HOST:-$(${JSON} services.CoAuthoring.redis.host)} +REDIS_SERVER_PORT=${REDIS_SERVER_PORT:-$(${JSON} services.CoAuthoring.redis.port)} -mkdir -p ${LOG_DIR}-example +waiting_for_connection(){ + until nc -z -w 3 "$1" "$2"; do + >&2 echo "Waiting for connection to the $1 host on port $2" + sleep 1 + done +} -# Set up nginx -sed 's/^worker_processes.*/'"worker_processes ${NGINX_WORKER_PROCESSES};"'/' -i ${NGINX_CONFIG_PATH} -sed 's/worker_connections.*/'"worker_connections ${NGINX_WORKER_CONNECTIONS};"'/' -i ${NGINX_CONFIG_PATH} -sed 's/access_log.*/'"access_log off;"'/' -i ${NGINX_CONFIG_PATH} +waiting_for_mysql(){ + waiting_for_connection ${MYSQL_SERVER_HOST} ${MYSQL_SERVER_PORT} +} -# setup HTTPS -if [ -f "${SSL_CERTIFICATE_PATH}" -a -f "${SSL_KEY_PATH}" ]; then - cp ${SYSCONF_TEMPLATES_DIR}/nginx/onlyoffice-documentserver-ssl.conf ${NGINX_ONLYOFFICE_PATH} +waiting_for_rabbitmq(){ + waiting_for_connection ${RABBITMQ_SERVER_HOST} ${RABBITMQ_SERVER_PORT} +} - mkdir ${DATA_DIR} +waiting_for_redis(){ + waiting_for_connection ${REDIS_SERVER_HOST} ${REDIS_SERVER_PORT} +} - # configure nginx - sed 's,{{SSL_CERTIFICATE_PATH}},'"${SSL_CERTIFICATE_PATH}"',' -i ${NGINX_ONLYOFFICE_PATH} - sed 's,{{SSL_KEY_PATH}},'"${SSL_KEY_PATH}"',' -i ${NGINX_ONLYOFFICE_PATH} +update_mysql_settings(){ + ${JSON} -I -e "this.services.CoAuthoring.sql.dbHost = '${MYSQL_SERVER_HOST}'" + ${JSON} -I -e "this.services.CoAuthoring.sql.dbPort = '${MYSQL_SERVER_PORT}'" + ${JSON} -I -e "this.services.CoAuthoring.sql.dbName = '${MYSQL_SERVER_DB_NAME}'" + ${JSON} -I -e "this.services.CoAuthoring.sql.dbUser = '${MYSQL_SERVER_USER}'" + ${JSON} -I -e "this.services.CoAuthoring.sql.dbPass = '${MYSQL_SERVER_PASS}'" +} - # if dhparam path is valid, add to the config, otherwise remove the option - if [ -r "${SSL_DHPARAM_PATH}" ]; then - sed 's,{{SSL_DHPARAM_PATH}},'"${SSL_DHPARAM_PATH}"',' -i ${NGINX_ONLYOFFICE_PATH} - else - sed '/ssl_dhparam {{SSL_DHPARAM_PATH}};/d' -i ${NGINX_ONLYOFFICE_PATH} - fi +update_rabbitmq_setting(){ + ${JSON} -I -e "this.rabbitmq.url = 'amqp://${RABBITMQ_SERVER_HOST}'" + ${JSON} -I -e "this.rabbitmq.login = '${RABBITMQ_SERVER_USER}'" + ${JSON} -I -e "this.rabbitmq.password = '${RABBITMQ_SERVER_PASS}'" +} - sed 's,{{SSL_VERIFY_CLIENT}},'"${SSL_VERIFY_CLIENT}"',' -i ${NGINX_ONLYOFFICE_PATH} - - if [ -f "${CA_CERTIFICATES_PATH}" ]; then - sed 's,{{CA_CERTIFICATES_PATH}},'"${CA_CERTIFICATES_PATH}"',' -i ${NGINX_ONLYOFFICE_PATH} - else - sed '/{{CA_CERTIFICATES_PATH}}/d' -i ${NGINX_ONLYOFFICE_PATH} - fi - - if [ "${ONLYOFFICE_HTTPS_HSTS_ENABLED}" == "true" ]; then - sed 's/{{ONLYOFFICE_HTTPS_HSTS_MAXAGE}}/'"${ONLYOFFICE_HTTPS_HSTS_MAXAGE}"'/' -i ${NGINX_ONLYOFFICE_PATH} - else - sed '/{{ONLYOFFICE_HTTPS_HSTS_MAXAGE}}/d' -i ${NGINX_ONLYOFFICE_PATH} - fi -else - cp ${SYSCONF_TEMPLATES_DIR}/nginx/onlyoffice-documentserver.conf ${NGINX_ONLYOFFICE_PATH} -fi - -JSON="json -I -q -f ${ONLYOFFICE_DEFAULT_CONFIG}" - -if [ ${MYSQL_SERVER_HOST} != "localhost" ]; then - - # Change mysql settings - ${JSON} -e "this.services.CoAuthoring.sql.dbHost = '${MYSQL_SERVER_HOST}'" - ${JSON} -e "this.services.CoAuthoring.sql.dbPort = '${MYSQL_SERVER_PORT}'" - ${JSON} -e "this.services.CoAuthoring.sql.dbName = '${MYSQL_SERVER_DB_NAME}'" - ${JSON} -e "this.services.CoAuthoring.sql.dbUser = '${MYSQL_SERVER_USER}'" - ${JSON} -e "this.services.CoAuthoring.sql.dbPass = '${MYSQL_SERVER_PASS}'" +update_redis_settings(){ + ${JSON} -I -e "this.services.CoAuthoring.redis.host = '${REDIS_SERVER_HOST}'" + ${JSON} -I -e "this.services.CoAuthoring.redis.port = '${REDIS_SERVER_PORT}'" +} +create_mysql_db(){ MYSQL="mysql -s -h${MYSQL_SERVER_HOST} -u${MYSQL_SERVER_USER}" if [ -n "${MYSQL_SERVER_PASS}" ]; then MYSQL="$MYSQL -p${MYSQL_SERVER_PASS}" @@ -102,38 +88,102 @@ if [ ${MYSQL_SERVER_HOST} != "localhost" ]; then # Create db on remote server ${MYSQL} -e "CREATE DATABASE IF NOT EXISTS ${MYSQL_SERVER_DB_NAME} CHARACTER SET utf8 COLLATE 'utf8_general_ci';" ${MYSQL} "${MYSQL_SERVER_DB_NAME}" < "${APP_DIR}/server/schema/createdb.sql" +} + +start_nginx(){ + # Set up nginx + sed 's/^worker_processes.*/'"worker_processes ${NGINX_WORKER_PROCESSES};"'/' -i ${NGINX_CONFIG_PATH} + sed 's/worker_connections.*/'"worker_connections ${NGINX_WORKER_CONNECTIONS};"'/' -i ${NGINX_CONFIG_PATH} + sed 's/access_log.*/'"access_log off;"'/' -i ${NGINX_CONFIG_PATH} + + # setup HTTPS + if [ -f "${SSL_CERTIFICATE_PATH}" -a -f "${SSL_KEY_PATH}" ]; then + cp ${SYSCONF_TEMPLATES_DIR}/nginx/onlyoffice-documentserver-ssl.conf ${NGINX_ONLYOFFICE_PATH} + + mkdir ${DATA_DIR} + + # configure nginx + sed 's,{{SSL_CERTIFICATE_PATH}},'"${SSL_CERTIFICATE_PATH}"',' -i ${NGINX_ONLYOFFICE_PATH} + sed 's,{{SSL_KEY_PATH}},'"${SSL_KEY_PATH}"',' -i ${NGINX_ONLYOFFICE_PATH} + + # if dhparam path is valid, add to the config, otherwise remove the option + if [ -r "${SSL_DHPARAM_PATH}" ]; then + sed 's,{{SSL_DHPARAM_PATH}},'"${SSL_DHPARAM_PATH}"',' -i ${NGINX_ONLYOFFICE_PATH} + else + sed '/ssl_dhparam {{SSL_DHPARAM_PATH}};/d' -i ${NGINX_ONLYOFFICE_PATH} + fi + + sed 's,{{SSL_VERIFY_CLIENT}},'"${SSL_VERIFY_CLIENT}"',' -i ${NGINX_ONLYOFFICE_PATH} + + if [ -f "${CA_CERTIFICATES_PATH}" ]; then + sed 's,{{CA_CERTIFICATES_PATH}},'"${CA_CERTIFICATES_PATH}"',' -i ${NGINX_ONLYOFFICE_PATH} + else + sed '/{{CA_CERTIFICATES_PATH}}/d' -i ${NGINX_ONLYOFFICE_PATH} + fi + + if [ "${ONLYOFFICE_HTTPS_HSTS_ENABLED}" == "true" ]; then + sed 's/{{ONLYOFFICE_HTTPS_HSTS_MAXAGE}}/'"${ONLYOFFICE_HTTPS_HSTS_MAXAGE}"'/' -i ${NGINX_ONLYOFFICE_PATH} + else + sed '/{{ONLYOFFICE_HTTPS_HSTS_MAXAGE}}/d' -i ${NGINX_ONLYOFFICE_PATH} + fi + else + cp ${SYSCONF_TEMPLATES_DIR}/nginx/onlyoffice-documentserver.conf ${NGINX_ONLYOFFICE_PATH} + fi + + #start service + service nginx start +} + +start_supervisor(){ + # Copy modified supervisor start script + cp ${SYSCONF_TEMPLATES_DIR}/supervisor/supervisor /etc/init.d/ + # Copy modified supervisor config + cp ${SYSCONF_TEMPLATES_DIR}/supervisor/supervisord.conf /etc/supervisor/supervisord.conf + + #start service + service supervisor start +} + +# create base folders +for i in converter docservice spellchecker metrics gc; do + mkdir -p "${LOG_DIR}/$i" +done + +mkdir -p ${LOG_DIR}-example + +if [ ${MYSQL_SERVER_HOST} != "localhost" ]; then + update_mysql_settings + create_mysql_db else - service mysql start + if [ ${ONLYOFFICE_DATA_CONTAINER} != "true" ]; then + service mysql start + fi fi if [ ${RABBITMQ_SERVER_HOST} != "localhost" ]; then - - # Change rabbitmq settings - ${JSON} -e "this.rabbitmq.url = 'amqp://${RABBITMQ_SERVER_HOST}'" - ${JSON} -e "this.rabbitmq.login = '${RABBITMQ_SERVER_USER}'" - ${JSON} -e "this.rabbitmq.password = '${RABBITMQ_SERVER_PASS}'" - + update_rabbitmq_setting else - service redis-server start + if [ ${ONLYOFFICE_DATA_CONTAINER} != "true" ]; then + service redis-server start + fi fi if [ ${REDIS_SERVER_HOST} != "localhost" ]; then - - # Change redis settings - ${JSON} -e "this.services.CoAuthoring.redis.host = '${REDIS_SERVER_HOST}'" - ${JSON} -e "this.services.CoAuthoring.redis.port = '${REDIS_SERVER_PORT}'" - + update_redis_settings else - service rabbitmq-server start + if [ ${ONLYOFFICE_DATA_CONTAINER} != "true" ]; then + service rabbitmq-server start + fi fi -# Copy modified supervisor start script -cp ${SYSCONF_TEMPLATES_DIR}/supervisor/supervisor /etc/init.d/ -# Copy modified supervisor config -cp ${SYSCONF_TEMPLATES_DIR}/supervisor/supervisord.conf /etc/supervisor/supervisord.conf - -service nginx start -service supervisor start +if [ ${ONLYOFFICE_DATA_CONTAINER} != "true" ]; then + waiting_for_mysql + waiting_for_rabbitmq + waiting_for_redis + + start_nginx + start_supervisor +fi # Regenerate the fonts list and the fonts thumbnails -documentserver-generate-allfonts.sh +documentserver-generate-allfonts.sh ${ONLYOFFICE_DATA_CONTAINER} \ No newline at end of file