# Read-only mode please!

**URL:** https://meta.discourse.org/t/read-only-mode-please/12163
**Category:** Feature
**Tags:** read-only
**Created:** [2014年一月24日 06:23 UTC](https://meta.discourse.org/t/read-only-mode-please/12163 "2014-01-24T06:23:27Z")
**Posts on this page:** 20
**Page:** 1

<div class="post-metadata">

### Author: ![supermathie](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/supermathie/32/507518_2.png) [@supermathie](https://meta.discourse.org/u/supermathie)
#### Post date: [2014年一月24日 06:23 UTC](https://meta.discourse.org/t/read-only-mode-please/12163/1 "2014-01-24T06:23:27Z")

</div>

Having a read-only mode would be great in a few situations:

- failover to standby read-only database
- migrations (set read-only, slurp data, restore, switch DNS)
- upgrades (could upgrade and leave the old thins up and running safely)

Please add! I’ll love you forever.

---

<div class="post-metadata">

### Author: ![riking](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/riking/32/170938_2.png) [@riking](https://meta.discourse.org/u/riking)
#### Post date: [2014年一月24日 06:37 UTC](https://meta.discourse.org/t/read-only-mode-please/12163/2 "2014-01-24T06:37:41Z")

</div>

I’m trying to find where one of the team said that this was needed/coming, but I just can’t find it!

But yes, a “manual site maintenance” mode is essential. Even if upgrades happen transparently almost all of the time with the `/admin/docker` page.

---

<div class="post-metadata">

### Author: ![codinghorror](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/codinghorror/32/110067_2.png) [@codinghorror](https://meta.discourse.org/u/codinghorror)
#### Post date: [2014年一月24日 08:36 UTC](https://meta.discourse.org/t/read-only-mode-please/12163/3 "2014-01-24T08:36:09Z")

</div>

We haven’t said we need it in public yet, but we definitely do.. no question.

---

<div class="post-metadata">

### Author: ![zogstrip](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/zogstrip/32/512781_2.png) [@zogstrip](https://meta.discourse.org/u/zogstrip)
#### Post date: [2014年二月20日 23:49 UTC](https://meta.discourse.org/t/read-only-mode-please/12163/4 "2014-02-20T23:49:39Z")

</div>

I made this one for you @supermathie.

Now you can go to: Admin \> Backups and click on the ![](https://global.discourse-cdn.com/meta/original/2X/e/ecbb2920d723d105c842da400b43c6edc80a95c6.png) button 😉

---

<div class="post-metadata">

### Author: ![supermathie](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/supermathie/32/507518_2.png) [@supermathie](https://meta.discourse.org/u/supermathie)
#### Post date: [2014年二月21日 00:16 UTC](https://meta.discourse.org/t/read-only-mode-please/12163/5 "2014-02-21T00:16:51Z")

</div>

Awesome! How do I do it from a rake task (or CLI)? Where is it saved? Postgres or redis?

Presumably this only affects a single site in a multisite setup, so how can I toggle it for all sites on a host?

---

<div class="post-metadata">

### Author: ![riking](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/riking/32/170938_2.png) [@riking](https://meta.discourse.org/u/riking)
#### Post date: [2014年二月21日 00:29 UTC](https://meta.discourse.org/t/read-only-mode-please/12163/6 "2014-02-21T00:29:23Z")

</div>

With `Discourse.enable_readonly_mode` and `Discourse.disable_readonly_mode`, which set a flag in Redis and publish a message on the MessageBus.

```ruby
  def self.enable_readonly_mode
    $redis.set readonly_mode_key, 1
    MessageBus.publish(readonly_channel, true) # "/site/read-only"
    true
  end

  def self.disable_readonly_mode
    $redis.del readonly_mode_key
    MessageBus.publish(readonly_channel, false)
    true
  end

```

---

<div class="post-metadata">

### Author: ![zogstrip](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/zogstrip/32/512781_2.png) [@zogstrip](https://meta.discourse.org/u/zogstrip)
#### Post date: [2014年二月21日 16:12 UTC](https://meta.discourse.org/t/read-only-mode-please/12163/7 "2014-02-21T16:12:10Z")

</div>

> [@supermathie](#):
>
> How do I do it from a rake task (or CLI)?

You can [now](https://github.com/discourse/discourse/commit/4c941495e5a28955c07d97ef04b16da538de7b4f) run `script/discourse enable_readonly` or `script/discourse disable_readonly` to enable/disable the readonly mode.

> [@supermathie](#):
>
> Where is it saved? Postgres or redis?

As @riking said, it’s saved in redis right now. Would not make sense to save it in a read-only database 😄

> [@supermathie](#):
>
> Presumably this only affects a single site in a multisite setup, so how can I toggle it for all sites on a host?

Not implemented yet. This was mostly made for a site’s admin. Not a super-admin.

---

<div class="post-metadata">

### Author: ![supermathie](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/supermathie/32/507518_2.png) [@supermathie](https://meta.discourse.org/u/supermathie)
#### Post date: [2014年二月25日 21:56 UTC](https://meta.discourse.org/t/read-only-mode-please/12163/8 "2014-02-25T21:56:07Z")

</div>

> [@zogstrip](#):
>
> Would not make sense to save it in a read-only database

Speaking of, what happens if Discourse notices that the postgres to which it’s connected is operating in read-only mode? Will it set `readonly`? Will it behave nicely? Or is that FINR? 😄

> [@zogstrip](#):
>
> Not implemented yet.

So for sites in a multisite setup, I’ll need to iterate over each site and disable it for each? OK, can do.

---

<div class="post-metadata">

### Author: ![supermathie](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/supermathie/32/507518_2.png) [@supermathie](https://meta.discourse.org/u/supermathie)
#### Post date: [2014年二月26日 07:16 UTC](https://meta.discourse.org/t/read-only-mode-please/12163/9 "2014-02-26T07:16:07Z")

</div>

> [@supermathie](#):
>
> Speaking of, what happens if Discourse notices that the postgres to which it’s connected is operating in read-only mode?

Topics load, mostly. Most requests (notifications, etc) puke and die with a 500.

---

<div class="post-metadata">

### Author: ![zogstrip](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/zogstrip/32/512781_2.png) [@zogstrip](https://meta.discourse.org/u/zogstrip)
#### Post date: [2014年二月27日 14:46 UTC](https://meta.discourse.org/t/read-only-mode-please/12163/10 "2014-02-27T14:46:59Z")

</div>

> [@supermathie](#):
>
> So for sites in a multisite setup, I’ll need to iterate over each site and disable it for each? OK, can do.

Unfortunately yes.

> [@supermathie](#):
>
> Topics load, mostly. Most requests (notifications, etc) puke and die with a 500.

Read-only mode needs LOTS of polish on the client-side. We need to refactor and normalize how we deal with errors server-side first.

---

<div class="post-metadata">

### Author: ![illspirit](https://avatars.discourse-cdn.com/v4/letter/i/49beb7/32.png) [@illspirit](https://meta.discourse.org/u/illspirit)
#### Post date: [2014年三月1日 14:48 UTC](https://meta.discourse.org/t/read-only-mode-please/12163/11 "2014-03-01T14:48:04Z")

</div>

> [@zogstrip](#):
>
> You can now run script/discourse enable\_readonly or script/discourse disable\_readonly to enable/disable the readonly mode.

I got stuck in read only mode and I’m logged out, I tried just running `script/discourse disable_readonly` but I believe I’m doing it wrong. Where do I type the command?

I hate to bump this but I can’t access my website.

---

<div class="post-metadata">

### Author: ![riking](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/riking/32/170938_2.png) [@riking](https://meta.discourse.org/u/riking)
#### Post date: [2014年三月1日 22:18 UTC](https://meta.discourse.org/t/read-only-mode-please/12163/12 "2014-03-01T22:18:08Z")

</div>

In the root of your discourse install, you should be able to run `script/discourse` and get a help menu.

For docker installs, that means `cd /var/docker` `./launcher ssh app` `cd /var/www/discourse` `script/discourse`.

---

<div class="post-metadata">

### Author: ![illspirit](https://avatars.discourse-cdn.com/v4/letter/i/49beb7/32.png) [@illspirit](https://meta.discourse.org/u/illspirit)
#### Post date: [2014年三月1日 22:20 UTC](https://meta.discourse.org/t/read-only-mode-please/12163/13 "2014-03-01T22:20:43Z")

</div>

Yep, I did that and I’m getting this error message

```
/usr/local/lib/ruby/site_ruby/2.0.0/rubygems/core_ext/kernel_require.rb:55:in `require': cannot load such file -- thor (LoadError)
        from /usr/local/lib/ruby/site_ruby/2.0.0/rubygems/core_ext/kernel_require.rb:55:in `require'
        from script/discourse:3:in `<main>'

```

---

<div class="post-metadata">

### Author: ![codinghorror](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/codinghorror/32/110067_2.png) [@codinghorror](https://meta.discourse.org/u/codinghorror)
#### Post date: [2014年三月2日 07:22 UTC](https://meta.discourse.org/t/read-only-mode-please/12163/14 "2014-03-02T07:22:43Z")

</div>

Just FYI this is what it looks like, a banner at the top of every page:

![](https://global.discourse-cdn.com/meta/original/2X/3/33a0be83fb714b37b944133076c7da0b53e24ff2.png)

> An administrator has enabled read-only mode. You can continue to browse the site, but interactions won’t work properly.

---

<div class="post-metadata">

### Author: ![supermathie](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/supermathie/32/507518_2.png) [@supermathie](https://meta.discourse.org/u/supermathie)
#### Post date: [2014年三月2日 07:35 UTC](https://meta.discourse.org/t/read-only-mode-please/12163/15 "2014-03-02T07:35:55Z")

</div>

Have you updated to the latest? Are you running as the right user (discourse)?

---

<div class="post-metadata">

### Author: ![illspirit](https://avatars.discourse-cdn.com/v4/letter/i/49beb7/32.png) [@illspirit](https://meta.discourse.org/u/illspirit)
#### Post date: [2014年三月2日 13:21 UTC](https://meta.discourse.org/t/read-only-mode-please/12163/16 "2014-03-02T13:21:22Z")

</div>

Yeah I’m running latest on Docker, as discourse user.

I just ran the command manually, but `script/discourse` still gives me that error.

---

<div class="post-metadata">

### Author: ![zogstrip](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/zogstrip/32/512781_2.png) [@zogstrip](https://meta.discourse.org/u/zogstrip)
#### Post date: [2014年三月2日 17:30 UTC](https://meta.discourse.org/t/read-only-mode-please/12163/17 "2014-03-02T17:30:40Z")

</div>

Can you access the rails console?

```shell
cd /var/docker
./launcher ssh app

```

to ssh into the docker container.

```shell
cd /var/www/discourse
RAILS_ENV=production bundle exec rails c

```

to launch the console.

```ruby
Discourse.disable_readonly_mode

```

to disable the readonly mode.

---

<div class="post-metadata">

### Author: ![trident](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/trident/32/2078_2.png) [@trident](https://meta.discourse.org/u/trident)
#### Post date: [2014年三月2日 17:36 UTC](https://meta.discourse.org/t/read-only-mode-please/12163/18 "2014-03-02T17:36:01Z")

</div>

You can also `gem install thor` temporarily (until the next bootstrap); and the script will run. At least, it did for me.

---

<div class="post-metadata">

### Author: ![illspirit](https://avatars.discourse-cdn.com/v4/letter/i/49beb7/32.png) [@illspirit](https://meta.discourse.org/u/illspirit)
#### Post date: [2014年三月2日 18:46 UTC](https://meta.discourse.org/t/read-only-mode-please/12163/19 "2014-03-02T18:46:35Z")

</div>

This is how I ended up doing it, thanks.

---

<div class="post-metadata">

### Author: ![Sailsman63](https://avatars.discourse-cdn.com/v4/letter/s/b5ac83/32.png) [@Sailsman63](https://meta.discourse.org/u/Sailsman63)
#### Post date: [2014年三月2日 18:48 UTC](https://meta.discourse.org/t/read-only-mode-please/12163/20 "2014-03-02T18:48:51Z")

</div>

> [@zogstrip](#):
>
> Read-only mode needs LOTS of polish on the client-side.

One piece of client-side behavior that might be a little more vital than “polish:”

Here on meta last night I noticed that I **cannot log out** when the site is set to read-only. The logged in session persisted between browser restarts. This did not inconvenience me, as I was using my own device and internet connection, however not all forum users will be in that position.

If we assume that a user is at a public internet kiosk of some sort, (Public library, Internet cafe, etc.) The only way to prevent the user’s account from being compromised if he needs to leave is:

- Hope the user is savvy enough to clear his cookie cache before leaving.
- Hope the access point automatically does so between users.

In an ideal world, both of these would be true. In our world…

If you are already aware of this, sorry for the duplication. Just thought it might be worth mentioning.

[下一頁](https://meta.discourse.org/t/read-only-mode-please/12163.md?page=2)
