Starting and stopping instances
Place the instance file (for example,
/etc/tarantool/instances.enabled/. This is the default location where
ttsearches for instance files.
$ tt start • Starting an instance [my_app]...
In this case,
tt starts an instance from any
*.lua file it finds in
All the instance files or directories placed in the
specified in tt configuration are called enabled instances.
If there are several enabled instances,
tt start starts a separate Tarantool
instance for each of them.
Learn more about working with multiple Tarantool instances in Multi-instance applications.
To start a specific enabled instance, specify its name in the
tt start argument:
$ tt start my_app • Starting an instance [my_app]...
When starting an instance,
tt uses its configuration file
tt.yaml to set up a tt environment in which the instance runs.
tt configuration file is created automatically in
Learn how to set up a
tt environment in a directory of your choice in
Running Tarantool locally.
After the instance has started and worked for some time, you can find its artifacts
in the directories specified in the
tt configuration. These are the default
/var/log/tarantool/<instance_name>.log– instance logs.
/var/lib/tarantool/<instance_name>/– snapshots and write-ahead logs.
/var/run/tarantool/<instance_name>.control– a control socket. This is a Unix socket with the Lua console attached to it. This file is used to connect to the instance console.
/var/run/tarantool/<instance_name>.pid– a PID file that
ttuses to check the instance status and send control commands.
These commands can be called without an instance name. In this case, they are executed for all enabled instances.
tt provides a set of commands for performing basic operations over instances:
tt check– check the instance file for syntax errors:
$ tt check my_app • Result of check: syntax of file '/etc/tarantool/instances.enabled/my_app.lua' is OK
tt status– check the instance status:
$ tt status my_app INSTANCE STATUS PID my_app NOT RUNNING
tt restart– restart the instance:
$ tt restart my_app -y • The Instance my_app (PID = 729) has been terminated. • Starting an instance [my_app]...
-yoption responds «yes» to the confirmation prompt automatically.
tt stop– stop the instance:
$ tt stop my_app • The Instance my_app (PID = 639) has been terminated.
tt clean– remove instance artifacts: logs, snapshots, and other files.
$ tt clean my_app -f • List of files to delete: • /var/log/tarantool/my_app.log • /var/lib/tarantool/my_app/00000000000000000000.snap • /var/lib/tarantool/my_app/00000000000000000000.xlog
-foption removes the files without confirmation.
Tarantool applications can include multiple instances that run different code.
A typical example is a cluster application that includes router and storage
tt utility enables managing such applications.
With a single
tt call, you can:
- start an application on multiple instances
- check the status of application instances
- connect to a specific instance of an application
- stop a specific instance of an application or all its instances
To create a multi-instance application, prepare its layout
in a directory inside
instances_enabled. The directory name is used as
the application identifier.
This directory should contain the following files:
The default instance file named
init.lua. This file is used for all instances of the application unless there are specific instance files (see below).
The instances configuration file
instances.ymlwith instance names followed by colons:
<instance_name1>: <instance_name2>: ...
Do not use the dot (
.) and dash (
-) characters in the instance names. They are reserved for system use.
(Optional) Specific instances files. These files should have names
<instance_name>is the name specified in
instances.yml. For example, if your application has separate source files for the
storageinstances, place the router code in the
For example, take a
demo application that has three instances:
router. Storage instances share the same code, and
router has its own.
The application directory
instances_enabled must contain the following files:
instances.yml– the instances configuration:
storage1: storage2: router:
init.lua– the code of
router.init.lua– the code of
When the application is working, each instance has associated environment variables
TARANTOOL_APP_NAME. You can use them in the application
code to identify the instance on which the code runs.
To obtain the instance and application names, use the following code:
local inst_name = os.getenv('TARANTOOL_INSTANCE_NAME') local app_name = os.getenv('TARANTOOL_APP_NAME')
Start all three instances of the
$ tt start demo • Starting an instance [demo:router]... • Starting an instance [demo:storage1]... • Starting an instance [demo:storage2]...
Check the status of
$ tt status demo INSTANCE STATUS PID demo:router RUNNING 55 demo:storage1 RUNNING 56 demo:storage2 RUNNING 57
Check the status of a specific instance:
$ tt status demo:router INSTANCE STATUS PID demo:router RUNNING 55
Connect to an instance:
$ tt connect demo:router • Connecting to the instance... • Connected to /var/run/tarantool/demo/router/router.control /var/run/tarantool/demo/router/router.control>
Stop a specific instance:
$ tt stop demo:storage1 • The Instance demo:storage1 (PID = 56) has been terminated.
Stop all running instances of the
$ tt stop demo • The Instance demo:router (PID = 55) has been terminated. • can't "stat" the PID file. Error: "stat /var/run/tarantool/demo/storage1/storage1.pid: no such file or directory" • The Instance demo:storage2 (PID = 57) has been terminated.
The error message indicates that
storage1 is already not running.
Sometimes you may need to run a Tarantool instance locally, for example, for test
tt runs in a local environment if it finds a
file in the current directory or any of its enclosing directories.
To set up a local environment for
- Create a home directory for the environment.
tt initin this directory:
$ tt init • Environment config is written to 'tt.yaml'
This command creates a default
tt configuration file
tt.yaml for a local
environment and the directories for instance files, control sockets, logs, and other
$ ls bin distfiles include instances.enabled modules templates tt.yaml
To run a Tarantool instance in the local environment:
Place the instance file into the
instances.enabled/directory inside the current directory.
$ tt start
After the instance is started, you can find its artifacts in their locations inside the current directory:
- logs in
- snapshots and write-ahead logs in
- control sockets and PID files in
To work with a local environment from a directory outside it, issue
tt calls with
--local argument with the path to this environment as its value:
$ tt --local=/usr/tt/env/ start
При запуске экземпляра с помощью инструментария
systemd указанным ниже способом (имя экземпляра –
$ systemctl start tarantool@my_app $ ps axuf|grep my_app taranto+ 5350 1.3 0.3 1448872 7736 ? Ssl 20:05 0:28 tarantool my_app.lua <running>
This actually calls
tarantoolctl like in case of
tarantoolctl start my_app.
Для включения автоматической загрузки экземпляра
my_app при запуске всей системы используйте команду:
$ systemctl enable tarantool@my_app
To stop a running
my_app instance with
$ systemctl stop tarantool@my_app
To restart a running
my_app instance with
$ systemctl restart tarantool@my_app