Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make current version test more robust #34

Open
m4z opened this issue Dec 2, 2020 · 1 comment · May be fixed by #40
Open

Make current version test more robust #34

m4z opened this issue Dec 2, 2020 · 1 comment · May be fixed by #40

Comments

@m4z
Copy link

m4z commented Dec 2, 2020

As mentioned in the margin in #33, we often see the "current_rocketchat_version" check fail (on Debian 9.13) when running "rocketchatctl check-updates" and "rocketchatctl update", and that seems to cause additional problems, like in this case (first without debug output, then using "bash -x"):

[… rocketchat has just been backed up and was restarted by the backup command …]
trolls:~ # rocketchatctl update
Updates could be risky, you can use the backup option # rocketchatctl backup, to create a backup of the rocketchat database first. Please check that you have enough space in your system to store the backup.
/usr/local/bin/rocketchatctl: line 900: [: 3.9.0: unary operator expected
Could not determine if updates available for RocketChat server.


[… immediate retry with debugging enabled …]
trolls:~ # bash -x rocketchatctl update
+ set -o nounset
+ main update
+ local VERSION=latest
+ local -r NODE_VERSION=v12.14.0
+ local -r NPM_VERSION=6.13.4
+ local MONGO_VERSION=
+ local -r 'MONGO_URL=mongodb://localhost:27017/rocketchat?replicaSet=rs01'
+ local -r 'MONGO_OPLOG_URL=mongodb://localhost:27017/local?replicaSet=rs01'
+ local ROCKETCHAT_DOWNLOAD_URL=https://releases.rocket.chat/latest/download
+ local -r NODE_DEB_DOWNLOAD_URL=https://deb.nodesource.com/setup_12.x
+ local -r NODE_RPM_DOWNLOAD_URL=https://rpm.nodesource.com/setup_12.x
+ local -r ROCKETCHAT_DIR=/opt/Rocket.Chat
+ local -r ROCKETCHAT_DIR_UPDATE=/opt/Rocket.Chat.bkup
+ local -r ROCKET_VERSION_INFO_URL=https://releases.rocket.chat/latest/info
+ local -r ROCKETCHATCTL_DOWNLOAD_URL=https://raw.githubusercontent.com/RocketChat/install.sh/master/rocketchatctl
+ local -r ROCKETCHATCTL_DIRECTORY=/usr/local/bin
+ local -r ROCKETCHATCTL_TEMP_DIRECTORY=/tmp
+ local -r TRAEFIK_DOWNLOAD_URL=https://github.com/containous/traefik/releases/download/v1.7.20/traefik
+ local -r CADDY_DOWNLOAD_URL=https://github.com/mholt/caddy/releases/download/v1.0.0/caddy_v1.0.0_linux_amd64.tar.gz
+ local distro=
+ local distro_version=
+ local install_node=0
+ local install_mongo=0
+ local rocket_healthy=0
+ local ROOT_URL=
+ local PORT=3000
+ local BIND_IP=0.0.0.0
+ local bind_loopback=true
+ local webserver=none
+ local install_node_arg=0
+ local use_mongo_arg=0
+ local webserver_arg=0
+ local rocket_mail_arg=0
+ local bind_loopback_arg=0
+ local rocket_domain=
+ local configure_rocketchat=0
+ local configure_webserver=0
+ local root_url_arg=0
++ date +%s
+ local sufix=1606910670
+ local node_path=/usr/bin/node
+ local backup_dir=/tmp
+ local update_node=0
+ '[' 0 -ne 0 ']'
+ '[' 1 -lt 1 ']'
+ [[ -t 0 ]]
+ case $1 in
+ os_supported
+ get_os_distro
+ '[' -r /etc/os-release ']'
++ . /etc/os-release
+++ PRETTY_NAME='Debian GNU/Linux 9 (stretch)'
+++ NAME='Debian GNU/Linux'
+++ VERSION_ID=9
+++ VERSION='9 (stretch)'
+++ VERSION_CODENAME=stretch
+++ ID=debian
+++ HOME_URL=https://www.debian.org/
+++ SUPPORT_URL=https://www.debian.org/support
+++ BUG_REPORT_URL=https://bugs.debian.org/
++ echo debian
+ distro=debian
++ . /etc/os-release
+++ PRETTY_NAME='Debian GNU/Linux 9 (stretch)'
+++ NAME='Debian GNU/Linux'
+++ VERSION_ID=9
+++ VERSION='9 (stretch)'
+++ VERSION_CODENAME=stretch
+++ ID=debian
+++ HOME_URL=https://www.debian.org/
+++ SUPPORT_URL=https://www.debian.org/support
+++ BUG_REPORT_URL=https://bugs.debian.org/
++ echo 9
+ distro_version=9
+ case "$distro" in
+ [[ 9 =~ ((9|10)) ]]
+ do_check_updates
+ get_rocketchat_latest_version
+ command_exists curl
+ command -v curl
++ curl https://releases.rocket.chat/latest/info
++ awk '-F"' '{print $2}'
++ awk -F: '{print $2}'
++ grep -w tag
+ latest_rocketchat_version=3.9.0
+ get_rocketchat_current_version
+ systemctl status rocketchat
++ awk -F= '{print $3}'
++ grep PORT
++ cat /lib/systemd/system/rocketchat.service
+ PORT=3000
++ curl --interface lo http://localhost:3000/api/info
++ cut '-d"' -f4
+ current_rocketchat_version=
+ print_make_backup
+ echo 'Updates could be risky, you can use the backup option # rocketchatctl backup, to create a backup of the rocketchat database first. Please check that you have enough space in your system to store the backup.'
Updates could be risky, you can use the backup option # rocketchatctl backup, to create a backup of the rocketchat database first. Please check that you have enough space in your system to store the backup.
+ [[ '' =~ ^([0-2]\..\..)$ ]]
+ version_gt 3.9.0
++ head -n 1
++ printf '%s\n' 3.9.0
++ sort -V
+ test 3.9.0 '!=' 3.9.0
+ '[' 3.9.0 == ']'
/usr/local/bin/rocketchatctl: line 900: [: 3.9.0: unary operator expected
+ print_check_updates_error_and_exit
+ errcho 'Could not determine if updates available for RocketChat server.'
+ echo 'Could not determine if updates available for RocketChat server.'
Could not determine if updates available for RocketChat server.
+ exit 1

I'm going to demonstrate the behavior with the following script, which is largely copy-and-pasted from "rocketchatctl", plus an "until" patch I'm suggesting (ignore the "--interface lo", that's a patch for another day):

trolls:~ # cat test_version.sh
#!/bin/bash

PORT=$(cat /lib/systemd/system/rocketchat.service |grep PORT |awk -F= '{print $3}')

current_rocketchat_version=""
until [ -n "$current_rocketchat_version" ]; do
                current_rocketchat_version=$(curl --interface lo http://localhost:$PORT/api/info 2>/dev/null |cut -d\" -f4)
                sleep 1
        done
trolls:~ #

When running this on our very much non-beefy stage system, it behaves as follows:

trolls:~ # bash -x test_version.sh ; systemctl restart rocketchat.service ; bash -x test_version.sh
[…can't reproduce the problem when rocketchat is still running…]
++ cat /lib/systemd/system/rocketchat.service
++ awk -F= '{print $3}'
++ grep PORT
+ PORT=3000
+ current_rocketchat_version=
+ '[' -n '' ']'
++ curl --interface lo http://localhost:3000/api/info
++ cut '-d"' -f4
+ current_rocketchat_version=3.9.0
+ sleep 1
+ '[' -n 3.9.0 ']'
[…restart happens here…]
++ cat /lib/systemd/system/rocketchat.service
++ awk -F= '{print $3}'
++ grep PORT
+ PORT=3000
+ current_rocketchat_version=
+ '[' -n '' ']'
++ curl --interface lo http://localhost:3000/api/info
++ cut '-d"' -f4
+ current_rocketchat_version=
+ sleep 1
+ '[' -n '' ']'
++ curl --interface lo http://localhost:3000/api/info
++ cut '-d"' -f4
+ current_rocketchat_version=
+ sleep 1
[…4 minutes 30 seconds later, when Rocket.Chat has finished starting up…]
+ '[' -n '' ']'
++ cut '-d"' -f4
++ curl --interface lo http://localhost:3000/api/info
+ current_rocketchat_version=3.9.0
+ sleep 1
+ '[' -n 3.9.0 ']'
trolls:~ #

So, I suggest a patch similar to the following:

--- /usr/local/bin/rocketchatctl        2020-12-01 08:14:38.872413023 +0000
+++ /usr/local/bin/rocketchatctl.2020-12-02.issue-34.patch      2020-12-02 16:52:39.787651510 +0000
@@ -757,7 +757,11 @@
 get_rocketchat_current_version(){
     if systemctl status rocketchat > /dev/null 2>&1; then
         PORT=$(cat /lib/systemd/system/rocketchat.service |grep PORT |awk -F= '{print $3}')
-        current_rocketchat_version=$(curl http://localhost:$PORT/api/info 2>/dev/null |cut -d\" -f4)
+        current_rocketchat_version=""
+        until [ -n "$current_rocketchat_version" ]; do
+                current_rocketchat_version=$(curl http://localhost:$PORT/api/info 2>/dev/null |cut -d\" -f4)
+                sleep 1
+        done
     else
         print_rocketchat_not_running_error_and_exit
     fi

I believe (but I'm not sure) we've also in the past experienced this problem during the post-update startup wait period.

@frdmn
Copy link
Contributor

frdmn commented Dec 13, 2020

Hi @m4z. Thanks for reporting this. I have had come across this a couple of times in my local test environment as well. Will take a look at this ASAP.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants