Posted on Leave a comment

Troubleshooting systemd Services

Raspbian, like most Linux distributions, has changed to using systemd as the primary software suite to control the Linux system. Part of systemd’s responsibilities include running the services that provide much of the Linux functionality. Systemd is also the ideal tool for starting software at boot. I use this feature for my RTL-SDR Server and the Spy Server pre-formatted SD cards. Whilst setting up a new service is relatively simple, there are occasions when things don’t behave as expected; that’s when you need to understand a few of the trouble shooting tools. In this post I’ll cover some commands and tools that I’ve found useful.

systemd: services on Linux are called using a configuration file known as a Unit file. This is a small text file that contains the command line to run your program plus some instructions to let systemd know how and when to run the program. For example, in my RTL-SDR server I don’t want systemd to start the server until after the network is fully connected. I won’t go into the details of the Unit file here as there are lots of tutorials already provided. You can control the running of services using the following commands:

  • sudo systemctl start myservice – starts the service
  • sudu systemctl stop myservice – stops the service
  • sudo systemctl status myservice – prints a status report
  • sudo systemctl restart myservice – restarts the service and loads the configuration file

It’s important to note that systemctl start, will start the service but it won’t usually read the service’s configuration file. This is important to know if you’re changing configuration parameters to try and solve a problem. To start the process and reload the configuration file, you have to use restart.

journalctl: Linux keeps comprehensive logs of just about everything that happens on the system, including messages and errors from system units/services. The tool to view these logs from the command line is journalctl. This command has a host of filtering options so that you only have to look through relevant messages.

To only see messages relating to your unit, use the -u suffix. For example, to see only messages from a unit called test.service use:

  • journalctl -u test.service
  • To see the messages in real-time add -f like so: journalctl -u test.service -f
  • If you want to restrict the number of lines on display add -n 20 for 20 lines
  • If you only want recent logs you could add –since “5 minutes ago”
  • If you only want current logs you could add –since “now”

Cockpit: This software package is popular with system administrators as it provides easy visibility of a server’s state and allows a degree of remote management. It can also provide useful information when troubleshooting. Cockpit runs as a web service so the machine can be accessed by anyone on the local network who has the hosts username/password. To access Cockpit from the host machine, enter localhost:9090 in the browser address bar and sign on with the host’s user/password. To access from another machine enter the host’s ip address followed by :9090. To install Cockpit use: sudo apt install -y cockpit

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.