From 6712ab9a44f27b5f0f0899c9aad8b239090643dd Mon Sep 17 00:00:00 2001
From: Alexander Turenko <alexander.turenko@tarantool.org>
Date: Tue, 22 Aug 2023 03:37:43 +0300
Subject: [PATCH] config: change default paths to var/<...>

The new default directory layout is the following.

```
+ var/
  + lib/
    + instance-001/
      - *.xlog
      - *.snap
      - *.vylog
  + log/
    + instance-001/
      - tarantool.log
  + run/
    + instance-001/
      - tarantool.control
      - tarantool.pid
```

Our guess is that it should be convenient for development environments,
when the application consists of several instances. The idea is borrowed
from the `cartridge-cli` and `tt` tools.

We plan to synchronize these defaults with the `tt` tool, to simplify
cases, when pure tarantool (without `tt`) should be run in the
directories layout created by `tt`. It should simplify debugging using
`gdb`, `strace` and other tools.

Also, it should reduce possible confusion for users of `cartridge-cli`
and `tt`.

Part of #8862

NO_DOC=https://github.com/tarantool/doc/issues/3544 already points to
       the actual instance config schema
---
 changelogs/unreleased/config-change-default-paths.md |  4 ++++
 src/box/lua/config/instance_config.lua               | 12 ++++++------
 test/config-luatest/appliers_test.lua                |  4 ++--
 test/config-luatest/cli_test.lua                     |  2 +-
 test/config-luatest/cluster_config_schema_test.lua   | 12 ++++++------
 test/config-luatest/instance_config_schema_test.lua  | 12 ++++++------
 6 files changed, 25 insertions(+), 21 deletions(-)
 create mode 100644 changelogs/unreleased/config-change-default-paths.md

diff --git a/changelogs/unreleased/config-change-default-paths.md b/changelogs/unreleased/config-change-default-paths.md
new file mode 100644
index 0000000000..c051acaae8
--- /dev/null
+++ b/changelogs/unreleased/config-change-default-paths.md
@@ -0,0 +1,4 @@
+## feature/config
+
+* The default directory and file paths are changed to `var/run/<...>`,
+  `var/log/<...>`, `var/lib/<...>` and so on (gh-8862).
diff --git a/src/box/lua/config/instance_config.lua b/src/box/lua/config/instance_config.lua
index faccae5c67..7d2a86ded0 100644
--- a/src/box/lua/config/instance_config.lua
+++ b/src/box/lua/config/instance_config.lua
@@ -368,7 +368,7 @@ return schema.new('instance_config', schema.record({
             box_cfg = 'pid_file',
             box_cfg_nondynamic = true,
             mk_parent_dir = true,
-            default = '{{ instance_name }}.pid',
+            default = 'var/run/{{ instance_name }}/tarantool.pid',
         }),
     }),
     console = schema.record({
@@ -382,7 +382,7 @@ return schema.new('instance_config', schema.record({
             -- because otherwise the directory would be created
             -- unconditionally. Instead, mkdir applier creates it
             -- if console.enabled is true.
-            default = '{{ instance_name }}.control',
+            default = 'var/run/{{ instance_name }}/tarantool.control',
         }),
     }),
     fiber = schema.record({
@@ -440,7 +440,7 @@ return schema.new('instance_config', schema.record({
             -- because otherwise the directory would be created
             -- unconditionally. Instead, mkdir applier creates it
             -- if log.to is 'file'.
-            default = '{{ instance_name }}.log',
+            default = 'var/log/{{ instance_name }}/tarantool.log',
         }),
         pipe = schema.scalar({
             type = 'string',
@@ -767,7 +767,7 @@ return schema.new('instance_config', schema.record({
             box_cfg = 'vinyl_dir',
             box_cfg_nondynamic = true,
             mkdir = true,
-            default = '{{ instance_name }}',
+            default = 'var/lib/{{ instance_name }}',
         }),
         max_tuple_size = schema.scalar({
             type = 'integer',
@@ -827,7 +827,7 @@ return schema.new('instance_config', schema.record({
             box_cfg = 'wal_dir',
             box_cfg_nondynamic = true,
             mkdir = true,
-            default = '{{ instance_name }}',
+            default = 'var/lib/{{ instance_name }}',
         }),
         mode = schema.enum({
             'none',
@@ -908,7 +908,7 @@ return schema.new('instance_config', schema.record({
             box_cfg = 'memtx_dir',
             box_cfg_nondynamic = true,
             mkdir = true,
-            default = '{{ instance_name }}',
+            default = 'var/lib/{{ instance_name }}',
         }),
         by = schema.record({
             interval = schema.scalar({
diff --git a/test/config-luatest/appliers_test.lua b/test/config-luatest/appliers_test.lua
index 4298ee704e..7fd534f8c2 100644
--- a/test/config-luatest/appliers_test.lua
+++ b/test/config-luatest/appliers_test.lua
@@ -76,8 +76,8 @@ g.test_applier_mkdir = function()
     local opts = {nojson = true, stderr = false}
     local res = justrun.tarantool(dir, env, {'main.lua'}, opts)
     t.assert_equals(res.exit_code, 0)
-    t.assert_equals(res.stdout, 'instance-001')
-    t.assert(fio.path.is_dir(fio.pathjoin(dir, 'instance-001')))
+    t.assert_equals(res.stdout, 'var/lib/instance-001')
+    t.assert(fio.path.is_dir(fio.pathjoin(dir, '/var/lib/instance-001')))
 end
 
 g.test_applier_box_cfg = function()
diff --git a/test/config-luatest/cli_test.lua b/test/config-luatest/cli_test.lua
index ffd00ae962..f8b7893983 100644
--- a/test/config-luatest/cli_test.lua
+++ b/test/config-luatest/cli_test.lua
@@ -44,7 +44,7 @@ g.test_help_env_list = function()
         {
             name = 'TT_CONSOLE_SOCKET',
             type = 'string',
-            default = '{{ instance_name }}.control',
+            default = 'var/run/{{ instance_name }}/tarantool.control',
             availability = 'Community Edition',
         },
         -- An Enterprise Edition option and, at the same time,
diff --git a/test/config-luatest/cluster_config_schema_test.lua b/test/config-luatest/cluster_config_schema_test.lua
index 0fa6480533..8c6de92027 100644
--- a/test/config-luatest/cluster_config_schema_test.lua
+++ b/test/config-luatest/cluster_config_schema_test.lua
@@ -132,7 +132,7 @@ g.test_defaults = function()
         },
         log = {
             to = 'stderr',
-            file = '{{ instance_name }}.log',
+            file = 'var/log/{{ instance_name }}/tarantool.log',
             pipe = box.NULL,
             syslog = {
                 identity = 'tarantool',
@@ -144,7 +144,7 @@ g.test_defaults = function()
             format = 'plain',
         },
         snapshot = {
-            dir = '{{ instance_name }}',
+            dir = 'var/lib/{{ instance_name }}',
             by = {
                 interval = 3600,
                 wal_size = 1000000000000000000,
@@ -170,10 +170,10 @@ g.test_defaults = function()
             title = 'tarantool - {{ instance_name }}',
             username = box.NULL,
             work_dir = box.NULL,
-            pid_file = '{{ instance_name }}.pid',
+            pid_file = 'var/run/{{ instance_name }}/tarantool.pid',
         },
         vinyl = {
-            dir = '{{ instance_name }}',
+            dir = 'var/lib/{{ instance_name }}',
             max_tuple_size = 1048576,
             bloom_fpr = 0.05,
             page_size = 8192,
@@ -213,7 +213,7 @@ g.test_defaults = function()
             bootstrap_strategy = 'auto',
         },
         wal = {
-            dir = '{{ instance_name }}',
+            dir = 'var/lib/{{ instance_name }}',
             mode = 'write',
             max_size = 268435456,
             dir_rescan_delay = 2,
@@ -222,7 +222,7 @@ g.test_defaults = function()
         },
         console = {
             enabled = true,
-            socket = '{{ instance_name }}.control',
+            socket = 'var/run/{{ instance_name }}/tarantool.control',
         },
         memtx = {
             memory = 268435456,
diff --git a/test/config-luatest/instance_config_schema_test.lua b/test/config-luatest/instance_config_schema_test.lua
index 5b12dfc07f..b0f8a89bfe 100644
--- a/test/config-luatest/instance_config_schema_test.lua
+++ b/test/config-luatest/instance_config_schema_test.lua
@@ -156,7 +156,7 @@ g.test_process = function()
         title = 'tarantool - {{ instance_name }}',
         username = box.NULL,
         work_dir = box.NULL,
-        pid_file = '{{ instance_name }}.pid',
+        pid_file = 'var/run/{{ instance_name }}/tarantool.pid',
     }
     local res = instance_config:apply_default({}).process
     t.assert_equals(res, exp)
@@ -174,7 +174,7 @@ g.test_console = function()
 
     local exp = {
         enabled = true,
-        socket = '{{ instance_name }}.control',
+        socket = 'var/run/{{ instance_name }}/tarantool.control',
     }
     local res = instance_config:apply_default({}).console
     t.assert_equals(res, exp)
@@ -256,7 +256,7 @@ g.test_log = function()
 
     local exp = {
         to = 'stderr',
-        file = '{{ instance_name }}.log',
+        file = 'var/log/{{ instance_name }}/tarantool.log',
         pipe = box.NULL,
         syslog = {
             identity = 'tarantool',
@@ -734,7 +734,7 @@ g.test_vinyl = function()
     validate_fields(iconfig.vinyl, instance_config.schema.fields.vinyl)
 
     local exp = {
-        dir = '{{ instance_name }}',
+        dir = 'var/lib/{{ instance_name }}',
         max_tuple_size = 1048576,
         bloom_fpr = 0.05,
         page_size = 8192,
@@ -768,7 +768,7 @@ g.test_wal = function()
     validate_fields(iconfig.wal, instance_config.schema.fields.wal)
 
     local exp = {
-        dir = '{{ instance_name }}',
+        dir = 'var/lib/{{ instance_name }}',
         mode = 'write',
         max_size = 268435456,
         dir_rescan_delay = 2,
@@ -832,7 +832,7 @@ g.test_snapshot = function()
     validate_fields(iconfig.snapshot, instance_config.schema.fields.snapshot)
 
     local exp = {
-        dir = '{{ instance_name }}',
+        dir = 'var/lib/{{ instance_name }}',
         by = {
             interval = 3600,
             wal_size = 1000000000000000000,
-- 
GitLab