Skip to content

Instantly share code, notes, and snippets.

@f13dev
Last active September 18, 2016 17:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save f13dev/5771bc6379e0fb58619b93f981788dc0 to your computer and use it in GitHub Desktop.
Save f13dev/5771bc6379e0fb58619b93f981788dc0 to your computer and use it in GitHub Desktop.
Bash script to start and/or stop Apache Tomcat on MacOS. Place these files in "/usr/local/bin" and mark each executable using "chmod +x filename".
#Start tomcat
/Library/Tomcat/bin/startup.sh &>/dev/null &disown
#print message
printf "\n\nStarting apache tomcat\n"
#sleep for 5 seconds
sleep 5
#Check if tomcat has started (localhost:8080 should succeed)
if curl --output /dev/null --silent --head --fail http://localhost:8080/
then
echo "Tomcat is now running"
else
echo "Tomcat could not be started"
fi
#Add a couple of new lines to neaten up the appearance
printf "\n\n"
#Stop tomcat
/Library/Tomcat/bin/shutdown.sh &>/dev/null &disown
#print message
printf "\n\nStopping apache tomcat\n"
#sleep for 5 seconds
sleep 5
#Check if tomcat has stopped (localhost:8080 should return an error)
if curl --output /dev/null --silent --head --fail http://localhost:8080/
then
echo "Tomcat could not be stopped"
else
echo "Tomcat is no longer running"
fi
#Add a couple of new lines to neaten up the appearance
printf "\n\n"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment