• Home
  • Categories
  • Recent
  • Popular
  • Top
  • Tags
  • Users
  • Groups
  • Documentation
    • Home
    • Read API
    • Write API
    • Plugin Development
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
v3.5.2 Latest
Buy Hosting

Turn maintenance mode on/off from script.

Scheduled Pinned Locked Moved Technical Support
503maintenancescript
7 Posts 2 Posters 568 Views
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    MoJo
    wrote on last edited by MoJo
    #1

    I read this topic: https://community.nodebb.org/topic/12275/scripted-maintenance-mode/4

    And there are three ways of turning maintainence mode:
    1st

    use myDatabase
    db.objects.update({ _key: "config" }, { $set: { "maintenanceMode": 1 } });
    

    Then restart nodebb.

    2nd

    // 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!" } }) 
    
    mongo -u user -p pass mongo-hostname/nodebb-db-name start-maintenance.js
    

    1st and 2nd way didn't set maintenance mode on for me.

    3rd is to use api, but i don't know how to use it, could someone point me direction (using bash/python).

    I just realized that maintenance mode returns 503 page, so:

    4th way would be returning 503 page from nginx directly, this is the easiest one. But it requires to write some custom error page.

    1 Reply Last reply
    0
  • M Offline
    M Offline
    MoJo
    wrote on last edited by
    #2

    I created read only user in mongodb, replaced user with read only user in config.json. Then added in nginx location block:

    sub_filter </head> '</head><h2 style="text-align:center">Forum in readonly mode.</h2>';
    

    So now users can browse forum but can't change it (database). And users can read maintenance warning.

    But still i want to know how to set maintenance by api 3rd step, so if soemone have time and knowledge please post it here.

    1 Reply Last reply
    0
  • M Offline
    M Offline
    MoJo
    wrote on last edited by
    #3

    Nope just checked, user need to have write permissions to the database otherwise nodebb throws "Internal Error".

    1 Reply Last reply
    0
  • barisB Offline
    barisB Offline
    <baris> NodeBB
    wrote on last edited by
    #4

    Your first option should work setting maintenanceMode to 1 and restarting nodebb should show the maintenance page to regular users.

    M 1 Reply Last reply
    0
  • M Offline
    M Offline
    MoJo
    replied to <baris> on last edited by
    #5

    @baris i will try again later, but when i was testing before nothing happened.

    1 Reply Last reply
    0
  • M Offline
    M Offline
    MoJo
    wrote on last edited by
    #6

    I also tried db.fsyncLock() / db.fsyncUnlock() on mongo db, to force db to read-only, nodebb show no error but was waiting (loading page).

    1 Reply Last reply
    0
  • M Offline
    M Offline
    MoJo
    wrote on last edited by MoJo
    #7

    Weird,

    > use nodebb
    switched to db nodebb
    > db.objects.update({ _key: "config" }, { $set: { "maintenanceMode": 1 } });
    WriteResult({ "nMatched" : 1, "nUpserted" : 0, "nModified" : 1 })
    

    NodeBB restart.

    It's working, checked APC and the switch is turned on.

    I think i was loged in as administrator before, but i was checking maintenance page in APC and switch was turned off.

    1 Reply Last reply
    0

Copyright © 2023 NodeBB | Contributors
  • Login

  • Don't have an account? Register

  • Login or register to search.
Powered by NodeBB Contributors
  • First post
    Last post
0
  • Home
  • Categories
  • Recent
  • Popular
  • Top
  • Tags
  • Users
  • Groups
  • Documentation
    • Home
    • Read API
    • Write API
    • Plugin Development