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-terminal 窗口,其中包含十几个命名选项卡(每个服务一个),每个选项卡中都有激活的 virtualenv 并在该选项卡中运行一堆服务实例。到目前为止,我得到的最好结果是:

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

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

有任何想法吗?如何获取激活脚本、命名和运行服务?

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

4

2 回答 2

2

以下对我有用,并按照您的要求执行:

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'

于 2009-11-09T14:17:52.493 回答
0

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

在 Edit > Profile Preferences > Title and Command > Run a custom command 而不是我的 shell 中,将自定义命令设置为:

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

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

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"

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

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

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

于 2011-02-21T22:11:23.457 回答