使用多个 virtualenv 选项卡和服务启动 gnome-terminal,预先命名

发布于 2024-08-10 07:49:50 字数 719 浏览 5 评论 0原文

我正在开发一个由多项服务组成的服务器端项目。每个服务都以交互(即非守护进程)模式运行,这在积极开发时很方便。该项目位于 virtualenv 中。所以启动一个服务的典型方式是:

$ cd ~/to/vitualenv/subdir/where/service/code/located
$ source ../path/to/virtualenv/bin/activate
$ ./script-to-start-service
+ Set title of terminal to the service name via GUI

如果有2-3个服务就可以了。但我们有十几个。计算机重新启动后重新启动所有这些程序确实很痛苦。

所以我想要的是一个脚本,一旦执行,它就会打开新的 gnome 终端窗口,其中包含十几个命名选项卡(每个服务一个),每个选项卡中都激活了 virtualenv,并在该选项卡中运行一堆服务实例。到目前为止我得到的最好结果是:

$ gnome-terminal --working-directory=~/to/vitualenv/subdir --window --tab --tab

--title 和 --profile 看起来被忽略了,如果指定 --command ,新打开的窗口将在打开后立即关闭。

有什么想法吗?如何获取激活脚本、给出标题并运行服务?

PS 仅用于开发目的,不适用于真实服务器上的部署。

I'm working on a server-side project that consists of several services. Each service is run in interactive (i.e. non-daemon) mode, this is handy while active development. The project is in virtualenv. So the typical way to start a service is:

$ cd ~/to/vitualenv/subdir/where/service/code/located
$ source ../path/to/virtualenv/bin/activate
$ ./script-to-start-service
+ Set title of terminal to the service name via GUI

It would be ok if there were 2-3 services at all. But we have a dozen. And restarting all of them after computer reboot is a real pain.

So what I want is a script, that once executed opens me new gnome-terminal window with a dozen of named tabs (one per service), with activated virtualenv in each and running bunch of service instances in that tabs. The best result I've got so far is:

$ gnome-terminal --working-directory=~/to/vitualenv/subdir --window --tab --tab

--title and --profile looks like been ignored and if --command is specified newly opened window is closed just in moment after open.

Any ideas? How to source activation script, give a title, and run service?

P.S. It is for development purposes only, not for deployment on real servers.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

温馨耳语 2024-08-17 07:49:50

以下内容对我有用并执行您所要求的操作:

gnome-terminal --working-directory=/path/to/wd --tab-with-profile=profile1 --title=title1 -e 'bash --rcfile /path/to/rcfile1.sh' --tab-with-profile=profile2 --title=title2 -e 'bash --rcfile /path/to/rcfile2.sh'

The following works for me and do what you requested:

gnome-terminal --working-directory=/path/to/wd --tab-with-profile=profile1 --title=title1 -e 'bash --rcfile /path/to/rcfile1.sh' --tab-with-profile=profile2 --title=title2 -e 'bash --rcfile /path/to/rcfile2.sh'

傲影 2024-08-17 07:49:50

创建一个名为“service”的 gnome-terminal 配置文件(编辑 > 配置文件 > 新建)。

在编辑>配置文件首选项>标题和命令>运行自定义命令而不是我的 shell,将自定义命令设置为:

bash --rcfile ../path/to/virtualenv/bin/activate

然后使用 gnome-terminal 启动您的服务。以下命令在不同目录的选项卡中启动两个 yes 实例。我已将命令分成三行,但您应该将其输入为一行。

gnome-terminal
--tab-with-profile=service --working-directory=/home/$USER/data --title="feelgood" --command="yes"
--tab-with-profile=service --working-directory=/code --title="negative" --command="yes no"

您可能希望创建一个文件用作自定义命令,而不是直接调用 activate:

source ~/.bashrc
source ../path/to/virtualenv/bin/activate

您还可以添加命令(例如更改目录或启动服务)。请注意,每次使用该配置文件打开终端时,都会执行这些命令。

Create a gnome-terminal profile named "service" (Edit > Profiles > New).

In Edit > Profile Preferences > Title and Command > Run a custom command instead of my shell, set the custom command to:

bash --rcfile ../path/to/virtualenv/bin/activate

Then use gnome-terminal to launch your services. The following command launches two instances of yes in tabs in different directories. I've broken the command into three lines, but you should enter it as one line.

gnome-terminal
--tab-with-profile=service --working-directory=/home/$USER/data --title="feelgood" --command="yes"
--tab-with-profile=service --working-directory=/code --title="negative" --command="yes no"

Instead of directly calling activate, you may want to create a file to use as your custom command:

source ~/.bashrc
source ../path/to/virtualenv/bin/activate

You can also add commands (like change directory or launching your service). Just beware that every time you open a terminal with that profile, those commands are executed.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文