Site automatically exits read-only mode when enabled by 'discourse enable_readonly'

Hi folks,

I’m setting up some automation for deployment and migration with Ansible but I’ve got an issue with read-only mode.

When I enabled read-only with:
docker exec app discourse enable_readonly
or

./launcher enter app
discourse enable_readonly

After ~1:20 the site exits read-only mode all by itself.

If I enable read-only mode via the WebUI (admin/backups section), it stays enabled until I disable it.

Any thoughts?

1 Like

Did you check your logs? perhaps you have a background job or plugin somewhere that is interrupting the process.

Hi Lilly,

Thanks for your response. This is a fresh default install and I’ve not installed any plugins or created any jobs. Which logs am I best to look at? Sorry I’m a bit of a noob.

I’ve tried tail -f on:

/var/discourse/shared/standalone/log/rails/unicorn.stdout.log
/var/discourse/shared/standalone/log/rails/unicorn.stderr.log
/var/discourse/shared/standalone/log/rails/production_errors.log
/var/discourse/shared/standalone/log/rails/production.log
/var/discourse/shared/standalone/log/rails/sidekiq.log
/var/discourse/shared/standalone/log/var-log/redis/current

I waited for the event to occur while following the logs but I didn’t see anything that stood out.

It’s odd to me that it works perfectly when activated via the WebUI but not via cli.

I have had trouble using that as well, both for enabling and disabling readonly mode. The last time I ended up running Discourse.enable_readonly_mode in rails.

It’s always an emergency when it happens and I haven’t investigated what the issue might be.

FWIW, in my own Ansible tooling I don’t use read-only mode, but do use Introducing Post Deployment Migration

1 Like

Thanks Jay. I suspect I’m taking an XY approach to the problem. I’ll check out the Post Deployment Migration. Thanks for that.

I guess the other option might be to activate RO via an API call.

- name: post migrations
  shell: "docker exec  {{ discourse_yml }} bash -c 'rake db:ensure_post_migrations db:migrate'"
  become: yes

so this might work for read-only mode:

- name: post migrations
  shell: "docker exec  {{ discourse_yml }} bash -c 'echo Discourse.enable_readonly_mode | rails c"
  become: yes

Thank you, much appreciated. I’ll give this a go tonight.

1 Like

Is the difference down to the read-only mode you’re using?

3 Likes

Thanks JammyDodger! The info and link were very helpful. I’m not sure what constitutes a container restart - as far as I know my container is not restarting every ~1:30 which is as long as the RO mode stays enabled when using discourse enable_readonly i.e. Discourse.enable_readonly_mode(Discourse::READONLY_MODE_KEY)

I can confirm however that Discourse.enable_readonly_mode(Discourse::USER_READONLY_MODE_KEY) “sticks” indefinitely, which is what I was trying to achieve :+1:

1 Like

For completeness:

- name: Set read-only mode for live forum host
  ansible.builtin.shell: |
      docker exec app bash -c 'echo Discourse.enable_readonly_mode\(Discourse::USER_READONLY_MODE_KEY\) | rails c'
  register: enable_readonly_output
2 Likes

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.