From 126e3ae636bcbca6be87394479c8b3ef8581534f Mon Sep 17 00:00:00 2001
From: Pavel Semyonov
Date: Tue, 15 Aug 2023 17:50:41 +0700
Subject: [PATCH] Add TT_PRELOAD doc
---
doc/book/admin/instance_config.rst | 44 ++++++++++++++++++++++++++----
1 file changed, 38 insertions(+), 6 deletions(-)
diff --git a/doc/book/admin/instance_config.rst b/doc/book/admin/instance_config.rst
index 5f8945d930..e8d81e0fe6 100644
--- a/doc/book/admin/instance_config.rst
+++ b/doc/book/admin/instance_config.rst
@@ -1,8 +1,7 @@
.. _admin-instance_config:
-================================================================================
Instance configuration
-================================================================================
+======================
For each Tarantool instance, you need two files:
@@ -50,9 +49,8 @@ For each Tarantool instance, you need two files:
.. _admin-instance_file:
---------------------------------------------------------------------------------
Instance file
---------------------------------------------------------------------------------
+-------------
After this short introduction, you may wonder what an instance file is, what it
is for, and how ``tarantoolctl`` uses it. After all, Tarantool is an application
@@ -84,11 +82,45 @@ entire application business logic in it. We, however, do not recommend this,
since it clutters the instance file and leads to unnecessary copy-paste when
you need to run multiple instances of an application.
+.. _admin-tt-preload:
+
+Preloading Lua scripts and modules
+----------------------------------
+
+Tarantool supports loading and running chunks of Lua code before the loading instance file.
+To load or run Lua code immediately upon Tarantool startup, specify the ``TT_PRELOAD``
+environment variable. Its value can be either a path to a Lua script, or a Lua module name.
+
+* Run the Lua script ``script.lua`` from the ``preload/path/`` directory inside
+ the working directory in Tarantool before executing ``main.lua``:
+
+ .. code-block:: bash
+
+ TT_PRELOAD=/preload/path/script.lua tarantool main.lua
+
+* Load the ``preload.module`` into the Tarantool Lua interpreter
+ executing ``main.lua``:
+
+ .. code-block:: bash
+
+ TT_PRELOAD=preload.module tarantool main.lua
+
+ .. warning::
+
+ ``TT_PRELOAD`` values that end with ``.lua`` are considered scripts,
+ so avoid modules names with this ending.
+
+To load several scripts or modules, pass them in a single quoted string separated
+by semicolons:
+
+.. code-block:: bash
+
+ TT_PRELOAD="/preload/path/script.lua;preload.module" tarantool main.lua
+
.. _admin-tarantoolctl_config_file:
---------------------------------------------------------------------------------
tarantoolctl configuration file
---------------------------------------------------------------------------------
+-------------------------------
While instance files contain instance configuration, the ``tarantoolctl``
configuration file contains the configuration that ``tarantoolctl`` uses to