View Full Version : Turn off Forum via Shell Command Line?
BryceW
04-07-2010, 02:21 PM
I currently have a decently large forum with 56,000+ members and 2.1 million posts. This is on dedicated server and I back it up using mysqldump via SSH command line. I want to automate this process via a cron job.
Currently, I turn off the forums in the admin CP, do the mysqldump in shell then turn it back on.
Obviously, the mysqldump is easily scripted but I need a way to turn off the forums with a script, like a ssh command or something. Any suggestions, ideas?
If I dont turn the forums off, the update takes twice as long, the forums lag out and my members just sit there hitting refresh :)
Marco van Herwaarden
04-07-2010, 02:34 PM
You will need to run 2 queries:
To turn your forums off
UPDATE datastore SET data=REPLACE(data,'s:8:"bbactive";i:1;','s:8:"bbactive";i:0;') WHERE title='options';
UPDATE setting SET value=0 WHERE varname='bbactive';
To turn your forums on
UPDATE datastore SET data=REPLACE(data,'s:8:"bbactive";i:0;','s:8:"bbactive";i:1;') WHERE title='options';
UPDATE setting SET value=1 WHERE varname='bbactive';
kmike
04-07-2010, 05:31 PM
Note that the queries above will not work when one of the datastore caching modules (XCache, APC, eAccelerator, memcached) is enabled. The script must be more sophisticated - it should be able to flush memory cache for the appropriate datastore caching module.
Andreas
04-08-2010, 03:27 PM
Here is a more sophisticated script:
<?php
@ini_set('display_errors', 0);
@error_reporting(0);
define('VB_AREA', 'Maintenance');
define('SKIP_SESSIONCREATE', 1);
define('SKIP_LOCATIONUPDATE', 1);
define('SKIP_DEFAULTDATASTORE', 1);
define('DISABLE_HOOKS', 1); // You might want to comment this out if you need plugins in this script
define('NOCOOKIES', 1);
define('CWD', '/path/to/vbulletin');
require(CWD . '/includes/init.php');
require(DIR . '/includes/adminfunctions.php');
$db->query_write("UPDATE " . TABLE_PREFIX . "setting SET value = " . (($_SERVER['argv'][1] == 1) ? 1 : 0) . " WHERE varname = 'bbactive'");
build_options();
?>
I've turned off all error reporting as vB 4 seems to assume that every request comes through a webserver :rolleyes:
(Adding yet-another bug report now ...)
Also setting the board offline does not completely kill queries so you might still run into table locking issues.
BryceW
04-18-2010, 11:21 AM
Sorry its taken me so long to get back to you. But thanks alot all. I appreciate it. Hopefully thread will help others as well.
zagman76
09-03-2012, 10:19 PM
-bump-
Sorry to bump such an old thread, but I was wondering how one could manipulate this to do the reverse - turn the forum back ON via a script.
NickCat
09-17-2012, 07:55 PM
-bump-
Sorry to bump such an old thread, but I was wondering how one could manipulate this to do the reverse - turn the forum back ON via a script.
This script does already allow for that... you just have to pass a variable it to the script.
If calling from a shell (ie straight on the server using command line) you would call it like this:
> vbscript.php (will close the site)
> vbscript.php 1 (will open the site)
> vbscript.php 0 (will also close site)
I believe you can also use these through a direct call to the file from a web browser. I'm not sure the exact formatting, but it would be similar to "yourservername.com/vbscript.php?1"
Hope that helps.
Also from a security standpoint I wound't suggest allowing something like this to be call from a web browser and only use it on the command line.
I'm integrating this into a script I use to backup my site, but we are so large I need to have the site offline in order to make the 18GB backup.
PHP Page for reference on usage: http://www.php.net/manual/en/reserved.variables.server.php
argv specific section:
'argv'
Array of arguments passed to the script. When the script is run on the command line, this gives C-style access to the command line parameters. When called via the GET method, this will contain the query string.
vBulletin® v3.8.12 by vBS, Copyright ©2000-2025, vBulletin Solutions Inc.