The discussion revolves around the issue of the site automatically exiting read-only mode when enabled by ‘discourse enable_readonly’. The original poster, RhysGoodwin, mentions that when enabling read-only mode via the command line interface, it only stays enabled for approximately 1 minute and 20 seconds, whereas enabling it via the WebUI keeps it enabled until manually disabled.
RhysGoodwin checked the logs but didn’t find anything unusual. pfaffman shared a similar experience and suggested running Discourse.enable_readonly_mode in rails instead. RhysGoodwin considered using an API call or exploring Post Deployment Migration as an alternative.
JammyDodger pointed out that the difference might be due to the type of read-only mode used. The READONLY_MODE_KEY is mainly used for backup and restore processes and does not survive container restarts, whereas the USER_READONLY_MODE_KEY is used when an admin enables read-only mode and survives container restarts.
RhysGoodwin confirmed that using Discourse.enable_readonly_mode(Discourse::USER_READONLY_MODE_KEY) keeps the read-only mode enabled indefinitely, achieving the desired outcome. The solution was implemented using an Ansible shell command, as shown in RhysGoodwin’s updated code snippet.
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 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.
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
- 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