Troubleshooting and Tricks to Improve Your Server - BeagleBone Media Center (2015)

BeagleBone Media Center (2015)

Appendix A. Troubleshooting and Tricks to Improve Your Server

You can have the best book in your hands, but experimentation will always remain the best way to learn. It is even more true that, even after following the instructions provided in this book, you might experience some problems. Therefore, as nothing is written in stone, here you will find some topics to help you resolve different cases that can happen. From tricks to ease your life to troubleshooting steps, I have grouped the useful tools that you can implement daily.

In this chapter, we will cover the following situations:

· How to ease your life with the command line?

· When you need to retrieve open ports

Ease your life with the command line

At the beginning, the command line can be confusing. Even though the instructions in the chapters of this book have been written for you to install in the easiest way, there's no reason to spend more time than necessary with this command line. Therefore, it's always helpful to have some tools and customizations on your system. In the long run, you will see that you will not be able to do without them.

Package management

Throughout the chapters in this book, the Linux distribution package tools are never mentioned. Indeed, you will always have commands as follows:

install apackage

This intentional abstraction helps you focus on installation itself and is short, to keep you away from syntax errors. Most importantly, with this you can set up your commands toolbox in such a way that whenever you would want to change to a different distribution, you will still use install package. Here is how you can do this:

Go and edit your bashrc in the following directory:

~/.bashrc

Here, define some aliases for debian:

· alias install="sudo apt-get install"

· alias update="sudo apt-get update"

· alias search="sudo apt-cache search"

After saving and quitting the editor, you can apply your configuration using the following command:

debian@beaglebone:~$ source ~/.bashrc

As easy as it can be, you will then just rely on these commands most of the time to handle your system. In the case, when you use a different package system, you'll just have to modify accordingly, such as with Fedora:

· alias install="yum install"

· alias update="yum update"

· alias search="yum list"

Get to know what you did previously

Let's keep on personalizing the bashrc file, but this time with the goal being to look backward for commands that you have already performed.

The aim of this trick is to avoid retyping the same command multiple times. Moreover, sometimes it's useful to analyze in which order you have executed different commands, one after the other. This is often the root cause of errors. This is where histogrep will make your life easier:

function histogrep{

history | grep $1

}

Source the file as in the previous topic, and try to search, a command you entered previously:

debian@beaglebone:~$ histogrep Mediadrop

Different ways to find your files

When you don't remember where a specific file is located, you can rely on some Linux tools. In this specific case, let's say that we want to retrieve the deployment.ini location; thus we can use two different commands:

To find your files, run the following command:

(mediacore_env)debian@beaglebone:~$ find / -name production.ini –type f 2>/dev/null

The various parameters involved are as follows:

· / : We want to look into the root partition. Obviously, if you install MediaDrop to another partition, set it accordingly.

· –type f (optional): This optimizes the search, as we want to find only files but not directories.

· 2>/dev/null (optional): This is to remove annoying and most of the time useless Permission denied messages.

While being really powerful, the find command requires some options, which you have to know, to use it well. The locate command is a quick and an easy way to find your file. You will have to install it, as this command is not installed, by default. You will retrieve it from the mlocate package.

To request an update of the index of all your files, use the following command:

debian@beaglebone:~$ sudo updatedb

Now you can search for any file with the following command:

debian@beaglebone:~$ Locate production.ini

You have the result(s) instantly, faster than with the find command.

What is perturbing with locate is that you might not find a file that can exist anyway. This situation happens when the searched-for file had been created after the indexation of the locate database.

Each command has its own pros and cons; find is really handy and powerful but requires a lot of options that you need to know; on the other hand, locate is easy, and simple but requires being updated regularly.

All you need to know about open network ports

As long as you aim at using BeagleBone Black for server purposes, many ports are going to be used. You will soon need to know those that are already assigned. For example, ports 8080 and 8000 are very often required so they will be most probably defined in many default configuration files when you install an application. Then, to avoid port conflicts, you will want to retrieve those that are currently used. For this, enter the following command:

debian@arm:~$ sudo netstat -an | grep LISTEN | grep -v ^unix

tcp 0 0 0.0.0.0:1984 0.0.0.0:* LISTEN

tcp 0 0 127.0.0.1:3306 0.0.0.0:* LISTEN

tcp 0 0 127.0.0.1:11211 0.0.0.0:* LISTEN

tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN

tcp6 0 0 :::6600 :::* LISTEN

tcp6 0 0 :::80 :::* LISTEN

tcp6 0 0 :::22 :::* LISTEN

In the beginning of this appendix, we have seen how to ease our life with aliases and functions.

I strongly suggest that you use the same technique with this long command. Thereafter, you won't hesitate any more to use it because you won't need to remember the whole syntax.