Discourse 升级中断服务 4 个小时

说实话,这种频繁的升级还是比较容易出问题。

今天升级就出现了下面的这个问题。

FAILED
--------------------
Pups::ExecError: cd /var/www/discourse && if [ -f yarn.lock ]; then
  if [ -d node_modules/.pnpm ]; then
    echo "This version of Discourse uses yarn, but pnpm node_modules are preset. Cleaning up..."
    find ./node_modules ./app/assets/javascripts/*/node_modules -mindepth 1 -maxdepth 1 -exec rm -rf {} +
  fi
  su discourse -c 'yarn install --frozen-lockfile && yarn cache clean'
else
  su discourse -c 'CI=1 pnpm install --frozen-lockfile && pnpm prune'
fi failed with return #<Process::Status: pid 421 exit 1>
Location of failure: /usr/local/lib/ruby/gems/3.3.0/gems/pups-1.2.1/lib/pups/exec_command.rb:132:in `spawn'
exec failed with the params {"cd"=>"$home", "hook"=>"yarn", "cmd"=>["if [ -f yarn.lock ]; then\n  if [ -d node_modules/.pnpm ]; then\n    echo \"This version of Discourse uses yarn, but pnpm node_modules are preset. Cleaning up...\"\n    find ./node_modules ./app/assets/javascripts/*/node_modules -mindepth 1 -maxdepth 1 -exec rm -rf {} +\n  fi\n  su discourse -c 'yarn install --frozen-lockfile && yarn cache clean'\nelse\n  su discourse -c 'CI=1 pnpm install --frozen-lockfile && pnpm prune'\nfi"]}
bootstrap failed with exit code 1
** FAILED TO BOOTSTRAP ** please scroll up and look for earlier error messages, there may be more than one.
./discourse-doctor may help diagnose the problem.
8aca470809dda6ed910eb4e64c0018b930db0678126c55b0983fa21320d4fb90
root@www:/var/discourse# dir
LICENSE  README.md  bin  cids  containers  discourse-doctor  discourse-setup  image  launcher  samples	scripts  shared  templates  tests
root@www:/var/discourse# cd containers/
root@www:/var/discourse/containers# dir
app.yml
root@www:/var/discourse/containers# vi app.yml 
root@www:/var/discourse/containers# cd ..
root@www:/var/discourse# ./launcher rebuild app
x86_64 arch detected.
Ensuring launcher is up to date
Launcher is up-to-date
Stopping old container
+ /usr/bin/docker stop -t 600 app

后来发现,出现这个问题的原因是: npm registry 访问异常。

导致整个编译无法完成。

这个情况就是今天正好碰到服务不可用。

1 Like

想问问升级不成功的时候为啥不及时做回滚,这样不至于中断很久?

或者有没有Test env 可以先尝试升级如果成功之后再升级prod env,可行的话 大概具体怎么执行呢?

通常来说 Discourse 升级是没有什么问题的。

这次出现问题的原因是,Discourse 我们有些插件用了我们自己的代码库,但这些代码库我们换路径了,最开始的代码库名拼写错误。

升级的时候如果这些代码库不可用的话也会提示错误。

第二个问题就是,在构建 npm 的时候,远程仓库突然不可用,结果导致构建错误,因为没有办法拉取回来最新的依赖。

感觉是最奇葩的时刻都遇到了。

恢复

最后我们的还是用了一台新服务器给老的备份给恢复回来了才可以用的,

实际上,老的服务器在 npm 服务器恢复正常后就可以了,

通常 Discourse 重构都能解决问题,只是这次的时间是太凑巧了。

Discourse 的系统升级设计逻辑和其他很多软件不一样。

Discourse 认为所有的版本只要重构都能解决问题,他们的重构是重构一个 Docker 的镜像,然后把老的镜像删除掉。

到那个新的镜像不可用的话,老的镜像是可用重新挂进来使用的,因为 Discourse 只是重构失败,老镜像还在。

我们的问题是,在老镜像中升级插件没有成功 ,因为代码库找不到了,重构的时候 npm 又出问题,导致新镜像构建不起来。

这个时候,解决办法就是找到更老的镜像然后给挂进来。

好在后来 npm 仓库恢复工作了,问题也就解决了。

不过也给我们提示,在升级 Discourse 的时候最好做个备份,最差的情况也可用通过备份给恢复在新服务器上。

正是因为上面的设计,Discourse 就没有提供生产和测试环境的概念了。