Make nginx and collectd dynamic config

With nginx and collect being dynamic, we do no need to regenerate
this for updates where the cloud version does not change

Part of #342
This commit is contained in:
Girish Ramakrishnan
2015-04-22 10:17:41 -07:00
parent 95d22c8986
commit 73de1a7c4e
8 changed files with 34 additions and 33 deletions
+2 -2
View File
@@ -37,8 +37,8 @@ setup_cloud.sh
Containers are relaunched based on the CLOUD_VERSION. The script compares
the version here with the version in the file DATA_DIR/CLOUD_VERSION.
If they match, the containers are not recreated. The apps are marked for "reuse".
In "reuse" state, the apptask merely generates the nginx and collectd configs.
If they match, the containers are not recreated and nothing is to be done.
nginx, collectd configs are part of data already and containers are running.
If they do not match, it deletes all containers (including app containers) and starts
them all afresh. Important thing here is that, DATA_DIR is never removed across
+4 -13
View File
@@ -7,15 +7,10 @@ set -eu -o pipefail
readonly container_files="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/container"
readonly CONFIG_DIR="/home/yellowtent/configs"
readonly DATA_DIR="/home/yellowtent/data"
########## create config directory
rm -rf "${CONFIG_DIR}"
mkdir -p "${CONFIG_DIR}/addons"
mkdir -p "${CONFIG_DIR}/nginx/applications"
mkdir -p "${CONFIG_DIR}/nginx/cert"
mkdir -p "${CONFIG_DIR}/collectd/collectd.conf.d"
mkdir -p "${CONFIG_DIR}/nginx/applications"
mkdir -p "${CONFIG_DIR}/nginx/cert"
rm -rf "${CONFIG_DIR}" && mkdir "${CONFIG_DIR}"
########## logrotate (default ubuntu runs this daily)
rm -rf /etc/logrotate.d/*
@@ -31,16 +26,12 @@ cp "${container_files}/sudoers" /etc/sudoers.d/yellowtent
########## collectd
rm -rf /etc/collectd
ln -sfF "${CONFIG_DIR}/collectd" /etc/collectd
cp "${container_files}/collectd.conf" "${CONFIG_DIR}/collectd/collectd.conf"
ln -sfF "${DATA_DIR}/collectd" /etc/collectd
########## nginx
cp "${container_files}/nginx/nginx.conf" "${CONFIG_DIR}/nginx/nginx.conf"
cp "${container_files}/nginx/mime.types" "${CONFIG_DIR}/nginx/mime.types"
# link nginx config to system config
unlink /etc/nginx 2>/dev/null || rm -rf /etc/nginx
ln -s "${CONFIG_DIR}/nginx" /etc/nginx
ln -s "${DATA_DIR}/nginx" /etc/nginx
########## Restart services (this is only needed since we are not a real container)
update-rc.d -f collectd defaults
+15 -6
View File
@@ -72,15 +72,24 @@ cd "${box_src_tmp_dir}"
NODE_ENV=cloudron DATABASE_URL=mysql://root:password@localhost/box "${box_src_tmp_dir}/node_modules/.bin/db-migrate" up
EOF
set_progress "28" "Setup collectd"
mkdir -p "${DATA_DIR}/collectd/collectd.conf.d"
cp "${script_dir}/start/collectd.conf" "${DATA_DIR}/collectd/collectd.conf"
set_progress "30" "Setup nginx"
# setup naked domain to use admin by default. app restoration will overwrite this config
${box_src_tmp_dir}/node_modules/.bin/ejs-cli -f "${script_dir}/start/nginx/appconfig.ejs" \
-O "{ \"vhost\": \"${arg_fqdn}\", \"isAdmin\": true, \"sourceDir\": \"${BOX_SRC_DIR}\" }" > "${CONFIG_DIR}/nginx/naked_domain.conf"
${box_src_tmp_dir}/node_modules/.bin/ejs-cli -f "${script_dir}/start/nginx/appconfig.ejs" \
-O "{ \"vhost\": \"${admin_fqdn}\", \"isAdmin\": true, \"sourceDir\": \"${BOX_SRC_DIR}\" }" > "${CONFIG_DIR}/nginx/applications/admin.conf"
mkdir -p "${DATA_DIR}/nginx/applications"
cp "${script_dir}/start/nginx/nginx.conf" "${DATA_DIR}/nginx/nginx.conf"
cp "${script_dir}/start/nginx/mime.types" "${DATA_DIR}/nginx/mime.types"
echo "${arg_tls_cert}" > ${CONFIG_DIR}/nginx/cert/host.cert
echo "${arg_tls_key}" > ${CONFIG_DIR}/nginx/cert/host.key
${box_src_tmp_dir}/node_modules/.bin/ejs-cli -f "${script_dir}/start/nginx/appconfig.ejs" \
-O "{ \"vhost\": \"${arg_fqdn}\", \"isAdmin\": true, \"sourceDir\": \"${BOX_SRC_DIR}\" }" > "${DATA_DIR}/nginx/naked_domain.conf"
${box_src_tmp_dir}/node_modules/.bin/ejs-cli -f "${script_dir}/start/nginx/appconfig.ejs" \
-O "{ \"vhost\": \"${admin_fqdn}\", \"isAdmin\": true, \"sourceDir\": \"${BOX_SRC_DIR}\" }" > "${DATA_DIR}/nginx/applications/admin.conf"
mkdir -p "${DATA_DIR}/nginx/cert"
echo "${arg_tls_cert}" > ${DATA_DIR}/nginx/cert/host.cert
echo "${arg_tls_key}" > ${DATA_DIR}/nginx/cert/host.key
set_progress "33" "Changing ownership of source, data, configs"
chown "${USER}:${USER}" -R "${BOX_SRC_DIR}" "${DATA_DIR}" "${CONFIG_DIR}"
+8 -7
View File
@@ -3,13 +3,14 @@
set -eu -o pipefail
readonly DATA_DIR="/home/yellowtent/data"
readonly CONFIG_DIR="/home/yellowtent/configs"
arg_fqdn="$1"
mysql_root_password="$2"
postgresql_root_password="$3"
mongodb_root_password="$4"
mkdir -p "${DATA_DIR}/addons"
# removing containers ensures containers are launched with latest config updates
# restore code in appatask does not delete old containers
existing_containers=$(docker ps -qa)
@@ -36,7 +37,7 @@ echo "Mail container id: ${mail_container_id}"
# mysql
docker0_ip=$(/sbin/ifconfig docker0 | grep "inet addr" | awk -F: '{print $2}' | awk '{print $1}')
cat > "${CONFIG_DIR}/addons/mysql_vars.sh" <<EOF
cat > "${DATA_DIR}/addons/mysql_vars.sh" <<EOF
readonly MYSQL_ROOT_PASSWORD='${mysql_root_password}'
readonly MYSQL_ROOT_HOST='${docker0_ip}'
EOF
@@ -44,30 +45,30 @@ rm -rf "${DATA_DIR}/mysql"
mysql_container_id=$(docker run --restart=always -d --name="mysql" \
-h "${arg_fqdn}" \
-v "${DATA_DIR}/mysql:/var/lib/mysql" \
-v "${CONFIG_DIR}/addons/mysql_vars.sh:/etc/mysql/mysql_vars.sh:r" \
-v "${DATA_DIR}/addons/mysql_vars.sh:/etc/mysql/mysql_vars.sh:r" \
girish/mysql:0.1.0)
echo "MySQL container id: ${mysql_container_id}"
# postgresql
cat > "${CONFIG_DIR}/addons/postgresql_vars.sh" <<EOF
cat > "${DATA_DIR}/addons/postgresql_vars.sh" <<EOF
readonly POSTGRESQL_ROOT_PASSWORD='${postgresql_root_password}'
EOF
rm -rf "${DATA_DIR}/postgresql"
postgresql_container_id=$(docker run --restart=always -d --name="postgresql" \
-h "${arg_fqdn}" \
-v "${DATA_DIR}/postgresql:/var/lib/postgresql" \
-v "${CONFIG_DIR}/addons/postgresql_vars.sh:/etc/postgresql/postgresql_vars.sh:r" \
-v "${DATA_DIR}/addons/postgresql_vars.sh:/etc/postgresql/postgresql_vars.sh:r" \
girish/postgresql:0.1.0)
echo "PostgreSQL container id: ${postgresql_container_id}"
cat > "${CONFIG_DIR}/addons/mongodb_vars.sh" <<EOF
cat > "${DATA_DIR}/addons/mongodb_vars.sh" <<EOF
readonly MONGODB_ROOT_PASSWORD='${mongodb_root_password}'
EOF
rm -rf "${DATA_DIR}/mongodb"
mongodb_container_id=$(docker run --restart=always -d --name="mongodb" \
-h "${arg_fqdn}" \
-v "${DATA_DIR}/mongodb:/var/lib/mongodb" \
-v "${CONFIG_DIR}/addons/mongodb_vars.sh:/etc/mongodb_vars.sh:r" \
-v "${DATA_DIR}/addons/mongodb_vars.sh:/etc/mongodb_vars.sh:r" \
girish/mongodb:0.1.0)
echo "Mongodb container id: ${mongodb_container_id}"
+5 -5
View File
@@ -7,13 +7,13 @@ var config = require('../config.js'),
// keep these values in sync with start.sh
exports = module.exports = {
NGINX_CONFIG_DIR: path.join(config.baseDir(), 'configs/nginx'),
NGINX_APPCONFIG_DIR: path.join(config.baseDir(), 'configs/nginx/applications'),
NGINX_CERT_DIR: path.join(config.baseDir(), 'configs/nginx/cert'),
NGINX_CONFIG_DIR: path.join(config.baseDir(), 'data/nginx'),
NGINX_APPCONFIG_DIR: path.join(config.baseDir(), 'data/nginx/applications'),
NGINX_CERT_DIR: path.join(config.baseDir(), 'data/nginx/cert'),
ADDON_CONFIG_DIR: path.join(config.baseDir(), 'configs/addons'),
ADDON_CONFIG_DIR: path.join(config.baseDir(), 'data/addons'),
COLLECTD_APPCONFIG_DIR: path.join(config.baseDir(), 'configs/collectd/collectd.conf.d'),
COLLECTD_APPCONFIG_DIR: path.join(config.baseDir(), 'data/collectd/collectd.conf.d'),
DATA_DIR: path.join(config.baseDir(), 'data'),
BOX_DATA_DIR: path.join(config.baseDir(), 'data/box'),