Webserver initializer/stopper in bash
#!/bin/bash
# First, kill mailcatcher everytime
hasmailcatcher=`ps aux | grep '[m]ailcatcher'`
echo $hasmailcatcher
if [[ -n $hasmailcatcher ]]; then
sudo kill -9 `ps aux | grep '[m]ailcatcher' | awk '{print $1}'`
fi
# Determine the action
action=$1
if [ "$action" == 'start' ]; then
sudo apachectl restart
sudo mysql.server start
mailcatcher --smtp-port 1040 --verbose
elif [ "$action" == 'stop' ]; then
sudo apachectl stop
sudo mysql.server stop
else
echo 'Please specify an action: start or stop'
exit 1
fi
echo 'Done!'