Two days ago I had an interview in a Buenos Aires’ software company. They decided to test my Linux skills with a simple task, to create a .deb package with certain characteristics.

  • They provided to me a binary in Python (which you can download here) that runs in a loop generating a file «log.txt». The idea were to automate all the next tasks within the .deb package or «with the installation of it»:
    • Run the binary as a service
    • Run the binary as the user «app»
    • The binary must be installed in /usr/local/bin/app
    • Create a crontab task to sent by email the «log.txt» to everyday at midday.
    • Rotate the «log.txt» to 5 files and delete the older ones.

All those tasks separately are common to me, but it was my first time dealing with an «.deb» package.

My first attempt to do it failed, I had tried to follow the Debian Packaging Introduction from the official Debian’s website and I tried to «fit that documentation to my needs». I had to deal with a lot of cryptic errors and the process was «too delicate» so after an hour fixing errors in that approach I searched for another way to accomplish the task.

As soon as I started searching I found and amazing and simple way to do it in this thread just a few steps and «tadaaaa» I had my first deb package just using this:

You’ll need to read the whole guide (1 page) to understand all the details.

How to create a .deb package

How to create a .deb package – The final result after installing my package.

So, I learnt how to create the deb package. Now it was time to fulfill with the rest of the requirements so I created the folder structure with the required files:

Example of control file

app-mailcron (Cron Task)

Bear in mind I’m adding this to /etc/cron.d/app-mailcron (Here is mandatory to specify the user, different than crontab -e where you do not specify it).

app-logrotate (Rotate log.txt)

But that was just the first part of it, now I had to add all the extra requirements. I really don’t know how I found this StackOverflow post but it exlpained the structure of the DEBIAN folder, it caught my attention immediatly when I saw «preinst and postinst» in the structure and the «mkdir» faulty command.

Those names so obvious had to be the files I needed, so I added the next instructions into them to fulfill the requirements:



And here’s the result of the whole process, you can use tar to extract its content and check it or install it (dpkg -i app-1.0.deb), but then you will have to deal deleting the «app» user because it doesn’t happen after a deinstall.

It may not be the best result because a matter of time, but at least it fulfill all the requirements.