From d5d2bb508a8bc11fe3bfa199b43b45c4fc0e087c Mon Sep 17 00:00:00 2001 From: Kristijan Mitrovic Date: Wed, 29 Jul 2020 23:21:16 +0000 Subject: [PATCH 1/3] Log flag and logs refactoring (#33) Use get_... and set_plaintext for log flag in redis Use links to /dev/null when logs are turned off Merge branch 'master' into kris/log_flag # Conflicts: # bubble-server/src/main/resources/packer/roles/nginx/files/init_dhparams.sh Add missing GET annotation on log flag status API call Remove encryption of log flag in redis Simplify geter and setter of log flag Fix log manager's tests and text replacements Fix log manager script Fix log manager script Move log manager cron to root user Move one more log into correct bubble folder Reload supervisor after changes in logs setup Remove another host prefix Add new subresource class for logs Create bubble user, bubble-log group and log folder earlier Set log flag initial value Fix not implemented error Add root user to the new group Fix user for newly created cron Move all log output to /var/log/bubble/ Merge branch 'master' into kris/log_flag Create a cron for log_manager in packer's ansible Add script for setting up logs as per log flag Add API calls to read and set log flag Remove not used file Use same log files' naming for tmp folder's logs Co-authored-by: Kristijan Mitrovic Reviewed-on: https://git.bubblev.org/bubblev/bubble/pulls/33 --- .gitignore | 1 - .../src/main/java/bubble/ApiConstants.java | 1 + .../bubble/resources/cloud/LogsResource.java | 49 +++++++++++++++++++ .../resources/cloud/NetworksResource.java | 8 +-- .../bubble/resources/cloud/NodesResource.java | 8 +++ .../bubble/service/boot/SelfNodeService.java | 3 ++ .../service/boot/StandardSelfNodeService.java | 25 ++++++++++ .../DbFilterSelfNodeService.java | 3 ++ .../resources/ansible/install_local.sh.hbs | 6 +-- .../ansible/roles/algo/tasks/main.yml | 2 +- .../bubble/templates/snapshot_ansible.sh.j2 | 34 ------------- .../ansible/roles/common/tasks/main.yml | 8 +++ .../templates/supervisor_bubble.conf.j2 | 4 +- .../main/resources/bubble/host-prefixes.txt | 1 - .../roles/algo/files/algo_refresh_users.sh | 2 +- .../algo/files/algo_refresh_users_monitor.sh | 2 +- .../algo/files/wg_monitor_connections.sh | 2 +- .../bubble/files/bubble_restore_monitor.sh | 4 +- .../roles/bubble/files/bubble_upgrade.sh | 2 +- .../bubble/files/bubble_upgrade_monitor.sh | 2 +- .../roles/bubble/files/init_bubble_db.sh | 2 +- .../packer/roles/bubble/files/log_manager.sh | 26 ++++++++++ .../bubble/files/refresh_bubble_ssh_keys.sh | 2 +- .../files/refresh_bubble_ssh_keys_monitor.sh | 2 +- .../packer/roles/bubble/tasks/main.yml | 24 +++------ .../roles/common/files/ensure_file_exists.sh | 2 +- .../packer/roles/common/tasks/main.yml | 27 ++++++++++ .../roles/finalizer/files/snapshot_ansible.sh | 2 +- .../files/supervisor_bubble_nodemanager.conf | 4 +- .../files/supervisor_bubble_peer_manager.conf | 4 +- .../roles/mitmproxy/files/mitm_monitor.sh | 2 +- .../packer/roles/mitmproxy/tasks/main.yml | 1 + .../packer/roles/nginx/files/init_certbot.sh | 2 +- .../packer/roles/nginx/files/init_dhparams.sh | 2 +- 34 files changed, 189 insertions(+), 80 deletions(-) create mode 100644 bubble-server/src/main/java/bubble/resources/cloud/LogsResource.java delete mode 100644 bubble-server/src/main/resources/ansible/roles/bubble/templates/snapshot_ansible.sh.j2 create mode 100755 bubble-server/src/main/resources/packer/roles/bubble/files/log_manager.sh diff --git a/.gitignore b/.gitignore index 943c9df2..66e4033a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,6 @@ *.iml .idea tmp -logs dependency-reduced-pom.xml *.log *~ diff --git a/bubble-server/src/main/java/bubble/ApiConstants.java b/bubble-server/src/main/java/bubble/ApiConstants.java index c9e2ded1..0e5b436b 100644 --- a/bubble-server/src/main/java/bubble/ApiConstants.java +++ b/bubble-server/src/main/java/bubble/ApiConstants.java @@ -201,6 +201,7 @@ public class ApiConstants { public static final String EP_FORK = "/fork"; public static final String EP_NODE_MANAGER = "/nodeman"; public static final String EP_UPGRADE = "/upgrade"; + public static final String EP_LOGS = "/logs"; public static final String DETECT_ENDPOINT = "/detect"; public static final String EP_LOCALE = "/locale"; diff --git a/bubble-server/src/main/java/bubble/resources/cloud/LogsResource.java b/bubble-server/src/main/java/bubble/resources/cloud/LogsResource.java new file mode 100644 index 00000000..2ea1623f --- /dev/null +++ b/bubble-server/src/main/java/bubble/resources/cloud/LogsResource.java @@ -0,0 +1,49 @@ +/** + * Copyright (c) 2020 Bubble, Inc. All rights reserved. + * For personal (non-commercial) use, see license: https://getbubblenow.com/bubble-license/ + */ +package bubble.resources.cloud; + +import bubble.model.account.Account; +import bubble.service.boot.SelfNodeService; +import lombok.NonNull; +import org.glassfish.jersey.server.ContainerRequest; +import org.springframework.beans.factory.annotation.Autowired; + +import javax.ws.rs.*; +import javax.ws.rs.core.Context; +import javax.ws.rs.core.Response; + +import static bubble.ApiConstants.*; +import static org.cobbzilla.util.http.HttpContentTypes.APPLICATION_JSON; +import static org.cobbzilla.wizard.resources.ResourceUtil.forbiddenEx; +import static org.cobbzilla.wizard.resources.ResourceUtil.ok; + +@Consumes(APPLICATION_JSON) +@Produces(APPLICATION_JSON) +public class LogsResource { + + @Autowired private SelfNodeService selfNodeService; + + private Account account; + + public LogsResource(@NonNull final Account account) { + this.account = account; + } + + @GET @Path(EP_STATUS) + @NonNull public Response getLoggingStatus(@NonNull @Context final ContainerRequest ctx) { + return ok(selfNodeService.getLogFlag()); + } + + @POST @Path(EP_START) + @NonNull public Response startLogging(@NonNull @Context final ContainerRequest ctx) { return setLogFlag(true); } + @POST @Path(EP_STOP) + @NonNull public Response stopLogging(@NonNull @Context final ContainerRequest ctx) { return setLogFlag(false); } + + @NonNull private Response setLogFlag(final boolean b) { + if (!account.admin()) throw forbiddenEx(); // caller must be admin + selfNodeService.setLogFlag(b); + return ok(); + } +} diff --git a/bubble-server/src/main/java/bubble/resources/cloud/NetworksResource.java b/bubble-server/src/main/java/bubble/resources/cloud/NetworksResource.java index 07d729ef..40896d28 100644 --- a/bubble-server/src/main/java/bubble/resources/cloud/NetworksResource.java +++ b/bubble-server/src/main/java/bubble/resources/cloud/NetworksResource.java @@ -18,16 +18,15 @@ import bubble.model.cloud.BubbleNetwork; import bubble.model.cloud.CloudService; import bubble.resources.TagsResource; import bubble.resources.account.AccountOwnedResource; +import bubble.service.boot.SelfNodeService; import bubble.service.cloud.GeoService; +import lombok.NonNull; import lombok.extern.slf4j.Slf4j; import org.glassfish.grizzly.http.server.Request; import org.glassfish.jersey.server.ContainerRequest; import org.springframework.beans.factory.annotation.Autowired; -import javax.ws.rs.GET; -import javax.ws.rs.Path; -import javax.ws.rs.PathParam; -import javax.ws.rs.QueryParam; +import javax.ws.rs.*; import javax.ws.rs.core.Context; import javax.ws.rs.core.MultivaluedMap; import javax.ws.rs.core.Response; @@ -47,6 +46,7 @@ public class NetworksResource extends AccountOwnedResource sageNode = new AtomicReference<>(); private static final AtomicBoolean wasRestored = new AtomicBoolean(false); + @Autowired private RedisService redisService; + @Getter(lazy=true) private final RedisService nodeConfig = redisService.prefixNamespace(getClass().getSimpleName()); + @Override public boolean initThisNode(BubbleNode thisNode) { log.info("initThisNode: initializing with thisNode="+thisNode.id()); final BubbleConfiguration c = configuration; @@ -432,4 +441,20 @@ public class StandardSelfNodeService implements SelfNodeService { return planDAO.findByUuid(accountPlan.getPlan()); } + @Override + public Boolean getLogFlag() { + if (!getNodeConfig().exists(REDIS_LOG_FLAG_KEY)) return false; + return Boolean.valueOf(getNodeConfig().get_plaintext(REDIS_LOG_FLAG_KEY)); + } + + @Override + public void setLogFlag(final boolean logFlag) { + if (logFlag) { + getNodeConfig().set_plaintext(REDIS_LOG_FLAG_KEY, "true", EX, + isSelfSage() ? TTL_LOG_FLAG_SAGE : TTL_LOG_FLAG_NODE); + } else { + // just (try to) remove the flag + getNodeConfig().del(REDIS_LOG_FLAG_KEY); + } + } } diff --git a/bubble-server/src/main/java/bubble/service_dbfilter/DbFilterSelfNodeService.java b/bubble-server/src/main/java/bubble/service_dbfilter/DbFilterSelfNodeService.java index 61f9bf3b..22b5b25f 100644 --- a/bubble-server/src/main/java/bubble/service_dbfilter/DbFilterSelfNodeService.java +++ b/bubble-server/src/main/java/bubble/service_dbfilter/DbFilterSelfNodeService.java @@ -29,4 +29,7 @@ public class DbFilterSelfNodeService implements SelfNodeService { @Override public BubblePlan getThisPlan() { return notSupported("getThisPlan"); } + @Override public Boolean getLogFlag() { return notSupported("getLogFlag"); } + @Override public void setLogFlag(boolean logFlag) { notSupported("setLogFlag"); } + } diff --git a/bubble-server/src/main/resources/ansible/install_local.sh.hbs b/bubble-server/src/main/resources/ansible/install_local.sh.hbs index e1586a60..e5d81e09 100644 --- a/bubble-server/src/main/resources/ansible/install_local.sh.hbs +++ b/bubble-server/src/main/resources/ansible/install_local.sh.hbs @@ -2,7 +2,7 @@ ANSIBLE_USER="{{node.user}}" ANSIBLE_HOME="$(cd ~{{node.user}} && pwd)" -LOG="${ANSIBLE_HOME}/.ansible.log" +LOG=/var/log/bubble/ansible.log # Stop unattended upgrades so that apt installs will work # unattended upgrades are re-enabled at the end of the ansible run @@ -17,7 +17,7 @@ set -m {{#if isNode}} # touch algo log and start tailing it -ALGO_LOG=/tmp/install_algo.log +ALGO_LOG=/var/log/bubble/install_algo.log touch ${ALGO_LOG} && tail -f ${ALGO_LOG} & {{/if}} @@ -80,7 +80,7 @@ fi {{#if isNode}} # touch algo log and start tailing it set -m -touch /tmp/install_algo.log && tail -f /tmp/install_algo.log & +touch ${ALGO_LOG} && tail -f ${ALGO_LOG} & {{/if}} set -o pipefail diff --git a/bubble-server/src/main/resources/ansible/roles/algo/tasks/main.yml b/bubble-server/src/main/resources/ansible/roles/algo/tasks/main.yml index 6f51ac9c..103069b5 100644 --- a/bubble-server/src/main/resources/ansible/roles/algo/tasks/main.yml +++ b/bubble-server/src/main/resources/ansible/roles/algo/tasks/main.yml @@ -14,7 +14,7 @@ # Don't setup algo when in restore mode, bubble_restore_monitor.sh will set it up after the CA key has been restored - name: Run algo playbook to install algo - shell: bash -c "/root/ansible/roles/algo/algo/install_algo.sh 2>&1 >> /tmp/install_algo.log" + shell: bash -c "/root/ansible/roles/algo/algo/install_algo.sh 2>&1 >> /var/log/bubble/install_algo.log" tags: algo_related # Algo installation clears out iptable rules. Add needed bubble rules back: diff --git a/bubble-server/src/main/resources/ansible/roles/bubble/templates/snapshot_ansible.sh.j2 b/bubble-server/src/main/resources/ansible/roles/bubble/templates/snapshot_ansible.sh.j2 deleted file mode 100644 index 635fcb9c..00000000 --- a/bubble-server/src/main/resources/ansible/roles/bubble/templates/snapshot_ansible.sh.j2 +++ /dev/null @@ -1,34 +0,0 @@ -#!/bin/bash - -SCRIPT="${0}" -SCRIPT_DIR=$(cd $(dirname ${SCRIPT}) && pwd) - -LOG=/tmp/$(basename ${0}).log - -function die { - echo 1>&2 "${1}" - log "${1}" - exit 1 -} - -function log { - echo "${1}" | tee -a ${LOG} -} - -if [[ $(whoami) != "{{ admin_user }}" ]] ; then - if [[ $(whoami) == "root" ]] ; then - sudo -H -u "{{ admin_user }}" ${0} - exit $? - fi - die "${0} must be run as {{ admin_user }}" -fi - -ANSIBLE_USER_HOME=$(cd ~{{ admin_user }} && pwd) - -ANSIBLE_SNAPSHOT="/home/bubble/ansible.tgz" - -cd ${ANSIBLE_USER_HOME} \ - && tar czf ${ANSIBLE_SNAPSHOT} ./ansible \ - && chmod 400 ${ANSIBLE_SNAPSHOT} \ - && chown bubble ${ANSIBLE_SNAPSHOT} \ - || die "Error creating ansible snapshot" diff --git a/bubble-server/src/main/resources/ansible/roles/common/tasks/main.yml b/bubble-server/src/main/resources/ansible/roles/common/tasks/main.yml index 2e29cb67..e5613d37 100644 --- a/bubble-server/src/main/resources/ansible/roles/common/tasks/main.yml +++ b/bubble-server/src/main/resources/ansible/roles/common/tasks/main.yml @@ -4,3 +4,11 @@ - name: Set hostname to {{ hostname }} hostname: name: '{{ hostname }}' + +- name: Set log flag to true with EX of 7 days for non-sage nodes + shell: echo 'set bubble.StandardSelfNodeService.bubble_server_logs_enabled "true" EX 604800' | redis-cli + when: install_type != 'sage' + +- name: Set log flag to true with EX of 30 days for sage nodes + shell: echo 'set bubble.StandardSelfNodeService.bubble_server_logs_enabled "true" EX 2592000' | redis-cli + when: install_type == 'sage' diff --git a/bubble-server/src/main/resources/ansible/roles/finalizer/templates/supervisor_bubble.conf.j2 b/bubble-server/src/main/resources/ansible/roles/finalizer/templates/supervisor_bubble.conf.j2 index 6b215aec..8e20c555 100644 --- a/bubble-server/src/main/resources/ansible/roles/finalizer/templates/supervisor_bubble.conf.j2 +++ b/bubble-server/src/main/resources/ansible/roles/finalizer/templates/supervisor_bubble.conf.j2 @@ -1,7 +1,7 @@ [program:bubble] -stdout_logfile = /home/bubble/logs/bubble-out.log -stderr_logfile = /home/bubble/logs/bubble-err.log +stdout_logfile = /var/log/bubble/api-server-out.log +stderr_logfile = /var/log/bubble/api-server-err.log command=sudo -u bubble bash -c "/usr/bin/java \ -Dfile.encoding=UTF-8 -Djava.net.preferIPv4Stack=true \ -XX:+UseG1GC -XX:MaxGCPauseMillis=400 {{ bubble_java_opts }} \ diff --git a/bubble-server/src/main/resources/bubble/host-prefixes.txt b/bubble-server/src/main/resources/bubble/host-prefixes.txt index 375196cd..d16560cf 100644 --- a/bubble-server/src/main/resources/bubble/host-prefixes.txt +++ b/bubble-server/src/main/resources/bubble/host-prefixes.txt @@ -964,7 +964,6 @@ beset besit besom besot -besti bests betas beted diff --git a/bubble-server/src/main/resources/packer/roles/algo/files/algo_refresh_users.sh b/bubble-server/src/main/resources/packer/roles/algo/files/algo_refresh_users.sh index eca53638..790f21a4 100644 --- a/bubble-server/src/main/resources/packer/roles/algo/files/algo_refresh_users.sh +++ b/bubble-server/src/main/resources/packer/roles/algo/files/algo_refresh_users.sh @@ -2,7 +2,7 @@ # # Copyright (c) 2020 Bubble, Inc. All rights reserved. For personal (non-commercial) use, see license: https://getbubblenow.com/bubble-license/ # -LOG=/tmp/bubble.algo_refresh_users.log +LOG=/var/log/bubble/algo_refresh_users.log ALGO_BASE=/root/ansible/roles/algo/algo REFRESH_MARKER=${ALGO_BASE}/.refreshing_users diff --git a/bubble-server/src/main/resources/packer/roles/algo/files/algo_refresh_users_monitor.sh b/bubble-server/src/main/resources/packer/roles/algo/files/algo_refresh_users_monitor.sh index eb006d61..532ba739 100644 --- a/bubble-server/src/main/resources/packer/roles/algo/files/algo_refresh_users_monitor.sh +++ b/bubble-server/src/main/resources/packer/roles/algo/files/algo_refresh_users_monitor.sh @@ -2,7 +2,7 @@ # # Copyright (c) 2020 Bubble, Inc. All rights reserved. For personal (non-commercial) use, see license: https://getbubblenow.com/bubble-license/ # -LOG=/tmp/bubble.algo_refresh_users_monitor.log +LOG=/var/log/bubble/algo_refresh_users_monitor.log function die { echo 1>&2 "${1}" diff --git a/bubble-server/src/main/resources/packer/roles/algo/files/wg_monitor_connections.sh b/bubble-server/src/main/resources/packer/roles/algo/files/wg_monitor_connections.sh index e9ea815c..5a29b1bf 100644 --- a/bubble-server/src/main/resources/packer/roles/algo/files/wg_monitor_connections.sh +++ b/bubble-server/src/main/resources/packer/roles/algo/files/wg_monitor_connections.sh @@ -2,7 +2,7 @@ # # Copyright (c) 2020 Bubble, Inc. All rights reserved. For personal (non-commercial) use, see license: https://getbubblenow.com/bubble-license/ # -LOG=/tmp/bubble.wg_monitor_connections.log +LOG=/var/log/bubble/wg_monitor_connections.log function die { echo 1>&2 "${1}" diff --git a/bubble-server/src/main/resources/packer/roles/bubble/files/bubble_restore_monitor.sh b/bubble-server/src/main/resources/packer/roles/bubble/files/bubble_restore_monitor.sh index 7eead8d0..57973b1d 100755 --- a/bubble-server/src/main/resources/packer/roles/bubble/files/bubble_restore_monitor.sh +++ b/bubble-server/src/main/resources/packer/roles/bubble/files/bubble_restore_monitor.sh @@ -12,7 +12,7 @@ BUBBLE_SELF_NODE="${BUBBLE_HOME}/${SELF_NODE}" ADMIN_PORT=${1:?no admin port provided} TIMEOUT=${2:-3600} # 60 minutes default timeout -LOG=/tmp/bubble.restore.log +LOG=/var/log/bubble/restore.log function die { echo 1>&2 "${1}" @@ -111,6 +111,8 @@ fi # flush redis log "Flushing redis" echo "FLUSHALL" | redis-cli || die "Error flushing redis" +# but reset the log flag to true (EX in 7 days) - do this here so logs from following lines will be logged +echo 'set bubble.StandardSelfNodeService.bubble_server_logs_enabled "true" EX 604800' | redis-cli # restore algo configs log "Restoring algo configs" diff --git a/bubble-server/src/main/resources/packer/roles/bubble/files/bubble_upgrade.sh b/bubble-server/src/main/resources/packer/roles/bubble/files/bubble_upgrade.sh index 8a9c0893..f79ebcd7 100644 --- a/bubble-server/src/main/resources/packer/roles/bubble/files/bubble_upgrade.sh +++ b/bubble-server/src/main/resources/packer/roles/bubble/files/bubble_upgrade.sh @@ -5,7 +5,7 @@ BUBBLE_HOME="/home/bubble" UPGRADE_JAR="${BUBBLE_HOME}/upgrade.jar" BUBBLE_JAR="${BUBBLE_HOME}/api/bubble.jar" -LOG=/tmp/bubble.upgrade.log +LOG=/var/log/bubble/upgrade.log function die { echo 1>&2 "${1}" diff --git a/bubble-server/src/main/resources/packer/roles/bubble/files/bubble_upgrade_monitor.sh b/bubble-server/src/main/resources/packer/roles/bubble/files/bubble_upgrade_monitor.sh index 75522efd..1c4ae801 100644 --- a/bubble-server/src/main/resources/packer/roles/bubble/files/bubble_upgrade_monitor.sh +++ b/bubble-server/src/main/resources/packer/roles/bubble/files/bubble_upgrade_monitor.sh @@ -6,7 +6,7 @@ THIS_DIR="$(cd "$(dirname "${0}")" && pwd)" BUBBLE_HOME="/home/bubble" UPGRADE_JAR="${BUBBLE_HOME}/upgrade.jar" -LOG=/tmp/bubble.upgrade.log +LOG=/var/log/bubble/upgrade.log function log { echo "$(date): ${1}" >> ${LOG} diff --git a/bubble-server/src/main/resources/packer/roles/bubble/files/init_bubble_db.sh b/bubble-server/src/main/resources/packer/roles/bubble/files/init_bubble_db.sh index 45955903..a70251ad 100644 --- a/bubble-server/src/main/resources/packer/roles/bubble/files/init_bubble_db.sh +++ b/bubble-server/src/main/resources/packer/roles/bubble/files/init_bubble_db.sh @@ -4,7 +4,7 @@ # echo "$@" > /tmp/init.args -LOG=/dev/null +LOG=/var/log/bubble/init_db.log function die { echo 1>&2 "${1}" diff --git a/bubble-server/src/main/resources/packer/roles/bubble/files/log_manager.sh b/bubble-server/src/main/resources/packer/roles/bubble/files/log_manager.sh new file mode 100755 index 00000000..a7926231 --- /dev/null +++ b/bubble-server/src/main/resources/packer/roles/bubble/files/log_manager.sh @@ -0,0 +1,26 @@ +#!/bin/bash +# +# Copyright (c) 2020 Bubble, Inc. All rights reserved. For personal (non-commercial) use, see license: +# https://getbubblenow.com/bubble-license/ +# + +BUBBLE_LOGS_FOLDER=/var/log/bubble +REDIS_LOG_FLAG_KEY="bubble.StandardSelfNodeService.bubble_server_logs_enabled" + +REDIS_LOG_FLAG_VALUE=$(echo "get ${REDIS_LOG_FLAG_KEY}" | redis-cli | xargs echo | tr '[:upper:]' '[:lower:]') + +if [[ ${REDIS_LOG_FLAG_VALUE} == true ]]; then + is_reload_needed=false + for logFile in $(find "${BUBBLE_LOGS_FOLDER}"/* -type l); do + rm "${logFile}" + touch "${logFile}" + is_reload_needed=true + done + if [[ ${is_reload_needed} == true ]]; then + supervisorctl reload + fi +else + for logFile in $(find "${BUBBLE_LOGS_FOLDER}"/* -type f); do + ln -sf /dev/null "${logFile}" + done +fi diff --git a/bubble-server/src/main/resources/packer/roles/bubble/files/refresh_bubble_ssh_keys.sh b/bubble-server/src/main/resources/packer/roles/bubble/files/refresh_bubble_ssh_keys.sh index 63e3247c..007789b1 100644 --- a/bubble-server/src/main/resources/packer/roles/bubble/files/refresh_bubble_ssh_keys.sh +++ b/bubble-server/src/main/resources/packer/roles/bubble/files/refresh_bubble_ssh_keys.sh @@ -2,7 +2,7 @@ # # Copyright (c) 2020 Bubble, Inc. All rights reserved. For personal (non-commercial) use, see license: https://getbubblenow.com/bubble-license/ # -LOG=/tmp/bubble.refresh_bubble_ssh_keys.log +LOG=/var/log/bubble/refresh_bubble_ssh_keys.log function die { echo 1>&2 "${1}" diff --git a/bubble-server/src/main/resources/packer/roles/bubble/files/refresh_bubble_ssh_keys_monitor.sh b/bubble-server/src/main/resources/packer/roles/bubble/files/refresh_bubble_ssh_keys_monitor.sh index 7ee94aa0..2f91f5ea 100644 --- a/bubble-server/src/main/resources/packer/roles/bubble/files/refresh_bubble_ssh_keys_monitor.sh +++ b/bubble-server/src/main/resources/packer/roles/bubble/files/refresh_bubble_ssh_keys_monitor.sh @@ -2,7 +2,7 @@ # # Copyright (c) 2020 Bubble, Inc. All rights reserved. For personal (non-commercial) use, see license: https://getbubblenow.com/bubble-license/ # -LOG=/tmp/bubble.ssh_keys_monitor.log +LOG=/var/log/bubble/ssh_keys_monitor.log function die { echo 1>&2 "${1}" diff --git a/bubble-server/src/main/resources/packer/roles/bubble/tasks/main.yml b/bubble-server/src/main/resources/packer/roles/bubble/tasks/main.yml index 2fe830d1..2025e6f5 100644 --- a/bubble-server/src/main/resources/packer/roles/bubble/tasks/main.yml +++ b/bubble-server/src/main/resources/packer/roles/bubble/tasks/main.yml @@ -9,14 +9,6 @@ - import_tasks: postgresql.yml -- name: Create bubble user - user: - name: bubble - comment: bubble user - shell: /bin/bash - system: yes - home: /home/bubble - - name: Creates bubble API dir file: path: /home/bubble/api @@ -25,14 +17,6 @@ mode: 0555 state: directory -- name: Creates bubble logs dir - file: - path: /home/bubble/logs - owner: bubble - group: root - mode: 0770 - state: directory - - name: Install bubble jar copy: src: bubble.jar @@ -113,6 +97,7 @@ - refresh_bubble_ssh_keys.sh - bubble_upgrade_monitor.sh - bubble_upgrade.sh + - log_manager.sh - name: Install refresh_bubble_ssh_keys_monitor supervisor conf file copy: @@ -124,6 +109,13 @@ src: supervisor_bubble_upgrade_monitor.conf dest: /etc/supervisor/conf.d/bubble_upgrade_monitor.conf +- name: Install log_namager monitor cron + cron: + name: "Log flag check and manager" + minute: "*/5" + user: "root" + job: "log_manager.sh" + - name: Install packer for sage node shell: su - bubble bash -c install_packer.sh when: install_type == 'sage' diff --git a/bubble-server/src/main/resources/packer/roles/common/files/ensure_file_exists.sh b/bubble-server/src/main/resources/packer/roles/common/files/ensure_file_exists.sh index e6cdec82..e65f5ee3 100644 --- a/bubble-server/src/main/resources/packer/roles/common/files/ensure_file_exists.sh +++ b/bubble-server/src/main/resources/packer/roles/common/files/ensure_file_exists.sh @@ -4,7 +4,7 @@ # TARGET_FILE=${1:?no target file provided} TIMEOUT=${2:?no timeout provided} -LOG=/tmp/ensure_file_$(echo ${TARGET_FILE} | tr '/' '_').log +LOG=/var/log/bubble/ensure_file_$(echo ${TARGET_FILE} | tr '/' '_').log start=$(date +%s) while [[ ! -s ${TARGET_FILE} && $(expr $(date +%s) - ${start}) -le ${TIMEOUT} ]] ; do diff --git a/bubble-server/src/main/resources/packer/roles/common/tasks/main.yml b/bubble-server/src/main/resources/packer/roles/common/tasks/main.yml index 373b1ba0..b2e4086d 100644 --- a/bubble-server/src/main/resources/packer/roles/common/tasks/main.yml +++ b/bubble-server/src/main/resources/packer/roles/common/tasks/main.yml @@ -57,3 +57,30 @@ state: restarted with_items: - fail2ban + +- name: Create bubble-log group + group: + name: bubble-log + +- name: Add root user to newly created group + user: + name: root + groups: bubble-log + append: yes + +- name: Create bubble user + user: + name: bubble + comment: bubble user + shell: /bin/bash + system: yes + home: /home/bubble + groups: bubble-log + +- name: Creates bubble logs dir + file: + path: /var/log/bubble + owner: bubble + group: bubble-log + mode: 0770 + state: directory diff --git a/bubble-server/src/main/resources/packer/roles/finalizer/files/snapshot_ansible.sh b/bubble-server/src/main/resources/packer/roles/finalizer/files/snapshot_ansible.sh index 8a663edd..cad0965b 100644 --- a/bubble-server/src/main/resources/packer/roles/finalizer/files/snapshot_ansible.sh +++ b/bubble-server/src/main/resources/packer/roles/finalizer/files/snapshot_ansible.sh @@ -5,7 +5,7 @@ SCRIPT="${0}" SCRIPT_DIR=$(cd $(dirname ${SCRIPT}) && pwd) -LOG=/tmp/$(basename ${0}).log +LOG=/var/log/bubble/snapshot_ansible.log function die { echo 1>&2 "${1}" diff --git a/bubble-server/src/main/resources/packer/roles/finalizer/files/supervisor_bubble_nodemanager.conf b/bubble-server/src/main/resources/packer/roles/finalizer/files/supervisor_bubble_nodemanager.conf index 2605be5f..a42b625a 100644 --- a/bubble-server/src/main/resources/packer/roles/finalizer/files/supervisor_bubble_nodemanager.conf +++ b/bubble-server/src/main/resources/packer/roles/finalizer/files/supervisor_bubble_nodemanager.conf @@ -1,5 +1,5 @@ [program:nodemanager] -stdout_logfile = /home/bubble/logs/nodemanager-out.log -stderr_logfile = /home/bubble/logs/nodemanager-err.log +stdout_logfile = /var/log/bubble/nodemanager-out.log +stderr_logfile = /var/log/bubble/nodemanager-err.log command=/usr/sbin/bubble-nodemanager diff --git a/bubble-server/src/main/resources/packer/roles/firewall/files/supervisor_bubble_peer_manager.conf b/bubble-server/src/main/resources/packer/roles/firewall/files/supervisor_bubble_peer_manager.conf index 01347d8d..a0087284 100644 --- a/bubble-server/src/main/resources/packer/roles/firewall/files/supervisor_bubble_peer_manager.conf +++ b/bubble-server/src/main/resources/packer/roles/firewall/files/supervisor_bubble_peer_manager.conf @@ -1,5 +1,5 @@ [program:bubble_peer_manager] -stdout_logfile = /var/log/bubble_peer_manager-out.log -stderr_logfile = /var/log/bubble_peer_manager-err.log +stdout_logfile = /var/log/bubble/bubble_peer_manager-out.log +stderr_logfile = /var/log/bubble/bubble_peer_manager-err.log command=bash -c "/usr/local/bin/bubble_peer_manager.py /home/bubble/peers.json /home/bubble/self_node.json 60" diff --git a/bubble-server/src/main/resources/packer/roles/mitmproxy/files/mitm_monitor.sh b/bubble-server/src/main/resources/packer/roles/mitmproxy/files/mitm_monitor.sh index 0c65568a..ea7443ba 100644 --- a/bubble-server/src/main/resources/packer/roles/mitmproxy/files/mitm_monitor.sh +++ b/bubble-server/src/main/resources/packer/roles/mitmproxy/files/mitm_monitor.sh @@ -2,7 +2,7 @@ # # Copyright (c) 2020 Bubble, Inc. All rights reserved. For personal (non-commercial) use, see license: https://getbubblenow.com/bubble-license/ # -LOG=/tmp/mitm_monitor.log +LOG=/var/log/bubble/mitm_monitor.log function die { echo 1>&2 "${1}" diff --git a/bubble-server/src/main/resources/packer/roles/mitmproxy/tasks/main.yml b/bubble-server/src/main/resources/packer/roles/mitmproxy/tasks/main.yml index 61097c0a..d6435fd0 100644 --- a/bubble-server/src/main/resources/packer/roles/mitmproxy/tasks/main.yml +++ b/bubble-server/src/main/resources/packer/roles/mitmproxy/tasks/main.yml @@ -27,6 +27,7 @@ shell: /bin/bash system: yes home: /home/mitmproxy + groups: bubble-log - name: Creates mitmproxy dir file: diff --git a/bubble-server/src/main/resources/packer/roles/nginx/files/init_certbot.sh b/bubble-server/src/main/resources/packer/roles/nginx/files/init_certbot.sh index 467b69e9..668292c4 100755 --- a/bubble-server/src/main/resources/packer/roles/nginx/files/init_certbot.sh +++ b/bubble-server/src/main/resources/packer/roles/nginx/files/init_certbot.sh @@ -2,7 +2,7 @@ # # Copyright (c) 2020 Bubble, Inc. All rights reserved. For personal (non-commercial) use, see license: https://getbubblenow.com/bubble-license/ # -LOG=/tmp/init_certbot.log +LOG=/var/log/bubble/init_certbot.log function log { echo "$(date): ${1}" >> ${LOG} diff --git a/bubble-server/src/main/resources/packer/roles/nginx/files/init_dhparams.sh b/bubble-server/src/main/resources/packer/roles/nginx/files/init_dhparams.sh index 270a1e50..99c4c086 100644 --- a/bubble-server/src/main/resources/packer/roles/nginx/files/init_dhparams.sh +++ b/bubble-server/src/main/resources/packer/roles/nginx/files/init_dhparams.sh @@ -2,7 +2,7 @@ # # Copyright (c) 2020 Bubble, Inc. All rights reserved. For personal (non-commercial) use, see license: https://getbubblenow.com/bubble-license/ # -LOG=/tmp/dhparams.log +LOG=/var/log/bubble/dhparams.log DH_PARAMS=/etc/nginx/dhparams.pem function log { From 65b683cafdda5264e0060efa4bb7c8a3c39eb332 Mon Sep 17 00:00:00 2001 From: Tyler Chen Date: Wed, 29 Jul 2020 23:23:05 +0000 Subject: [PATCH 2/3] fix: message changes (#35) Merge branch 'master' into fix/message_changes fix: message changes Co-authored-by: jonathan Co-authored-by: ever-dev Reviewed-on: https://git.bubblev.org/bubblev/bubble/pulls/35 --- .../post_auth/ResourceMessages.properties | 2 +- .../pre_auth/ResourceMessages.properties | 36 +++++++++---------- 2 files changed, 19 insertions(+), 19 deletions(-) diff --git a/bubble-server/src/main/resources/message_templates/en_US/server/post_auth/ResourceMessages.properties b/bubble-server/src/main/resources/message_templates/en_US/server/post_auth/ResourceMessages.properties index 452619ea..8b8c0e4a 100644 --- a/bubble-server/src/main/resources/message_templates/en_US/server/post_auth/ResourceMessages.properties +++ b/bubble-server/src/main/resources/message_templates/en_US/server/post_auth/ResourceMessages.properties @@ -308,7 +308,7 @@ payment_type_credit_applied=credit applied payment_type_refund=refund label_promotion_FirstMonthFree=First Month Free -label_promotion_FirstMonthFree_description=No charge for the first month of your plan! +label_promotion_FirstMonthFree_description=There is no charge for the first month of your Bubble. label_promotion_ReferralMonthFree=Referral Bonus label_promotion_ReferralMonthFree_description=An additional month of free service! label_promotion_AccountCredit1=$1 Bonus diff --git a/bubble-server/src/main/resources/message_templates/en_US/server/pre_auth/ResourceMessages.properties b/bubble-server/src/main/resources/message_templates/en_US/server/pre_auth/ResourceMessages.properties index 4035caa8..18f86f89 100644 --- a/bubble-server/src/main/resources/message_templates/en_US/server/pre_auth/ResourceMessages.properties +++ b/bubble-server/src/main/resources/message_templates/en_US/server/pre_auth/ResourceMessages.properties @@ -344,27 +344,27 @@ marketing_message_dedicated_title=Dedicated, Private & Secure marketing_message_dedicated_content=Your Bubble runs on its own dedicated system. Not even we have access to your Bubble. marketing_pricing_title=What does it cost? -marketing_pricing_options=standard,plus,super +marketing_pricing_options=personal,power,mega marketing_pricing_common_options=Free 30-day Trial,Bubble App Suite Included,Connect Unlimited Devices,Dedicated Private VPN marketing_pricing_period=/mo -marketing_pricing_standard_title=Standard Plan -marketing_pricing_standard_users=1 User Account -marketing_pricing_standard_price=1200 -marketing_pricing_standard_options=1 User Account,1TB/Month of Data Transfer -marketing_pricing_standard_link=/register?plan=bubble - -marketing_pricing_plus_title=Plus Plan -marketing_pricing_plus_users=5 User Accounts -marketing_pricing_plus_price=1900 -marketing_pricing_plus_options=5 User Accounts,2TB/Month of Data Transfer -marketing_pricing_plus_link=/register?plan=bubble_plus - -marketing_pricing_super_title=Super Plan -marketing_pricing_super_users=10 User Accounts -marketing_pricing_super_price=3100 -marketing_pricing_super_options=10 User Accounts,3TB/Month of Data Transfer -marketing_pricing_super_link=/register?plan=bubble_super +marketing_pricing_personal_title=Personal Bubble +marketing_pricing_personal_users=1 User Account +marketing_pricing_personal_price=1200 +marketing_pricing_personal_options=1 User Account,1TB/Month of Data Transfer +marketing_pricing_personal_link=/register?plan=bubble + +marketing_pricing_power_title=Power Plan +marketing_pricing_power_users=5 User Accounts +marketing_pricing_power_price=1900 +marketing_pricing_power_options=5 User Accounts,2TB/Month of Data Transfer +marketing_pricing_power_link=/register?plan=bubble_plus + +marketing_pricing_mega_title=Mega Plan +marketing_pricing_mega_users=10 User Accounts +marketing_pricing_mega_price=3100 +marketing_pricing_mega_options=10 User Accounts,3TB/Month of Data Transfer +marketing_pricing_mega_link=/register?plan=bubble_super # Old Login/Registration/Forgot Password form_title_login=Login From 5f18763c19f496377772fcb00fe0bb0b75530a92 Mon Sep 17 00:00:00 2001 From: Kristijan Mitrovic Date: Wed, 29 Jul 2020 23:26:13 +0000 Subject: [PATCH 3/3] Fix TTL parameter in redis calls with EX (#36) Merge branch 'master' into kris/fix_ex_ttl_in_redis_calls Fix TTL parameter in redis calls with EX Co-authored-by: jonathan Co-authored-by: Kristijan Mitrovic Reviewed-on: https://git.bubblev.org/bubblev/bubble/pulls/36 --- .../main/java/bubble/cloud/storage/s3/S3StorageDriver.java | 6 +++--- .../java/bubble/service/cloud/StorageStreamService.java | 2 +- .../bubble/service/upgrade/BubbleJarUpgradeService.java | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/bubble-server/src/main/java/bubble/cloud/storage/s3/S3StorageDriver.java b/bubble-server/src/main/java/bubble/cloud/storage/s3/S3StorageDriver.java index f03c68e9..b1119009 100644 --- a/bubble-server/src/main/java/bubble/cloud/storage/s3/S3StorageDriver.java +++ b/bubble-server/src/main/java/bubble/cloud/storage/s3/S3StorageDriver.java @@ -50,7 +50,7 @@ import static org.cobbzilla.wizard.cache.redis.RedisService.EX; public class S3StorageDriver extends StorageServiceDriverBase { public static final long STALE_REQUEST_TIMEOUT = HOURS.toMillis(1); - public static final long LISTING_TIMEOUT = MINUTES.toMillis(10); + public static final long LISTING_IN_REDIS_TTL = MINUTES.toSeconds(10); @Autowired private BubbleNodeDAO nodeDAO; @Autowired private RedisService redis; @@ -238,7 +238,7 @@ public class S3StorageDriver extends StorageServiceDriverBase { listing.getObjectSummaries().forEach(o -> keys.add(o.getKey().substring(rootPrefix.length()))); final ListingRequest listingRequest = new ListingRequest(key, listing); - getActiveListings().set(listRequestId, json(listingRequest), EX, LISTING_TIMEOUT); + getActiveListings().set(listRequestId, json(listingRequest), EX, LISTING_IN_REDIS_TTL); return new StorageListing() .setListingId(listRequestId) @@ -258,7 +258,7 @@ public class S3StorageDriver extends StorageServiceDriverBase { listingRequest.objectListing = s3client.listNextBatchOfObjects(listingRequest.objectListing); listingRequest.objectListing.getObjectSummaries().forEach(o -> keys.add(o.getKey().substring(rootPrefix.length()))); - activeListings.set(listingId, json(listingRequest), EX, LISTING_TIMEOUT); + activeListings.set(listingId, json(listingRequest), EX, LISTING_IN_REDIS_TTL); return new StorageListing() .setListingId(listingId) diff --git a/bubble-server/src/main/java/bubble/service/cloud/StorageStreamService.java b/bubble-server/src/main/java/bubble/service/cloud/StorageStreamService.java index 83300be0..637d86f1 100644 --- a/bubble-server/src/main/java/bubble/service/cloud/StorageStreamService.java +++ b/bubble-server/src/main/java/bubble/service/cloud/StorageStreamService.java @@ -31,7 +31,7 @@ import static org.cobbzilla.wizard.resources.ResourceUtil.notFoundEx; @Service @Slf4j public class StorageStreamService { - public static final long TOKEN_TTL = SECONDS.toMillis(30); + public static final long TOKEN_TTL = SECONDS.toSeconds(30); public static final String WR_PREFIX = "writeRequest:"; diff --git a/bubble-server/src/main/java/bubble/service/upgrade/BubbleJarUpgradeService.java b/bubble-server/src/main/java/bubble/service/upgrade/BubbleJarUpgradeService.java index 042a0610..918f74c9 100644 --- a/bubble-server/src/main/java/bubble/service/upgrade/BubbleJarUpgradeService.java +++ b/bubble-server/src/main/java/bubble/service/upgrade/BubbleJarUpgradeService.java @@ -51,7 +51,7 @@ public class BubbleJarUpgradeService { public String registerNodeUpgrade(String nodeUuid) { final String key = randomAlphanumeric(10) + "." + now(); - getNodeUpgradeRequests().set(key, nodeUuid, EX, MINUTES.toMillis(1)); + getNodeUpgradeRequests().set(key, nodeUuid, EX, MINUTES.toSeconds(1)); return key; }