Difference between revisions of "Watchdog"

From Second Life Wiki
Jump to navigation Jump to search
m
Line 10: Line 10:
// You break it, you get to keep both pieces.
// You break it, you get to keep both pieces.
//
//
string watchee = "Test Script";    // Set this to the name of a script in prim inventory to watch
string watchee = "Test";    // Set this to the name of a script in prim inventory to watch
float interval = 10.0; // Number of seconds between watchdog checks. Probably best to keep this above >= 10


default {
default {
     state_entry() {
     state_entry() {
         llSetTimerEvent(10);     // Set this to desired watchdog interval. Probably best to leave quite high.
         llSetTimerEvent(interval);
     }
     }
     timer() {
     timer() {
Line 23: Line 24:
             llRegionSay(DEBUG_CHANNEL, "Watchdog Trip: The script ["+watchee+"] has crashed and has been restarted.");
             llRegionSay(DEBUG_CHANNEL, "Watchdog Trip: The script ["+watchee+"] has crashed and has been restarted.");
             llSleep(1);
             llSleep(1);
             llResetScript();
             llResetScript(); // Reset this script as well as a preventative measure
         }
         }
        llSetTimerEvent(interval);
     }
     }
}
}
Line 36: Line 38:
// You break it, you get to keep both pieces.
// You break it, you get to keep both pieces.
//
//
// Basic LSL Watchdog Script to watch multiple scripts
// 2012-01-17 By Tika Oberueng
// Released to the public domain.
// You break it, you get to keep both pieces.
//
float interval = 10.0; // Number of seconds between watchdog checks. Probably best to keep this above >= 10
default {
    state_entry() {
        llSetTimerEvent(interval);
    }
    timer() {
        integer loop;
        string watchee;
        llSetTimerEvent(0);
        for (loop = llGetInventoryNumber(INVENTORY_SCRIPT) -1; loop > -1; --loop) {
            watchee = llGetInventoryName(INVENTORY_SCRIPT,loop);
            if (!llGetScriptState(watchee)) {
                if (watchee != llGetScriptName()) {
                    llResetOtherScript(watchee);
                    llSetScriptState(watchee, TRUE);
                    llRegionSay(DEBUG_CHANNEL, "Multiple Watchdog Trip: The script ["+watchee+"] has crashed and has been restarted.");
                    llSleep(1);
                    llResetScript(); // Reset this script as well as a preventative measure
                }
            }
        }
        llSetTimerEvent(interval);
    }
}
</lsl>
</lsl>

Revision as of 03:30, 17 January 2012

LSL WATCHDOG

These are some simple scripts that watch other scripts in the same prim and restarts them if they crash.

BASIC LSL WATCHDOG FOR A SINGLE PRIMARY SCRIPT <lsl> // Basic LSL Watchdog Script to watch a single script // 2012-01-17 By Tika Oberueng // Released to the public domain. // You break it, you get to keep both pieces. // string watchee = "Test"; // Set this to the name of a script in prim inventory to watch float interval = 10.0; // Number of seconds between watchdog checks. Probably best to keep this above >= 10

default {

   state_entry() {
       llSetTimerEvent(interval);
   }
   timer() {
       llSetTimerEvent(0);
       if (!llGetScriptState(watchee)) {
           llResetOtherScript(watchee);
           llSetScriptState(watchee, TRUE);
           llRegionSay(DEBUG_CHANNEL, "Watchdog Trip: The script ["+watchee+"] has crashed and has been restarted.");
           llSleep(1);
           llResetScript(); // Reset this script as well as a preventative measure
       }
       llSetTimerEvent(interval);
   }

} </lsl>

BASIC LSL WATCHDOG FOR MULTIPLE SCRIPTS <lsl> // Basic LSL Watchdog Script to watch multiple scripts // 2012-01-17 By Tika Oberueng // Released to the public domain. // You break it, you get to keep both pieces. // // Basic LSL Watchdog Script to watch multiple scripts // 2012-01-17 By Tika Oberueng // Released to the public domain. // You break it, you get to keep both pieces. // float interval = 10.0; // Number of seconds between watchdog checks. Probably best to keep this above >= 10

default {

   state_entry() {
       llSetTimerEvent(interval);
   }
   timer() {
       integer loop;
       string watchee;
       llSetTimerEvent(0);
       for (loop = llGetInventoryNumber(INVENTORY_SCRIPT) -1; loop > -1; --loop) {
           watchee = llGetInventoryName(INVENTORY_SCRIPT,loop);
           if (!llGetScriptState(watchee)) {
               if (watchee != llGetScriptName()) {
                   llResetOtherScript(watchee);
                   llSetScriptState(watchee, TRUE);
                   llRegionSay(DEBUG_CHANNEL, "Multiple Watchdog Trip: The script ["+watchee+"] has crashed and has been restarted.");
                   llSleep(1);
                   llResetScript(); // Reset this script as well as a preventative measure
               }
           }
       }
       llSetTimerEvent(interval);
   }

} </lsl>