Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How should I create an automated deployment script?

I need to create some way to get a local WAR file deployed on a Linux server. What I have been doing until now is the following process:

  1. Upload WAR using WinSCP.
  2. SSH into server using PuTTY.
  3. Move/Rename/Delete certain files folders to prepare for WAR explosion.
  4. Explode WAR.
  5. Send email notifying users of restart.
  6. Stop Tomcat server.
  7. Use tail to make sure server stopped correctly.
  8. Change symlink to point to exploded WAR.
  9. Start Tomcat.
  10. Use tail to make sure server started correctly.
  11. Send email notifying users of completed restart.

This stuff is all relatively straightforward. And I'm sure there are a million and one different ways to do it. Id like to hear about some options. My first thought was a Bash script. I have very little experience with scripting in general but thought this would be a good way to learn. I would also be interested in doing this with Ruby/Python or something current like this as I have little to no experience with these languages. I think as a young developer, I should definitely get some sort of scripting language under my belt. I may also be interested in some sort of software solution that could do this stuff for me, although I think scripting would be a better way to go for the sake of ease and customizability (I might have just made that word up).

Some actual questions for those that made it this far. What language would you recommend to automate the process I've listed above? Would this be a good opportunity for me to learn Bash/Ruby/Python/something else, or should I simply take the 10 minutes to do this by hand 2-3 times a week? I would think the answer to this is obviously no. Can I automate these things from my computer, or will I need to setup the scripts to run within the Linux server? Is the email something I can automate or am I better off doing that part myself?

More questions will almost certainly come up as I do this so thanks to all in advance.

UPDATE

I should mention, I am using Maven to build the WAR. So if I can do all of this with Maven please let me know.

like image 229
UmYeah Avatar asked Dec 31 '09 16:12

UmYeah


2 Answers

This might be too heavy duty for your needs, but have you looked at build automation tools such as CruiseControl or Hudson? You might also want to look at Integrity, which is more lightweight and written in Ruby (instead of Java like the other two I mentioned). These tools can do everything you said you needed in your question plus way, way more.

Edit

Since you want this to be more of a learning exercise in scripting languages than a practical solution, here's an idea for you. Instead of manually uploading your WAR each time to your server, set up a Mercurial repository on your server and create a hook (see here, here, and especially here) that executes a Ruby (or ant, or maven) script each time a changeset is pushed from a remote computer (i.e. your local workstation). You would write the script so it does all the action items in your list above. That way, you will get to learn three new things: a distributed version control paradigm, how to customize said tool, and how to write Ruby scripts to interact with your operating system (since your actions are very filesystem heavy).

like image 92
Marc W Avatar answered Sep 18 '22 08:09

Marc W


The most common in my experience is ant, it's worth learning, it's all pretty simple, and very usefull.

You should definately automate it, and you should aim to have it happen in 1 step.

like image 29
Paul Creasey Avatar answered Sep 19 '22 08:09

Paul Creasey