Method code for $sys.startup()

[Turn off line numbering]
  1: arg args;
  2: var opt, str, obj, f, ver, firsttime, doinit;
  3: 
  4: set_heartbeat(0);
  5: 
  6: // clean db?
  7: if ("-clean" in args) {
  8:     catch any {
  9:         dblog("** Cleaning Database..");
 10:         (> .clean_database() <);
 11:         dblog("** Done.");
 12:         if (dict_contains(startup, 'time))
 13:             startup = dict_del(startup, 'time);
 14:     } with {
 15:         .log($parse_lib.traceback(traceback()));
 16:     }
 17:     doinit = "-init" in args;
 18: } else {
 19:     doinit = "-init" in args || !dict_contains(startup, 'time);
 20: }
 21: 
 22: // init?
 23: if (doinit) {
 24:     catch any {
 25:         dblog("** Initializing Database..");
 26:         (> .init_database() <);
 27:         dblog("** Done.");
 28:     } with {
 29:         .log($parse_lib.traceback(traceback()));
 30:     }
 31: }
 32: 
 33: // done?
 34: if ("-quit" in args) {
 35:     dblog("** Shutting down.");
 36:     .shutdown();
 37:     return;
 38: }
 39: 
 40: // make core?
 41: if ((opt = find opt in (args) where (opt.match_begin("-makecore=")))) {
 42:     ver = regexp(args[opt], "-MAKECORE=(.*)$")[1];
 43:     dblog("** Calling .make_core(\"" + ver + "\")..");
 44:     .make_core(ver);
 45:     return;
 46: }
 47: 
 48: // Standard startup..
 49: startup = startup.add('time, time());
 50: backup = backup.add('next, time() + backup['interval]);
 51: 
 52: // In case we're recovering from a backup
 53: if (dict_contains(backup, 'started))
 54:     backup = dict_del(backup, 'started);
 55: catch any {
 56:     // get back the heartbeat
 57:     set_heartbeat(startup['heartbeat_interval]);
 58: 
 59:     // Bind functions for security
 60:     for f in (bindings) {
 61:         catch any
 62:             bind_function(@f);
 63:         with
 64:             dblog("** Unable to bind function " + f[1] + "() to " + f[2]);
 65:     }
 66: 
 67:     // tell objects who should know, that we are online
 68:     if (type(args) != 'list)
 69:         args = [];
 70:     for obj in (startup['objects]) {
 71:         .log("Calling " + obj + ".startup()");
 72:         catch any
 73:             (> obj.startup(@args) <);
 74:         with
 75:             .log($parse_lib.traceback(traceback()));
 76:     }
 77: } with {
 78:     .log("** Startup ERROR at " + ctime() + ":");
 79:     .log(toliteral(traceback()));
 80:     .log($parse_lib.traceback(traceback(), -1, ""));
 81: }
 82: 
 83: // $#Edited: 18 Aug 97 10:25 $brandon
 84: // $#Edited: 27 Dec 98 21:07 $brian
 85: // $#Edited: 11 Feb 99 04:19 $brandon
 86: // $#Edited: 19 Jul 99 11:18 $miro

["// Created 26-Mar-1995 as a part of ColdCore, see: @help Credit"]

the Cold Dark