Skip to content

Commit b8023b0

Browse files
committed
Update tt configuration and env description to 2.0 (#4033)
Resolves #3997 Resolves #3998 Resolves #3836
1 parent 35856dd commit b8023b0

File tree

4 files changed

+171
-87
lines changed

4 files changed

+171
-87
lines changed

doc/book/admin/logs.rst

Lines changed: 30 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ Each Tarantool instance logs important events to its own log file ``<instance-na
77
For instances started with :ref:`tt <tt-cli>`, the log location is defined by
88
the ``log_dir`` parameter in the :ref:`tt configuration <tt-config>`.
99
By default, it's ``/var/log/tarantool`` in the ``tt`` :ref:`system mode <tt-config_modes>`,
10-
and the ``var/log/`` subdirectory of the ``tt`` working directory in the :ref:`local mode <tt-config_modes>`.
10+
and the ``var/log`` subdirectory of the ``tt`` working directory in the :ref:`local mode <tt-config_modes>`.
1111
In the specified location, ``tt`` creates separate directories for each instance's logs.
1212

1313
To check how logging works, write something to the log using the :ref:`log <log-module>` module:
@@ -41,31 +41,35 @@ Then check the logs:
4141
Log rotation
4242
------------
4343

44-
When :ref:`logging to a file <cfg_logging-log>`, the system administrator must ensure logs are
45-
rotated timely and do not take up all the available disk space.
46-
To prevent log files from growing infinitely, ``tt`` automatically rotates instance
47-
logs. The following ``tt`` configuration parameters define the log rotation:
48-
``log_maxsize`` (in megabytes) and ``log_maxage`` (in days). When any of these
49-
limits is reached, the log is rotated.
50-
Additionally, there is the ``log_maxbackups`` parameter (the number of stored log
51-
files for an instance), which enables automatic removal of old log files.
52-
53-
.. code-block:: yaml
54-
55-
# tt.yaml
56-
tt:
57-
app:
58-
log_maxsize: 100
59-
log_maxage: 3
60-
log_maxbackups: 50
61-
# ...
62-
63-
There is also the :ref:`tt logrotate <tt-logrotate>` command that performs log
64-
rotation on demand.
65-
66-
.. code-block:: bash
67-
68-
tt logrotate my_app
44+
When :ref:`logging to a file <cfg_logging-log>`, the system administrator must ensure
45+
logs are rotated timely and do not take up all the available disk space.
46+
The recommended way to prevent log files from growing infinitely is using an external
47+
log rotation program, for example, ``logrotate``, which is pre-installed on most
48+
mainstream Linux distributions.
49+
50+
A Tarantool log rotation configuration for ``logrotate`` can look like this:
51+
52+
.. code-block:: text
53+
54+
/var/log/tarantool/*.log {
55+
daily
56+
size 512k
57+
missingok
58+
rotate 10
59+
compress
60+
delaycompress
61+
create 0640 tarantool adm
62+
postrotate
63+
tt -c <tt_config_file> logrotate
64+
endscript
65+
}
66+
67+
In this configuration, :ref:`tt logrotate <tt-logrotate>` is called after each log
68+
rotation to reopen the instance log files after they are moved by the ``logrotate``
69+
program.
70+
71+
There is also the built-in function :ref:`log.rotate() <log-rotate>`, which you
72+
can call on an instance to reopen its log file after rotation.
6973

7074
To learn about log rotation in the deprecated ``tarantoolctl`` utility,
7175
check its :ref:`documentation <tarantoolctl-log-rotation>`.

doc/reference/tooling/tt_cli/configuration.rst

Lines changed: 124 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -14,36 +14,63 @@ execution is its configuration file.
1414
By default, the configuration file is called ``tt.yaml``. The location
1515
where ``tt`` searches for it depends on the :ref:`launch mode <tt-config_modes>`.
1616
You can also pass the configuration file explicitly in the ``--cfg``
17-
:ref:`option <tt-global-options>`.
17+
:ref:`global option <tt-global-options>`.
1818

19-
The ``tt`` configuration file is a YAML file with the following content:
19+
The ``tt`` configuration file is a YAML file with the following structure:
2020

2121
.. code-block:: yaml
2222
23-
tt:
24-
modules:
25-
directory: path/to/modules/dir
26-
app:
27-
instances_enabled: path/to/applications
28-
run_dir: path/to/run_dir
29-
log_dir: path/to/log_dir
30-
bin_dir: path/to/bin_dir
31-
inc_dir: path/to/inc_dir
32-
wal_dir: path/to/wal_dir
33-
vinyl_dir: path/to/vinyl_dir
34-
memtx_dir: path/to/memtx_dir
35-
log_maxsize: num (MB)
36-
log_maxage: num (days)
37-
log_maxbackups: num
38-
restart_on_failure: bool
39-
repo:
40-
rocks: path/to/rocks
41-
distfiles: path/to/install
42-
ee:
43-
credential_path: path/to/file
44-
templates:
45-
- path: path/to/app/templates1
46-
- path: path/to/app/templates2
23+
env:
24+
instances_enabled: path/to/available/applications
25+
bin_dir: path/to/bin_dir
26+
inc_dir: path/to/inc_dir
27+
restart_on_failure: bool
28+
tarantoolctl_layout: bool
29+
modules:
30+
directory: path/to/modules/dir
31+
app:
32+
run_dir: path/to/run_dir
33+
log_dir: path/to/log_dir
34+
wal_dir: path/to/wal_dir
35+
vinyl_dir: path/to/vinyl_dir
36+
memtx_dir: path/to/memtx_dir
37+
repo:
38+
rocks: path/to/rocks
39+
distfiles: path/to/install
40+
ee:
41+
credential_path: path/to/file
42+
templates:
43+
- path: path/to/app/templates1
44+
- path: path/to/app/templates2
45+
46+
.. note::
47+
48+
The ``tt`` configuration format and application layout have been changed in version
49+
2.0. Learn how to upgrade from earlier versions in :ref:`tt-config_migrating-from-1`.
50+
51+
.. _tt-config_file_env:
52+
53+
env section
54+
~~~~~~~~~~~
55+
56+
.. note::
57+
58+
The paths specified in ``env.*`` parameters are relative to the current ``tt``
59+
environment's root.
60+
61+
* ``instances_enabled`` -- the directory where :ref:`instances <admin-instance_file>`
62+
are stored. Default: ``instances.enabled``.
63+
* ``bin_dir`` -- the directory where binary files are stored. Default: ``bin``.
64+
* ``inc_dir`` -- the base directory for storing header files. They will
65+
be placed in the ``include`` subdirectory inside the specified directory.
66+
Default: ``include``.
67+
* ``restart_on_failure`` -- restart the instance on failure: ``true`` or ``false``.
68+
Default: ``false``.
69+
* ``tarantoolctl_layout`` -- use a layout compatible with the deprecated ``tarantoolctl``
70+
utility for artifact files: control sockets, ``.pid`` files, log files.
71+
Default: ``false``.
72+
73+
.. _tt-config_file_modules:
4774

4875
modules section
4976
~~~~~~~~~~~~~~~
@@ -56,44 +83,25 @@ modules section
5683
app section
5784
~~~~~~~~~~~
5885

59-
* ``instances_enabled`` -- the directory where :ref:`instances <admin-instance_file>`
60-
are stored.
86+
.. note::
87+
88+
The paths specified in ``app.*_dir`` parameters are relative to the application
89+
location inside the ``instances.enabled`` directory specified in the ``env``
90+
configuration section. For example, the default location of the ``myapp``
91+
application's logs is ``instances.enabled/myapp/var/log``.
92+
Inside this location, ``tt`` creates separate directories for each application
93+
instance that runs in the current environment.
94+
6195
* ``run_dir``-- the directory for instance runtime artifacts, such as console
6296
sockets or PID files. Default: ``var/run``.
6397
* ``log_dir`` -- the directory where log files are stored. Default: ``var/log``.
64-
* ``bin_dir`` -- the directory where binary files are stored. Default: ``bin``.
65-
* ``inc_dir`` -- the base directory for storing header files. They will
66-
be placed in the ``include`` subdirectory inside the specified directory.
67-
Default: ``include``.
6898
* ``wal_dir`` -- the directory where write-ahead log (``.xlog``) files are stored.
6999
Default: ``var/lib``.
70100
* ``memtx_dir`` -- the directory where memtx stores snapshot (``.snap``) files.
71101
Default: ``var/lib``.
72102
* ``vinyl_dir`` -- the directory where vinyl files or subdirectories are stored.
73103
Default: ``var/lib``.
74104

75-
.. note::
76-
77-
In all directories specified in ``*_dir`` parameters, ``tt`` creates a
78-
directory for each application and instance directories inside it.
79-
Names of these directories match the names of applications and instances.
80-
81-
* ``log_maxsize`` -- the maximum size of the log file before it gets rotated,
82-
in megabytes. Default: 100.
83-
* ``log_maxage`` -- the maximum age of log files in days. The age of a log
84-
file is defined by the timestamp encoded in its name. Default: not defined
85-
(log files aren't deleted based on their age).
86-
87-
.. note::
88-
89-
A day is defined as exactly 24 hours. It may not exactly correspond to
90-
calendar days due to daylight savings, leap seconds, and other time adjustments.
91-
92-
* ``log_maxbackups`` -- the maximum number of stored log files.
93-
Default: not defined (log files aren't deleted based on their count).
94-
* ``restart_on_failure`` -- restart the instance on failure: ``true`` or ``false``.
95-
Default: ``false``.
96-
97105
.. _tt-config_file_repo:
98106

99107
repo section
@@ -131,7 +139,7 @@ configuration file. There are three launch modes:
131139
Default launch
132140
~~~~~~~~~~~~~~
133141

134-
**Argument**: none
142+
**Global option**: none
135143

136144
**Configuration file**: searched from the current directory to the root.
137145
Taken from ``/etc/tarantool`` if the file is not found.
@@ -143,7 +151,7 @@ Taken from ``/etc/tarantool`` if the file is not found.
143151
System launch
144152
~~~~~~~~~~~~~
145153

146-
**Argument**: ``--system`` or ``-S``
154+
**Global option**: ``--system`` or ``-S``
147155

148156
**Configuration file**: Taken from ``/etc/tarantool``.
149157

@@ -154,10 +162,68 @@ System launch
154162
Local launch
155163
~~~~~~~~~~~~
156164

157-
**Argument**: ``--local=DIRECTORY`` or ``-L=DIRECTORY``
165+
**Global option**: ``--local=DIRECTORY`` or ``-L=DIRECTORY``
158166

159167
**Configuration file**: Searched from the specified directory to the root.
160168
Taken from ``/etc/tarantool`` if the file is not found.
161169

162170
**Working directory**: The specified directory. If ``tarantool`` or ``tt``
163-
executable files are found in the working directory, they will be used.
171+
executable files are found in the working directory, they will be used.
172+
173+
.. _tt-config_migrating-from-1:
174+
175+
Migrating from tt 1.* to 2.0 or later
176+
-------------------------------------
177+
178+
The `tt` configuration and application layout were changed in version 2.0.
179+
If you are using ``tt`` 1.*, complete the following steps to migrate to ``tt`` 2.0 or later:
180+
181+
#. **Update the tt configuration file**.
182+
In tt 2.0, the following changes were made to the configuration file:
183+
184+
* The root section ``tt`` was removed. Its child sections -- ``app``, ``repo``,
185+
``modules``, and other -- have been moved to the top level.
186+
* Environment configuration parameters were moved from the ``app`` section
187+
to the new section ``env``. These parameters are ``instances.enabled``,
188+
``bin_dir``, ``inc_dir``, and ``restart_on_failure``.
189+
* The paths in the ``app`` section are now relative to the app directory in ``instances.enabled``
190+
instead of the environment root.
191+
192+
You can use :ref:`tt init <tt-init>` to generate a configuration file with
193+
the new structure and default parameter values.
194+
195+
#. **Move application artifacts**.
196+
With ``tt`` 1.*, application artifacts (logs, snapshots, pid, and other files)
197+
were created in the ``var`` directory inside the *environment root*. Starting from
198+
``tt`` 2.0, these artifacts are created in the ``var`` directory inside the
199+
*application directory*, which is ``instances.enabled/<app-name>``. This is
200+
how an application directory looks:
201+
202+
.. code-block:: text
203+
204+
instances.enabled/app/
205+
├── init.lua
206+
├── instances.yml
207+
└── var
208+
├── lib
209+
│ ├── instance1
210+
│ └── instance2
211+
├── log
212+
│ ├── instance1
213+
│ └── instance2
214+
└── run
215+
├── instance1
216+
└── instance2
217+
218+
To continue using existing application artifacts after migration from ``tt`` 1.*:
219+
220+
#. Create the ``var`` directory inside the application directory.
221+
#. Create the ``lib``, ``log``, and ``run`` directories inside ``var``.
222+
#. Move directories with instance artifacts from the old ``var`` directory
223+
to the new ``var`` directories in applications' directories.
224+
225+
#. **Move the files accessed from the application code**.
226+
The working directory of instance processes was changed from the ``tt`` working
227+
directory to the application directory inside ``instances.enabled``. If the
228+
application accesses files using relative paths, move the files accordingly
229+
or adjust the application code.

doc/reference/tooling/tt_cli/global_options.rst

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,18 @@
33
Global options
44
==============
55

6+
.. important::
7+
8+
Global options of ``tt`` must be passed before its commands and other options.
9+
For example:
10+
11+
.. code-block:: console
12+
13+
$ tt --cfg tt-conf.yaml start app
14+
615
``tt`` has the following global options:
716

8-
.. option:: -c=FILE, --cfg=FILE
17+
.. option:: -c=FILE, --cfg=FILE,
918

1019
Path to the :ref:`configuration file <tt-config_file>`.
1120

doc/reference/tooling/tt_cli/logrotate.rst

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,18 @@ Rotating instance logs
77
88
$ tt logrotate {INSTANCE | APPLICATION[:APP_INSTANCE]}
99
10-
``tt logrotate`` rotates logs of a specified Tarantool instance.
10+
``tt logrotate`` rotates logs of a Tarantool application or specific instances,
11+
and the ``tt`` log. For example, you need to call this function to continue logging
12+
after a log rotation program renames or moves instances' logs.
1113
Learn more about :ref:`rotating logs <admin-logs>`.
1214

15+
Calling ``tt logrotate`` on an application has the same effect as executing the
16+
built-in :ref:`log.rotate() <log-rotate>` function on all its instances.
17+
1318
Examples
1419
--------
1520

16-
Rotate logs of the ``app`` instance:
21+
Rotate logs of the ``app`` application's instances:
1722

1823
.. code-block:: console
1924

0 commit comments

Comments
 (0)