18

Instead of putting my site in "maintenance mode" I would like to put it in a complete "readonly mode". There is a module for that, however, it only prevents "node add and edit". I would like to prevent all user activity including login and registration to basically have the site get served from the (varnish) cache. As as side benefit I would use this type of "read only mode" if the site gets flooded with requests.

My question: how can I logout all active users? The login and registrations I can then redirect with a hook.

4 Answers 4

16

As far as I know you can empty the sessions table and all users will be logged out. There may be an issue though, depending on the modules that you have installed. For example, modules that implement hook_user_logout() will never get their actions fired, which could be an issue. Check to make sure none of your installed modules is implementing this hook.

2
  • 4
    As @F1234k said, deleting session table will never get hook_user_logout() to be triggered. But, you could just trigger it your self. Select all the uid's from the sessions table and than execute ` module_invoke_all('user_logout', $user);` for each of them. You could though filter by the ones that have their session opened for more than 1h (sessions in Drupal can stay enabled limitless). Feb 6, 2012 at 10:29
  • 1
    thanks. I'll need to fire the logout hooks, otherwise I get a WSOD for users that are logged in with the "persistent login" module.
    – uwe
    Feb 6, 2012 at 16:00
16

You can empty the sessions table using drush

drush sqlq "TRUNCATE sessions"

or if you have set prefixes for table names:

drush sqlq --db-prefix "TRUNCATE {sessions}"
2

Use Force Logout Module ..

Features

  • Settings form where you can enable and disable (Force logout).
  • Permission so you can exclude some user roles if you want to exclude administrator for example.
1

You can force to logout all the users via an update hook:

/**
 * Force to logout all the users.
 */
function mymodule_update_7001() {
  db_truncate('sessions')->execute();
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.