My latest commits added two new command line arguments to the Stunt server, and added support for "start scripts", which are scripts passed to the server from outside the server via the new command line arguments. Start scripts are useful for automating environment specific startup functionality, for stripping a larger database down to a redistributable core, and for bootstrapping an application database from Minimal.db (or Stunt.db). Here are a few examples:
./moo -c '$enable_debugging();' FooBar.db FooBar.db.new 7777
./moo -f corify.moo FooBar.db FooBar.db.new 7777
The "-c" argument sends the contents of the subsequent argument to the server. The "-f" argument loads the named file and sends the contents of that file to the server. In both cases, the contents comprise the so-called "start script". Both the "-c" and "-f" arguments can be specified at the same time, albeit only one time each. Neither argument can be used if the "-e" argument is specified.
When starting, the server looks for the verb $do_start_script()
and, if it exists, it invokes the verb and passes the start script to the verb in the args
built-in variable. This invocation occurs possibly multiple times, once for each script argument on the command line. The exact interpretation of the start script is up to the $do_start_script()
verb. A reasonable implementation might treat the start script as MOOcode and simply eval()
it.
Start script processing happens very early in the server startup sequence, before starting any suspended tasks and before accepting any connections. Of particular note, unless the script suspends or forks, it will complete before the server invokes $server_started()
.