Question

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.

Was it helpful?

Solution

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'

OTHER TIPS

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top