Easily Start and Stop Development Tools in OS X
Today I will show you two shortcuts I use to start and stop my development tools on OS X. As your tool stack grows, it becomes more and more cumbersome to perform this task and chances are that you do not have a graphical user interface to do this (unless you are using MAMP or similar). Also, you probably do not want your development tools to be running at all times, e.g. a web server and database. Either way, in this small article I will show you how you can perform an arbitrary task by using a command in the Terminal.
First we need to either edit or create a file named .bash_profile in your user directory, e.g. /Users/Andy/. There are incredibly many ways to do this. If you are familiar with vi or similar, then that is probably the easiest way to do it. However, I am going to assume that you will use your favorite text editor, and will therefore add a small additional step.
First we will check if the .bash_profile file already exists. Open the Terminal and enter the following:
open ~/.bash_profile
The tilde sign simply refers to the current user’s directory. If you get a message that the file does not exist, then we have to create it. Otherwise just skip the following small step.
touch ~/.bash_profile
This creates an empty file for us. Now open the file with the first mentioned command.
Great! Now we are ready to make our commands. Personally I am currently starting Apache, MySQL and Memcached, but you can add or remove as many tools as you like. Add the following to the open file:
startdev() {
echo "Starting Apache...";
sudo apachectl start;
sudo /usr/local/mysql/support-files/mysql.server start;
echo "Starting memcached...";
memcached -d;
}
stopdev() {
echo "Stopping Apache...";
sudo apachectl stop;
sudo /usr/local/mysql/support-files/mysql.server stop;
echo "Stopping memcached...";
killall memcached;
}
Provided that you have changed the commands to suit your environment, you are now good to go. Save the file, restart your Terminal (otherwise it will not work) and enter either of the two commands.
andy:~ Andy$ startdev
Starting Apache...
Starting MySQL
. SUCCESS!
Starting memcached...
Note that you may have to enter your password if one or more of your commands uses sudo. Of course you can use this technique for many other purposes as well.
That was easy, was it not? Now you can do just a little less typing and produce a little bit more.
One comment on »Easily Start and Stop Development Tools in OS X«
I’m New to MAC. Tried the above for starting and stopping my servlet container. Unfortunatley when i tried the first command, second command too got executed. Content of my bash_profile file is placed below