Automate, automate, automate!


What is usually the first thing that comes to mind when a software developer mentions the words “automate” or “automation“? You might think of automated tests, builds, and deployments. With the rise of Continuous Integration (CI) and Continuous Delivery (CD) in the last few years these are now common practices in many IT companies all over the world.

But it’s not only in the context of CI or CD that we should automate tasks, by the contrary. You should consider automating as much as possible – not only builds and deployments but also other tasks such as installing or configuring applications and services.


When should I automate?

Let’s suppose that a given task takes 30 minutes to be executed manually. In order to automate it we would need 2 hours.

If it is a one time job then it doesn’t make sense to automate the task given that it takes 4x more time than executing it manually. On the other hand, if you’re going to execute the task multiple times then it might compensate the time spent automating it. The time you save is not the only benefit – repetitive and manual tasks are tedious and error-prone, right?


How to automate these tasks?

Use powershell, batch files, python or create a small application in any other programming language or tool that you’re comfortable with like .NET or Java – ideally any application or script that can easily be executed on a command line and/or as part of a build in a CI/CD server. You might not have one yet but when the time comes it will be much easier to create a build/deployment pipeline.


An example – configure a Windows service for MongoDB

Recently I started working on a system that is using MongoDB, so I had to install it in my developer machine and configure it to be used as a Windows Service. Basically all I needed was to follow all the steps described in the section “Configure a Windows Service for MongoDB“of the following tutorial: Install MongoDB on Windows.

The steps are the following:

  1. Create a directory for the database
  2. Create a directory for the log files
  3. Remove the MongoDB service (if already installed)
  4. Create and copy the configuration file
  5. Install the MongoDB service
  6. Start the MongoDB service

Given that I needed to configure the service on multiple servers and that other members of the team would need to do the exact same thing I decided to automate this task.

For this task I created a small C# console application that looks like this:

Console application

As I mentioned before, use any language or tool that you’re comfortable with. In this case I used C# because I use it everyday so it was faster to create this application but I could have used  something else like Powershell or a batch script.

That’s it! No need for fancy or complicated applications/scripts, just something simple that does the job.

Happy coding and remember: automate (almost) everything  😉





Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s