I need to run multiple servers in a VM(Ubuntu 14.04)
. I'm using screen to do this. Now, every time I bring the VM down, I have to start the screens again. So, I'm writing a shell script to automate this. Following is my script as of now
#!/usr/bin/env bash
# Create a screen in detached mode and set default title
screen -d -m -S screenName -t "DjangoServer"
# Start django app in window 0
# Source environment variables for screen shell.
# TODO: Check if this is required.
screen -S screenName -X stuff $"source ~/.profile\n"
# Start virtual environment(virt_env command) exported via ~/.profile
screen -S screenName -X stuff $"virt_env\n"
# Run Django app using grunt
screen -S screenName -X stuff $"grunt\n"
# Start node app in window 1
screen -S screenName -X screen -t "NodeAPI"
screen -S screenName -p 1 -X stuff $"cd /vagrant/node-app\n"
screen -S screenName -p 1 -X stuff $"npm start\n"
# Start a screen running a shell, simply
screen -S screenName -X screen -t "bash"
I am new to shell scripting and am sure there must be a better way to do this. Could anyone tell me how to. Since the commands are very few, I'm not inclined towards writing a shell scripts for the commands to be run in screen-windows. But if that is the standard way, do suggest how to. TIA.
EDIT
I don't want to modify .screenrc
as well.
This is very nice, but maybe you should invest some time in discovering how to run system scripts via init (and the like) instead.
screen
is made primarily for human consumption.