Discourse rebuild app报错Pups::ExecError: cd /var/www/discourse && su discourse -c 'bundle exec rake db:migrate' failed with return #<Process::Status: pid 851 exit 1>

在另一台服务器上部署,又碰到了新问题 :melting_face:

报错

Pups::ExecError: cd /var/www/discourse && su discourse -c 'bundle exec rake db:migrate' failed with return #<Process::Status: pid 851 exit 1>

原因和尝试

可能是因为这个报错?

PG::InsufficientPrivilege: ERROR:  permission denied for table pg_type

app.yml配置

root@cvm-3k8ngdw25i225:/var/discourse# cat containers/app.yml
## this is the all-in-one, standalone Discourse Docker container template
##
## After making changes to this file, you MUST rebuild
## /var/discourse/launcher rebuild app
##
## BE *VERY* CAREFUL WHEN EDITING!
## YAML FILES ARE SUPER SUPER SENSITIVE TO MISTAKES IN WHITESPACE OR ALIGNMENT!
## visit http://www.yamllint.com/ to validate this file as needed

templates:
  - "templates/postgres.template.yml"
  - "templates/redis.template.yml"
  # - "templates/web.china.template.yml"
  - "templates/web.template.yml"
  ## Uncomment the next line to enable the IPv6 listener
  #- "templates/web.ipv6.template.yml"
  - "templates/web.ratelimited.template.yml"
  ## Uncomment these two lines if you wish to add Lets Encrypt (https)
  - "templates/web.ssl.template.yml"
  - "templates/web.letsencrypt.ssl.template.yml"

## which TCP/IP ports should this container expose?
## If you want Discourse to share a port with another webserver like Apache or nginx,
## see https://meta.discourse.org/t/17247 for details
expose:
  - "80:80"   # http
  - "443:443" # https

params:
  db_default_text_search_config: "pg_catalog.english"

  ## Set db_shared_buffers to a max of 25% of the total memory.
  ## will be set automatically by bootstrap based on detected RAM, or you can override
  db_shared_buffers: "256MB"

  ## can improve sorting performance, but adds memory usage per-connection
  #db_work_mem: "40MB"

  ## Which Git revision should this container use? (default: tests-passed)
  #version: tests-passed

env:
  LC_ALL: en_US.UTF-8
  LANG: en_US.UTF-8
  LANGUAGE: en_US.UTF-8
  # DISCOURSE_DEFAULT_LOCALE: en

  ## How many concurrent web requests are supported? Depends on memory and CPU cores.
  ## will be set automatically by bootstrap based on detected CPUs, or you can override
  UNICORN_WORKERS: 4

  ## TODO: The domain name this Discourse instance will respond to
  ## Required. Discourse will not work with a bare IP number.
  DISCOURSE_HOSTNAME: discuss.beginner.center

  ## Uncomment if you want the container to be started with the same
  ## hostname (-h option) as specified above (default "$hostname-$config")
  #DOCKER_USE_HOSTNAME: true

  ## TODO: List of comma delimited emails that will be made admin and developer
  ## on initial signup example '[email protected],[email protected]'
  DISCOURSE_DEVELOPER_EMAILS: '[email protected]'

  ## TODO: The SMTP mail server used to validate new accounts and send notifications
  # SMTP ADDRESS, username, and password are required
  # WARNING the char '#' in SMTP password can cause problems!
  DISCOURSE_SMTP_ADDRESS: smtp.mailgun.org
  DISCOURSE_SMTP_PORT: 587
  DISCOURSE_SMTP_USER_NAME: [email protected]
  DISCOURSE_SMTP_PASSWORD: "my smtp password"
  #DISCOURSE_SMTP_ENABLE_START_TLS: true           # (optional, default true)
  DISCOURSE_SMTP_DOMAIN: mg.beinner.center
  DISCOURSE_NOTIFICATION_EMAIL: [email protected]

  ## If you added the Lets Encrypt template, uncomment below to get a free SSL certificate
  LETSENCRYPT_ACCOUNT_EMAIL: [email protected]

  ## The http or https CDN address for this Discourse instance (configured to pull)
  ## see https://meta.discourse.org/t/14857 for details
  #DISCOURSE_CDN_URL: https://discourse-cdn.example.com
  
  ## The maxmind geolocation IP address key for IP address lookup
  ## see https://meta.discourse.org/t/-/137387/23 for details
  #DISCOURSE_MAXMIND_LICENSE_KEY: 1234567890123456

## The Docker container is stateless; all data is stored in /shared
volumes:
  - volume:
      host: /var/discourse/shared/standalone
      guest: /shared
  - volume:
      host: /var/discourse/shared/standalone/log/var-log
      guest: /var/log

## Plugins go here
## see https://meta.discourse.org/t/19157 for details
hooks:
  after_code:
    - exec:
        cd: $home/plugins
        cmd:
          - git clone https://github.com/discourse/docker_manager.git

## Any custom commands to run after building
run:
  - exec: echo "Beginning of custom commands"
  ## If you want to set the 'From' email address for your first registration, uncomment and change:
  ## After getting the first signup email, re-comment the line. It only needs to run once.
  - exec: rails r "SiteSetting.notification_email='[email protected]'"
  - exec: echo "End of custom commands"
root@cvm-3k8ngdw25i225:/var/discourse# 

rebuild完整记录

麻烦大哥再帮忙看看 @honeymoose

如果安装插件不是必须,推荐,其实也可以安装插件的

https://bitnami.com/stack/discourse/containers

国内的dockerhub上不去,有镜像直接下载可以用docker-compose直接安装,很简单。

1 Like

非常感谢你提供的新方案!

我看了一下bitnami的部署过程,好像得同时部署好几个docker,想想就头大 :melting_face:,而且没有discourse官方这样的交流环境,遇到啥问题光靠自己看手册可能太困难了,备用吧

@whitewatercn 的安装环境其实比较好,他的服务器在外面,所以网络访问应该是没有什么问题。

如果服务器在内网络环境,问题更多一些。这个时候 Docker 容器安装会简化一些内容。

其实你这个问题已经有提示了,我搜素了下你的日志。

日志中的最后的问题可能不是真正问题的所在。

我感觉你这次安装不是全新安装吧,上面的日志提示在这行:

2023-06-08 01:19:04.972 UTC [55] postgres@template1 ERROR:  database "discourse" already exists
2023-06-08 01:19:04.972 UTC [55] postgres@template1 STATEMENT:  CREATE DATABASE discourse;
createdb: error: database creation failed: ERROR:  database "discourse" already exists
I, [2023-06-08T01:19:04.977485 #1]  INFO -- : 
I, [2023-06-08T01:19:04.978414 #1]  INFO -- : > su postgres -c 'psql discourse -c "create user discourse;"' || true
2023-06-08 01:19:05.654 UTC [59] postgres@discourse ERROR:  role "discourse" already exists
2023-06-08 01:19:05.654 UTC [59] postgres@discourse STATEMENT:  create user discourse;
ERROR:  role "discourse" already exists

提示的是数据库已经存在了,Discourse 没有办法帮你重建数据库。

可能需要把 Docker 的容器删除清理掉,再重新安装。

小提示

程序错误最后提供的错误信息可能不是最终的错误信息。

就好像 Java 有个错误栈,最后会提示一个空对象异常,但是真正的原因可能不在这里,有很多原因会导致空对象异常。

所以可能要往上翻一下。

简单的一个小技巧就是拿到完整的日志后,搜索关键字: ERROR(不区分大小写)看看具体问题在哪里。

1 Like

刚刚用docker ps并没有容器,我猜可能是我一边部署一边还docker system prune(之前提示了空间不足,查了一下是pull太多次

感谢排查思路分享 :smiling_face_with_three_hearts:,以前看到一大堆日志眼都花了,之后我用ERROR搜索

哈哈,好的,好的。

不过觉得你已经做得很好了呢,你的日志是完整的。

比我们这边很多搞程序和测试都做得好,他们很多人贴的日志都不完整,都只有一部分,然后让开发去找问题。

这个问题根本就找不到不是,花了 2 天时间都找到问题在哪里,最后发现奶奶的是 DevOps 把网络端口给关了,你这不是瞎扯吗。

这是真事,我上一个公司就这情况,经常 2 天后发现问题压根不是问题。

DevOps 那边说,这不是他们的问题,各种扯皮。

嗯嗯,我在discourse官网看了很多报错帖子,发现很多人也是只放了一部分,用./discourse-doctor获取了完整的日志才能帮助排查解决问题

是的,我内网环境,用那个安装超简单,加载镜像,yml配置镜像版本,参数,docker-compose一条命令就都搞定了。
安装插件,进入容器,和你们在外网编译是一样的命令安装

2 Likes

get,谢谢分享,等我实在折腾不动官方方法就试试这个😂