Skip to content

Commit b0194f5

Browse files
committed
Split the Application server section
Move the content to different chapters, save some content for the Concepts section. * Tutorial on pokemons (Creating application): How-to * Developing with IDE, Cookbook recipes: How-to * Module installation and reload: Admin guide * Module contribution: Dev guide * Create a Tooling section in the Reference chapter * Move console tools to the Tooling section * LuaJIT tooling: Reference/Tooling * Concepts: early draft
1 parent e56bbd4 commit b0194f5

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

76 files changed

+604
-342
lines changed

doc/book/admin/index.rst

+1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ This chapter includes the following sections:
2929

3030
instance_config
3131
start_stop_instance
32+
modules
3233
logs
3334
security
3435
access_control

doc/book/admin/modules.rst

+213
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,213 @@
1+
.. _admin-managing_tarantool_modules:
2+
3+
Managing modules
4+
================
5+
6+
This section covers the installation and reloading of Tarantool modules.
7+
To learn about writing your own module and contributing it,
8+
check the :ref:`Contributing a module <app_server-contributing_module>` section.
9+
10+
.. _app_server-installing_module:
11+
12+
Installing a module
13+
-------------------
14+
15+
Modules in Lua and C that come from Tarantool developers and community
16+
contributors are available in the following locations:
17+
18+
* Tarantool modules repository (see :ref:`below <app_server-installing_module_luarocks>`)
19+
* Tarantool deb/rpm repositories (see :ref:`below <app_server-installing_module_debrpm>`)
20+
21+
.. _app_server-installing_module_luarocks:
22+
23+
Installing a module from a repository
24+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
25+
26+
See
27+
`README in tarantool/rocks repository <https://github.com/tarantool/rocks#managing-modules-with-tarantool-174>`_
28+
for detailed instructions.
29+
30+
.. _app_server-installing_module_debrpm:
31+
32+
Installing a module from deb/rpm
33+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
34+
35+
Follow these steps:
36+
37+
1. Install Tarantool as recommended on the
38+
`download page <http://tarantool.org/download.html>`_.
39+
40+
2. Install the module you need. Look up the module's name on
41+
`Tarantool rocks page <http://tarantool.org/rocks.html>`_ and put the prefix
42+
"tarantool-" before the module name to avoid ambiguity:
43+
44+
.. code-block:: console
45+
46+
$ # for Ubuntu/Debian:
47+
$ sudo apt-get install tarantool-<module-name>
48+
49+
$ # for RHEL/CentOS/Amazon:
50+
$ sudo yum install tarantool-<module-name>
51+
52+
For example, to install the module
53+
`shard <http://github.com/tarantool/shard>`_ on Ubuntu, say:
54+
55+
.. code-block:: console
56+
57+
$ sudo apt-get install tarantool-shard
58+
59+
Once these steps are complete, you can:
60+
61+
* load any module with
62+
63+
.. code-block:: tarantoolsession
64+
65+
tarantool> name = require('module-name')
66+
67+
for example:
68+
69+
.. code-block:: tarantoolsession
70+
71+
tarantool> shard = require('shard')
72+
73+
* search locally for installed modules using ``package.path`` (Lua) or
74+
``package.cpath`` (C):
75+
76+
.. code-block:: tarantoolsession
77+
78+
tarantool> package.path
79+
---
80+
- ./?.lua;./?/init.lua; /usr/local/share/tarantool/?.lua;/usr/local/share/
81+
tarantool/?/init.lua;/usr/share/tarantool/?.lua;/usr/share/tarantool/?/ini
82+
t.lua;/usr/local/share/lua/5.1/?.lua;/usr/local/share/lua/5.1/?/init.lua;/
83+
usr/share/lua/5.1/?.lua;/usr/share/lua/5.1/?/init.lua;
84+
...
85+
86+
tarantool> package.cpath
87+
---
88+
- ./?.so;/usr/local/lib/x86_64-linux-gnu/tarantool/?.so;/usr/lib/x86_64-li
89+
nux-gnu/tarantool/?.so;/usr/local/lib/tarantool/?.so;/usr/local/lib/x86_64
90+
-linux-gnu/lua/5.1/?.so;/usr/lib/x86_64-linux-gnu/lua/5.1/?.so;/usr/local/
91+
lib/lua/5.1/?.so;
92+
...
93+
94+
.. NOTE::
95+
96+
Question-marks stand for the module name that was specified earlier when
97+
saying ``require('module-name')``.
98+
99+
.. _app_server-reloading_module:
100+
101+
Reloading a module
102+
------------------
103+
104+
You can reload any Tarantool application or module with zero downtime.
105+
106+
.. _app_server-reloading_lua_module:
107+
108+
Reloading a module in Lua
109+
~~~~~~~~~~~~~~~~~~~~~~~~~
110+
111+
Here's an example that illustrates the most typical case -- "update and reload".
112+
113+
.. NOTE::
114+
115+
In this example, we use recommended :ref:`administration practices <admin>`
116+
based on :ref:`instance files <admin-instance_file>` and
117+
:ref:`tarantoolctl <tarantoolctl>` utility.
118+
119+
1. Update the application file.
120+
121+
For example, a module in ``/usr/share/tarantool/app.lua``:
122+
123+
.. code-block:: lua
124+
125+
local function start()
126+
-- initial version
127+
box.once("myapp:v1.0", function()
128+
box.schema.space.create("somedata")
129+
box.space.somedata:create_index("primary")
130+
...
131+
end)
132+
133+
-- migration code from 1.0 to 1.1
134+
box.once("myapp:v1.1", function()
135+
box.space.somedata.index.primary:alter(...)
136+
...
137+
end)
138+
139+
-- migration code from 1.1 to 1.2
140+
box.once("myapp:v1.2", function()
141+
box.space.somedata.index.primary:alter(...)
142+
box.space.somedata:insert(...)
143+
...
144+
end)
145+
end
146+
147+
-- start some background fibers if you need
148+
149+
local function stop()
150+
-- stop all background fibers and clean up resources
151+
end
152+
153+
local function api_for_call(xxx)
154+
-- do some business
155+
end
156+
157+
return {
158+
start = start,
159+
stop = stop,
160+
api_for_call = api_for_call
161+
}
162+
163+
2. Update the :ref:`instance file <admin-instance_file>`.
164+
165+
For example, ``/etc/tarantool/instances.enabled/my_app.lua``:
166+
167+
.. code-block:: lua
168+
169+
#!/usr/bin/env tarantool
170+
--
171+
-- hot code reload example
172+
--
173+
174+
box.cfg({listen = 3302})
175+
176+
-- ATTENTION: unload it all properly!
177+
local app = package.loaded['app']
178+
if app ~= nil then
179+
-- stop the old application version
180+
app.stop()
181+
-- unload the application
182+
package.loaded['app'] = nil
183+
-- unload all dependencies
184+
package.loaded['somedep'] = nil
185+
end
186+
187+
-- load the application
188+
log.info('require app')
189+
app = require('app')
190+
191+
-- start the application
192+
app.start({some app options controlled by sysadmins})
193+
194+
The important thing here is to properly unload the application and its
195+
dependencies.
196+
197+
3. Manually reload the application file.
198+
199+
For example, using ``tarantoolctl``:
200+
201+
.. code-block:: console
202+
203+
$ tarantoolctl eval my_app /etc/tarantool/instances.enabled/my_app.lua
204+
205+
.. _app_server-reloading_c_module:
206+
207+
Reloading a module in C
208+
~~~~~~~~~~~~~~~~~~~~~~~
209+
210+
After you compiled a new version of a C module (``*.so`` shared library), call
211+
:doc:`box.schema.func.reload('module-name') </reference/reference_lua/box_schema/func_reload>`
212+
from your Lua script to reload the module.
213+

doc/book/app_server/index.rst

-27
This file was deleted.

doc/book/app_server/installing_module.rst

-91
This file was deleted.

0 commit comments

Comments
 (0)