Skip to content

Commit

Permalink
run: remove our wrapper from instance start
Browse files Browse the repository at this point in the history
Now 'tt run' starts instance without our wrapper.

Follow up #696
  • Loading branch information
better0fdead authored and psergee committed Dec 27, 2023
1 parent 744a4c7 commit 9a1d317
Show file tree
Hide file tree
Showing 6 changed files with 6 additions and 54 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
running apps.
- `tt rocks --server` now accepts several URL's.
- Disable ``tt run`` tarantool flag parsing.
- Now ``tt run`` starts instance without our wrapper.

### Added

Expand Down
27 changes: 2 additions & 25 deletions cli/cmd/run.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
package cmd

import (
"fmt"
"os"
"strings"

"github.com/spf13/cobra"
"github.com/tarantool/tt/cli/cmdcontext"
"github.com/tarantool/tt/cli/modules"
Expand Down Expand Up @@ -85,29 +81,10 @@ func internalRunModule(cmdCtx *cmdcontext.CmdCtx, args []string) error {
}

runInfo := newRunInfo(*cmdCtx)
scriptPath := ""
startIndex := 0
if len(args) > 0 {
for i, option := range args {
if strings.HasSuffix(option, ".lua") {
scriptPath = option
if _, err := os.Stat(scriptPath); err != nil {
return fmt.Errorf("there was some problem locating script: %s", err)
}
startIndex = i
break
}
}
}

if len(args) != 0 && scriptPath != "" {
runInfo.RunOpts.RunArgs = args[startIndex+1:]
runInfo.RunOpts.RunFlags = args[:startIndex]
} else if scriptPath == "" {
runInfo.RunOpts.RunFlags = args
}
runInfo.RunOpts.RunArgs = args

if err := running.Run(runInfo, scriptPath); err != nil {
if err := running.Run(runInfo); err != nil {
return err
}

Expand Down
1 change: 0 additions & 1 deletion cli/running/cluster_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,6 @@ func (inst *clusterInstance) Run(opts RunOpts) error {
}
f.Close()

args = append(args, opts.RunFlags...)
args = append(args, opts.RunArgs...)
log.Debugf("Running Tarantool with args: %s", strings.Join(args[1:], " "))
execErr := syscall.Exec(inst.tarantoolPath, args, newInstanceEnv)
Expand Down
7 changes: 2 additions & 5 deletions cli/running/running.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,6 @@ type InstanceCtx struct {
type RunOpts struct {
// RunArgs contains command args.
RunArgs []string
// RunFlags contains command flags.
RunFlags []string
}

// RunInfo contains information for tt run.
Expand Down Expand Up @@ -675,9 +673,8 @@ func Stop(run *InstanceCtx) error {
}

// Run runs an Instance.
func Run(runInfo *RunInfo, scriptPath string) error {
inst := scriptInstance{tarantoolPath: runInfo.CmdCtx.Cli.TarantoolCli.Executable,
appPath: scriptPath}
func Run(runInfo *RunInfo) error {
inst := scriptInstance{tarantoolPath: runInfo.CmdCtx.Cli.TarantoolCli.Executable}
err := inst.Run(runInfo.RunOpts)
return err
}
Expand Down
22 changes: 0 additions & 22 deletions cli/running/script_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,29 +219,7 @@ func (inst *scriptInstance) Run(opts RunOpts) error {
}
f.Close()
newInstanceEnv := os.Environ()
newInstanceEnv = append(newInstanceEnv,
"TT_CLI_INSTANCE="+inst.appPath,
"TT_CLI=true",
)
args := []string{inst.tarantoolPath}
args = append(args, opts.RunFlags...)
if inst.appPath != "" {
log.Debugf("Script to run: %s", inst.appPath)

// Save current stdin file descriptor. It will be used in launcher lua
// script to restore original stdin.
stdinFd, _ := syscall.Dup(int(os.Stdin.Fd()))
newInstanceEnv = append(newInstanceEnv, fmt.Sprintf("TT_CLI_RUN_STDIN_FD=%d", stdinFd))

// Replace current stdin with pipe descriptor, and write launcher code to this pipe.
// Tarantool will read from pipe after exec.
stdinReader, stdinWriter, _ := os.Pipe()
syscall.Dup2(int(stdinReader.Fd()), int(os.Stdin.Fd()))
stdinWriter.Write([]byte(instanceLauncher))

// Enable reading from input for Tarantool.
args = append(args, "-")
}
args = append(args, opts.RunArgs...)
log.Debugf("Running Tarantool with args: %s", strings.Join(args[1:], " "))
execErr := syscall.Exec(inst.tarantoolPath, args, newInstanceEnv)
Expand Down
2 changes: 1 addition & 1 deletion test/integration/run/test_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def test_running_missing_script(tt_cmd, tmpdir_with_cfg):
text=True
)
run_output = instance_process.stdout.readline()
assert re.search(r"was some problem locating script", run_output)
assert re.search(r"Can't open script", run_output)


def test_running_multi_instance(tt_cmd, tmpdir_with_cfg):
Expand Down

0 comments on commit 9a1d317

Please sign in to comment.