One of the services we run is apache-tomcat. I was asked to upgrade it to the latest version on 3 of our environments. Normally you’d kick of something like yum update or the like, but we download packages manually, extract them, copy config files, logs, extras, etc over and then restart the service. So it’s pretty straight forward and give the option for a super easy rollback if needed.
I don’t feel like it’s appropriate to post the script here, but I’ll post a couple of the things I learned while doing it:
I had seen the ‘case $1’ used before and understood it, but never implemented it. I set it up to have 2 options
-v for verbose output
-h for help and then exit program
This little bit of code will take the file that you enter (which would be something like http://mirrors.sorengard.com/apache/tomcat/tomcat-9/v9.0.13/bin/apache-tomcat-9.0.13.tar.gz and then get just the file name, so it would be something like apache-tomcat-9.0.13.tar.gz
What this does is remove the tar.gz part of the file, so I know what directory I’m working with – useful if you need to change a symlink or something like that.
read -n 1 -srp "Press any key to continue..."
This was a pause I’d put in the script to make sure it was behaving appropriately.
There were other little things like if statements that got me tripped up for a bit and other times I’d mis typed something or the other, but as far as I can tell, it’s working. I’ll not be running the script today though so I’ll save it for later.
What I like most about doing things like this, is it solves a problem not just the one or two or fifteen times, but all of the rest of the times that you’d normally have to upgrade something. Even though it took me a about 2 hours to do, it will save lots of time in the long run and anyone else can run it if they have the right permissions.
It reminds me of the scene in the movie “Ender’s Game” where Ender is jumped in the bathroom by 2 or 3 guys but Ender surprises them and beats one guy up a few inches from his life. When he was questioned about it later, and was asked why he beat the guy up so hard and continued to beat him up after it was obvious that he won the fight and was able to get away. His answer was something like ‘I didn’t want to win this fight, but all the fights going forward’. And the bully never fought him again, thus solving his bully problem completely and allowing him to focus on other things. I like to think of this in the same way – it’s solved (I mean probably, I’m sure there’s things I could improve on and extend) and can move on to bigger and better.