使用多个 virtualenv 选项卡和服务启动 gnome-terminal,预先命名
我正在开发一个由多项服务组成的服务器端项目。每个服务都以交互(即非守护进程)模式运行,这在积极开发时很方便。该项目位于 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(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'
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'
创建一个名为“service”的 gnome-terminal 配置文件(编辑 > 配置文件 > 新建)。
在编辑>配置文件首选项>标题和命令>运行自定义命令而不是我的 shell,将自定义命令设置为:
然后使用 gnome-terminal 启动您的服务。以下命令在不同目录的选项卡中启动两个
yes
实例。我已将命令分成三行,但您应该将其输入为一行。您可能希望创建一个文件用作自定义命令,而不是直接调用 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:
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.Instead of directly calling activate, you may want to create a file to use as your custom command:
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.