ScriptChute™ is a script that is meant to suspend scripts when no avatars are present on the grid. This is beneficial for grids that have to be accessible all the time but do not necessarily have to occupy CPU time. ScriptChute™ is part of the Clockwerk which is a virtual machine meant to run a contained version of OpenSim modified by Wizardry and Steamworks.
If scripts on the grid are meant to perform computations (such as unattended scripts), then ScriptChute™ is not recommended yet in most cases, regions are only used when avatars are present and interacting with the environment.
ScriptChute™ is a PHP script that is designed to run on the command line and can be placed in /etc/cron.minutely
. If the /etc/cron.minutely
directory does not exist, then it can be created:
mkdir /etc/cron.minutely
and then the appropriate line can be added to crontab. For example, for Debian Linux, an entry would look like this:
* * * * * root cd / && run-parts --report /etc/cron.minutely
After that, the script below can be placed in /etc/cron.minutely
and cron
can be made to reload its directories with:
kill -s HUP `pidof cron`
The script requires wasRemoteAdmin.php. The location to wasRemoteAdmin.php
can be changed by editing the line:
require_once('/var/www/lib/wasRemoteAdmin.php');
in the provided script.
#!/usr/bin/php <?php ///////////////////////////////////////////////////////////// // Wizardry and Steamworks (c) grimore.org - 2014, License: MIT // // // // Permission is hereby granted, free of charge, to any // // person obtaining a copy of this software and associated // // documentation files (the "Software"), to deal in the // // Software without restriction, //including without // // limitation the rights to use, copy, modify, merge, // // publish, distribute, sublicense, and/or sell copies of // // the Software, and to permit persons to whom the // // Software is furnished to do so, subject to the // // following conditions: // // // // The above copyright notice and this permission notice // // shall be included in all copies or substantial portions // // of the Software. // // // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF // // ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT // // LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS // // FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO // // EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE // // FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER // // IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING // // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR // // THE USE OR OTHER DEALINGS IN THE SOFTWARE. // ///////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////// // CONFIGfURATION // ///////////////////////////////////////////////////////////// // Hostname or IP of your OpenSim MySQL server. define("MYSQL_HOSTNAME", "localhost"); // Username of the OpenSim MySQL user. define("MYSQL_USERNAME", "opensim"); // Password of the OpenSim MySQL user. define("MYSQL_PASSWORD", "***"); // Name of the OpenSim database on the MySQL server. define("MYSQL_DATABASE", "opensim"); ///////////////////////////////////////////////////////////// // INTERNALS // ///////////////////////////////////////////////////////////// require_once('/var/www/lib/wasRemoteAdmin.php'); if(!defined('STDIN')) { print 'This script is meant to be run on the command line.'."\n"; return 1; } $connection_ok = mysql_connect(MYSQL_HOSTNAME, MYSQL_USERNAME, MYSQL_PASSWORD); if(!$connection_ok) { print 'Could not connect to the OpenSim database. Please edit the script and make sure the credentials are correct.'."\n"; return 1; } $db_selected = mysql_select_db(MYSQL_DATABASE); if(!$db_selected) { print 'Could not select the opensim database. Please edit this script and make sure the credentials are correct.'."\n"; return 1; } $query = 'SELECT RegionName FROM regions'; $result = mysql_query($query); $regions = array(); while($row = mysql_fetch_array($result)) { if(!preg_match('/^http:\/\//', $row[0])) { array_push($regions, $row[0]); } } $agents = 0; $req = new wasRemoteAdmin('http://127.0.0.1:10000', 'opensim'); foreach($regions as $region) { $rep = new SimpleXMLElement($req->admin_get_agents($region, "false")); foreach($rep->params->param->value->struct->member as $member) { if($member->name == "regions") { foreach($member->value->array->data->value->struct->member as $member) { if($member->name == "agents") { $agents += count($member->value->array->data->value); } } } } } if($agents != 0) { $req->admin_console_command("scripts start"); return 0; } $req->admin_console_command("scripts stop"); return 0;