forked from tarantool/tt
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
start: add a "launcher" for the tarantool instance
This patch adds a "launcher" - an intermediate lua script that runs under tarantool and does some preparation (like creating "console socket", wrapping `box.cfg`...) before launching the application instance. Part of tarantool#7
- Loading branch information
Showing
12 changed files
with
182 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,4 @@ | |
__pycache__ | ||
.DS_Store | ||
/tt | ||
**/*_gen.go |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package main | ||
|
||
import ( | ||
"io/ioutil" | ||
|
||
"github.com/apex/log" | ||
"github.com/dave/jennifer/jen" | ||
) | ||
|
||
type generateLuaCodeOpts struct { | ||
PackageName string | ||
FileName string | ||
PackagePath string | ||
VariablesMap map[string]string | ||
} | ||
|
||
var luaCodeFiles = []generateLuaCodeOpts{ | ||
{ | ||
PackageName: "running", | ||
FileName: "cli/running/lua_code_gen.go", | ||
VariablesMap: map[string]string{ | ||
"instanceLauncher": "cli/running/lua/launcher.lua", | ||
}, | ||
}, | ||
} | ||
|
||
func generateLuaCodeVar() error { | ||
for _, opts := range luaCodeFiles { | ||
f := jen.NewFile(opts.PackageName) | ||
f.Comment("This file is generated! DO NOT EDIT\n") | ||
|
||
for key, val := range opts.VariablesMap { | ||
content, err := ioutil.ReadFile(val) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
f.Var().Id(key).Op("=").Lit(string(content)) | ||
} | ||
|
||
f.Save(opts.FileName) | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func main() { | ||
if err := generateLuaCodeVar(); err != nil { | ||
log.Errorf("Error while generating lua code string variables: %s", err) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
--- This is a launch script that does the necessary preparation | ||
-- before launching an instance. | ||
|
||
-- The script is delivered inside the "tt" binary and is launched | ||
-- to execution via the `-e` flag when starting the application instance. | ||
-- AFAIU, due to such method of launching, we can reach the limit of the | ||
-- command line length ("ARG_MAX") and in this case we will have to create | ||
-- a file with the appropriate code. But, in the real world this limit is | ||
-- quite high (I looked at it on several machines - it equals 2097152) | ||
-- and we can not create a workaround for this situation yet. | ||
-- | ||
-- Several useful links: | ||
-- https://porkmail.org/era/unix/arg-max.html | ||
-- https://unix.stackexchange.com/a/120842 | ||
|
||
local os = require('os') | ||
local console = require('console') | ||
local log = require('log') | ||
local title = require('title') | ||
|
||
|
||
--- Start an Instance. The "init" file of the Instance passes | ||
-- throught "TT_CLI_INSTANCE". | ||
local function start_instance() | ||
local instance_path = os.getenv('TT_CLI_INSTANCE') | ||
if instance_path == nil then | ||
log.error('Failed to get instance path') | ||
os.exit(1) | ||
end | ||
title.update{ | ||
script_name = instance_path, | ||
__defer_update = true | ||
} | ||
|
||
-- Preparation of the "console" socket. | ||
local console_sock = os.getenv('TT_CLI_CONSOLE_SOCKET') | ||
if console_sock ~= nil and console_sock ~= '' then | ||
console.listen(console_sock) | ||
end | ||
|
||
-- Start the Instance. | ||
local success, data = pcall(dofile, instance_path) | ||
if not success then | ||
log.error('Failed to run instance: %s', instance_path) | ||
os.exit(1) | ||
end | ||
return 0 | ||
end | ||
|
||
start_instance() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters