Analyze Linux disk usage

Fixing a disk space problem on a Linux server without a graphical interface is tedious without the right command line tools handy.

Disk usage

A quick df -h  lists all disks and their current usage.

Find large files

To find large folders with files to clean up, you can use ncdu. Install it ( sudo apt-get install ncdu ) and start it pointing to a certain folder.

Why I love Kotlin

At avisec we decided to use Kotlin when we started to rewrite our backend service. This has proven to be a very good decision. Here are my top 10 reasons why I do love Kotlin:

  1. Data classes eliminate a lot of boilerplate code.
  2. The nullability support of the compiler forces you to think about nulls everywhere. This reduces the number of NullpointerException related bugs to a minimum.
  3. The lambda syntax is very, very lean.
  4. No more guessing which functional Java interface to use.
  5. The standard library provides is a great help.
  6. The IntelliJ support is seamless.
  7. Java and Kotlin integrate both ways – you can start writing Kotlin code in Java projects today, no big deal.
  8. Return values are supported for most (?) structures: if, try/catch, when
  9. Assign default values to parameters and used named parameters when calling functions.
  10. Generics in Kotlin are more powerful than in Java.

Let’s hope the current adoption rate of Kotlin continues and it will become a widely used alternative for Java on the JVM.

Windows (Samba) Share on a Raspberry PI

Assuming you are working  somewhere with a small team and you need a local Windows share to collaborate on documents and oder data. A first choice would obviously be to use Dropbox or a similar cloud service. However if you do not want to send your data to another company or if your internet connection is unstable, you might want to use a server in your local network. My suggestion here is the following: Grab yourself a Rapberry PI, configure a Windows compatible Samba share and start using it.

Preparation

  • Purchase a Raspberry PI 3, a power supply, an SD card and preferably an enclosing.
  • Write the Raspbian image to the SD card and start the PI.
  • Use sudo raspi-config  to set the hostname and enable SSH.

Install Samba

  • Run sudo apt-get install samba samba-common-bin  to install the required packages.
  • Create the folder for the share:  sudo mkdir -m 1777 /share
  • Open /etc/samba/smb.conf  as root (sudo!) using vim or nano (according to your taste of Linux editors and append the following block at the bottom.
  • Restart the samba service: sudo service samba restart

Create Users

Now you can create the accounts that will be able to use the share:

You can now access the share using the hostname or the IP address in your windows explorer: \\ip\share

Configure Backup

Never trust your users not to mess up things. You should not skip doing backups, especially when it is as easy as this:

  1. Edit the crontab file: crontab -e
    Add the following line at the bottom to create a backup every hour from 7 to 22.
  2. Create the backup script: sudo nano /home/pi/run-backup.sh  and add the following content.
  3. Make the script executable:  chmod a+x /home/pi/run-backup.sh

Backups are now created every hour as zip files in the folder  /home/pi/backups/ .

Sources

Mosquitto TLS instability

We’ve been facing recurring TLS issues with Mosquitto, our MQTT broker. The clients tried to send a message and lost the connection in a random and non-reproducible manner. In the Mosquitto error log we always found the following problem:

This issue is reported on GitHub and there seems to be no solution to it yet. However wiebeytec recommended to use an NGINX stream proxy to terminate the TLS connection and forward the decrypted traffic locally to Mosquitto. This is what we did and it solved our issue too!

 

Webcam

I’m currently working at Avisec on an open source webcam software component to turn your Raspberry PI and your DSLR into an awesome image-publishing device. Here is a sneak preview of how it could look like when you publish your images to the (commercial) providers Teleport or Panomax.

The images are taken every 15 minutes from my home in Hirschthal AG, Switzerland.

Panomax.com (with panorama)

Teleport.nu (with timelapse)

Launch Jenkins using Docker Compose

To launch a Jenkins server in a Docker container using Docker Compose, the following docker-compose.yml defines a Jenkins server with a persistent job configuration.

And start then start it:

You should now have a Jenkins running on localhost:8080.

If you need a bash to change any configuration, start it like this:

 

Java startup parameters

The following Java startup parameters should be used (and the values adjusted) when running a Java process on a server.

When a Java process starts, it overwrites an existing GC log file. I would recommend to either use a timestamp in the filename or use the %pid placeholder.

If you want to use JMX, also add the following parameters:

Functional Interfaces in Java 8

With Java 8, the concept of Lambdas was finally added to the language specification. Often you’re using Lambdas on the fly without assigning them to a variable.

However if you want to save a Lambda into a variable and pass it as a method parameter or use it later, you need to pick the applicable type.

Here is the list of the Interfaces you might use from the Java API:

  • Runnable // nothing
  • Supplier<T> // a return value
  • Consumer<T> // a parameter
  • BiConsumer<T, U> // two parameters
  • Function<T, R> // a parameter and a return value
  • BiFunction<T, U, R> // two parameters and a return value
  • UnaryOperator<T> // the parameter and the return value have the same type
  • BinaryOperator<T> // two parameters and a return value of the same type
  • Predicate<T> // a parameter and a boolean return value
  • BiPredicate<T, U> // two parameters and a boolean return value

InformIT presents all those Interfaces using a nice table in the article “Java SE 8 for the Really Impatient: Programming with Lambdas“.