When I start up my development environment, there are a variety of processes I need to run in the background. It is a pain to start them all individually so I want to write a script that starts each one. I can do this just fine but the problem comes when I need to restart them (something I will need to do regularly).
What is the easiest way to capture the process upon starting it and saving that information so that when I run the script again, it will check to see if that information has been saved and then close down those processes before restarting them.
I also want the script to be flexible enough such that if I shutdown the process manually, it will a) not throw an error if it can't find the process and b) not accidentally shut down some other process that has since then shared whatever identifying information I have stored.
More specifically, I want to at least do the following at the moment:
1) Type a short command like "start-dev"
2) Execute the following (Note that I want the second and third commands to run in the background and am using & to do so but not the final command as I want to see the output from passenger as it runs):
- Change to my working directory
- Start faye as a background process
- Start watchr as a background process
- Start passenger
So far I have got this
#!/bin/bash cd ~/path/to/my/working-directory rackup faye.ru -s thin -E production & watch refresh.watchr & passenger start
This works fine but the problem comes when I need to restart all these processes. I first have to track down all their process ids and then kill them before running start-dev again. Therefore I would like to:
4) Type a short command like "restart-dev" which tracks down the processes I have previously run in the background and then kill them before running "start-dev" again. It needs to be able to not throw an error if I have shut down any of these manually and not accidentally shutdown an incorrect process.