Scripted maintenance mode
-
Since you're on MongoDB you can execute the mongodb command to set the maintenance mode value in
config
.I'm not sure on the specifics (@baris is more familiar with it), but you put in the commands in a file and then you can run it using the
mongo
keyword.The command, by the way is:
use myDatabase db.objects.update({ _key: "config" }, { $set: { "maintenanceMode": 0 } });
Then you can restart NodeBB (as the value is cached and you can't alter the value of the running memory via script), and take your backup.
A maintenance mode route in the write-api could be handier though.
-
Ignore this post, continue reading
Oh, right. That is actually a much better idea.
Fast and dirty simple solution would be to write two JavaScript file.
// start-maintenance.js db.objects.update({ _key: "config" }, { $set: { "maintenanceMode": 1 } }) db.objects.update({ _key: "config" }, { $set: { "maintenanceModeMessage": "Backup in progress! We are back online in a few minutes!" } })
// stop-maintenance.js db.objects.update({ _key: "config" }, { $set: { "maintenanceMode": 0 } })
And then have the backup script:
#!/bin/sh mongo -u user -p pass mongo-hostname/nodebb-db-name start-maintenance.js mongodump -h mongo-hostname -u user -p pass --db=nodebb-db-name mongo -u user -p pass mongo-hostname/nodebb-db-name stop-maintenance.js
I probably might do it via Python. Just so I don't need to have the username and password in the command line of
mongo
andmongodump
.Thanks!
-
While showering this morning I realized that his solution won't work. Why? Because of caching. NodeBB caches the configuration. It also has an LRU cache for all objects in which this probably will stay cached as well. Thus changing the value in the database directly won't ever be read by NodeBB.
@julian You should be aware of this!
-
@dravere that's why he said to restart NodeBB after making the changes.
-
POST/DELETE route to toggle maintenance mode ยท Issue #96 ยท NodeBB/nodebb-plugin-write-api
https://community.nodebb.org/topic/12275/scripted-maintenance-mode/8
GitHub (github.com)