Activate maintenance mode via Rails?

Hey there,

i’m not really having a problem here, i’m just curious if anyone knows how to do this.

I’m a bit lazy so i wrote some “zammad update shell script” for my environment (quick & dirty as hell). It’s not fully-automatic by choice so i still have to start it but it’s doing some stuff for me i’d have to do manually otherwise + i’m able to watch the output of the update-procedure and can still see if any errors occur.

The only thing i still have to do in the zammad GUI is activate the maintenance mode:

I already fiddled around in rails and was able to activate the mode via:

be careful i'm just playing around with it

Setting.set('maintenance_mode', true) #false to deactivate obviously

But this really seems to just activate it. It doesn’t seem to logout active users like the button does. While that’s working perfectly fine for all users that aren’t logged in it kinda messes up active sessions (users are only seeing blank pages).

I couldn’t find anything considering that in the docs and i guess i’m not supposed to do it that way but i’m just wondering if there is a way :>.

There’s also the maintenance.rb but that seems to be responsible for sending the broadcast messages not the mode itself. I’m going through the code from time to time but did not yet see the right function. Maybe someone else already stumbled across it?

cheers

This shell script should work:

zammad run rails runner 'if Sessions.sessions.size > 0; delay = 5; Sessions.broadcast({event:"maintenance", data: {type: "message", head: "System Update", message: "The ticket system will be updated in #{delay} minutes (#{delay.minutes.from_now.to_s}). The update will take approximatly 5 minutes. You will be automatically logged out.", reload: false}}, "public"); sleep delay.minutes; end; Setting.set("maintenance_mode", true); Sessions.broadcast({event:"maintenance", data: {type: "mode", on: true}}, "public")'

# do your update

zammad run rails runner 'Setting.set("maintenance_mode", false);Sessions.broadcast({event:"maintenance", data: {type: "mode", on: false}}, "public")'

The first zammad run rails runner command will warn active sessions 5 minutes in advance, will wait these 5 minutes and then activate the maintenance mode and log out all users.

The second zammad run rails runner will disable the maintenance mode and broadcast the new setting to all connected clients.

4 Likes

That’s a very lovely approach!

Neat, thanks a lot!

Gonna try that asap :slight_smile:

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