如何在不同环境下启动两个 tmux 会话? [英] How to start two tmux sessions with different environments?

查看:36
本文介绍了如何在不同环境下启动两个 tmux 会话?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这种天真的方法行不通.试试这个:

The naive way to do this is not working. Try this:

开始第一个 tmux 会话.

Start a first tmux session.

$ export ENVIRONMENT="production"
$ tmux

然后您可以验证会话内的 ENVIRONMENTproduction

You can then verify that inside the session ENVIRONMENT is production

然后,在第二个终端启动另一个会话

Then, in a second terminal start another session

$ export ENVIRONMENT="staging"
$ tmux

令人惊讶的是,在本次会议中,ENVIRONMENT 也是 production!这很不直观!

Surprisingly in this session ENVIRONMENT is also production! This is very unintuitive!

这里发生了什么?我怎样才能做到这一点?我喜欢会话中的所有窗口继承"环境变量.

What is going on here? How can I achive this? I like all windows in a session to "inherit" the ENVIRONMENT variable.

推荐答案

最简单"的解决方案是针对不同的环境创建一个新的 tmux 服务器.

The "simplest" solution is to create a new tmux server with the different environment.

$ ENVIRONMENT=production tmux -L prod-tmux

$ ENVIRONMENT=staging tmux -L staging-tmux

每当您重新连接到现有会话时,您始终需要指定使用哪个套接字 prod-tmuxstaging-tmux.

You'll always need to specify which socket, prod-tmux or staging-tmux, to use whenever you reconnect to an existing session.

下一个解决方案是使用一台服务器,但修改该服务器中每个会话的环境.类似的东西

The next solution would be to use one server, but modify the environment of each session in that server. Something like

$ tmux new-session -d -s production
$ tmux new-session -d -s staging
$ tmux set-environment -t production ENVIRONMENT production
$ tmux set-environment -t staging ENVIRONMENT staging

请注意,ENVIRONMENT 不会在每个会话的初始窗口中运行的进程中设置,但将用于创建的任何后续窗口.(除非服务器在第一次启动时继承了ENVIRONMENT.)

Note that ENVIRONMENT would not be set in the process running in the initial window for each session, but will be for any subsequent window created. (Unless the server inherited ENVIRONMENT when it first started.)

当您运行 tmux 时,它首先查找现有服务器(默认服务器,或由 -L-S 指定的服务器) 选项).如果没有服务器,则启动一个,从当前环境继承服务器的环境.

When you run tmux, it first looks for an existing server (either the default server, or the one specified by either the -L or -S options). If there is no server, one is started, and the server's environment is inherited from the current environment.

如果有 一个服务器,tmux 简单地请求服务器执行一个 tmux 命令(默认情况下,new-session,或其他任何命令由 tmux) 命令的参数指定,然后退出.tmux 命令本身的环境不相关,除非请求的命令被记录为从中读取(参见 set-environment).

If there is a server, tmux simply requests the server to execute a tmux command (by default, new-session, or whatever command is specified by an argument to tmux) command, then exits. The environment of the tmux command itself isn't relevant, unless the requested command is documented to read from it (cf. set-environment).

服务器管理一组窗口,每个窗口代表一个由服务器创建的进程(不是 tmux 命令本身).会话只是一组逻辑窗口,也由服务器管理.

The server manages a group of windows, each of which represents a process created by the server (not the tmux command itself). A session is just a logical group of windows, also managed by the server.

这篇关于如何在不同环境下启动两个 tmux 会话?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆